My next task is to create a menu state before the game starts. I was trying to make it simple as possible. I initially started off with if conditions. But after writing the first few if's i noticed this approach is bad.

The plants versus zombies game the forum was doing was the only really example of states in game that i could find. However, when we were doing it, i pretty much felt like i was way over my experience level. A simple game state repo example would be interesting to add to your examples repo....mekire. Anyways, being the fact that i only plan on having a game state and a menu state for this pong game...I dont plan on having more than these states, i was looking at a simple approach to handling game states.

Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

as i started making game states, i ended up having to split the code up anyways, i guess. https://github.com/metulburr/pong/tree/master/data. Pretty much most of the meat of the program ended up in the state. However i am still not happy with calling stuff like calling gamestates paddle movements

It simply inverts its stateIf its value is currently True, not True is False.If its value is currently False, not False is True.

Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

I strongly recomend you make each scene/state its own class (generally inheriting from a prototype State class). All the main control should do is pass events to the active state and handle state switching. The states themselves need methods to catch events and update.

Here is a basic example, there is no base state class here so there is a lot of repeated code. Left as excercise:

Note in the above the states don't communicate any data. Eventually you will need startup and cleanup functions to handle this, but then you start getting into the complexity of the PvZ game (which I think you are fully capable of).

ah ok, thats how you did it, each state handles their own list of events.

Its getting at the end of a long day, so i'll end up implementing it into the game tomorrow. But thanks. That stripped down code makes it easy to understand.

(which I think you are fully capable of).

really? I felt like you were just holding my hand as my eyebrows rose in confusion the entire time. I think my biggest problem was i never wrote a lot of the game aspects before in PvZ, and then once you wrote it, we kept just reusing it, so i never got into in depth.

Capable of writing and understanding it. Definately.Last time however I just handed it to you so you never went through the process, as you said.

This time slowly build it up until you have your own framework you are comfortable with. Also you should be aware that some people prefer to implement their state changes as a stack. You push states onto the stack when you change and then if you want, you can pop back multiple layers. I think building a state machine like this (push down automata technically) is pretty useful for nested submenus, but I have never personally had the need to pop back further than the previous scene (which I keep track of) in my scene manager.

ok i implemented it into the pong game. I think i have everything down for the exception of event handing. I thought i had it well, guess not. The paddles dont move when being held down. I thought this appraoch is the best way to have constant flow of movement with key held down:

Sometimes the paddle will constantly move and then it will stop. I checked every other file to make sure i didnt have conflicting event movements, but game_state.get_event() is the only location where the paddle moves. I used if if if instead of if elif elif because i am use to handling diagnal movements, and that seems to handle diagnal movment the easiest. I am use to just always leaving movement fi clauses if if if's because of that. I switched them to elif's to check if that might be the issue, but it is not. I am not sure at what point the sticky pad movement, is at?

It should be in the update method of the scene, or rather in a movement method called from your update method.

-Mek

Edit:Basically, if you aren't actually catching an event, it doesn't go in the event loop. Checking held keys seems like checking an event, but it actually isn't. Also you might have noticed I only call pygame.key.get_pressed from the control event_loop and pass it to scenes using the update method. No need to recall it in each specific scene (not that it will hurt anything if you do).