Oct-16-2018, 11:22 PM
hey
I have a couple (or so) questions about using the state engine code:
I have written a simple maze game with room, bad guys, and weapons. Everything is low-res, the player and bad guys are just squares and so on. I wrote it and then re-wrote it using the state engine code. It works, shows the title screen, when I press space the game starts, and when all the players lives are gone it flips back to the title screen. The thing is, there is an instructions screen that can be shown either when the titles are showing or in game. And in game there is a weapon chooser (certain bad guys need certain guns to kill them!)
so I am currently using a mode var:
I have also written a missile command type game, which I wrote when I was first learning python and pygame, and so it doesn't use classes and is full of global vars (yeah, I know!) So I was going to re-write it with classes and the state engine. The issue here is that, at the end of the game it checks for high score, so there are two routes:
game - high check - get name - show highs - title
game - high check - show highs - title
and the titles switch between showing the titles and the high scores. So how is it possible to have sub-states and switch between them? In the state engine code, everything is ran by the control, but then the states would also be controls and it seems like I would be duplicating code across two classes.
If anyone can help me further my understanding of these issues it would be much appreciated!
Also, on a slightly unrelated note, I am still using python 2.7 as the last I checked pygame only worked with it, does anyone know what version they are up to now? Does it work with Python3 as I feel I should be using that.
I have a couple (or so) questions about using the state engine code:
I have written a simple maze game with room, bad guys, and weapons. Everything is low-res, the player and bad guys are just squares and so on. I wrote it and then re-wrote it using the state engine code. It works, shows the title screen, when I press space the game starts, and when all the players lives are gone it flips back to the title screen. The thing is, there is an instructions screen that can be shown either when the titles are showing or in game. And in game there is a weapon chooser (certain bad guys need certain guns to kill them!)
so I am currently using a mode var:
if self.mode == TITLE: title_screen.draw() else: instructions_screen.draw()and in game I do the same but in the draw() routine, and that just has an added:
if self.mode == CHOOSER:And I have switching code in the game key check like so:
if event.key == pg.K_i: if self.mode == INSTR: self.mode = self.old_mode else: self.old_mode = self.mode self.mode = INSTRIs this the best way to do this or is their a state-engine style solution?
I have also written a missile command type game, which I wrote when I was first learning python and pygame, and so it doesn't use classes and is full of global vars (yeah, I know!) So I was going to re-write it with classes and the state engine. The issue here is that, at the end of the game it checks for high score, so there are two routes:
game - high check - get name - show highs - title
game - high check - show highs - title
and the titles switch between showing the titles and the high scores. So how is it possible to have sub-states and switch between them? In the state engine code, everything is ran by the control, but then the states would also be controls and it seems like I would be duplicating code across two classes.
If anyone can help me further my understanding of these issues it would be much appreciated!
Also, on a slightly unrelated note, I am still using python 2.7 as the last I checked pygame only worked with it, does anyone know what version they are up to now? Does it work with Python3 as I feel I should be using that.