Skip to main content
gamedev.net
🔒 Locked

A state machine problem

Started by acid2 1 reply 400+ views
Original Post
acid2
acid2
Hey, I've started learning about state machines, as I'm sure some of you are aware but I've hit a bit of iffy ground. I'm making a Pong game, but the state manager itself is just part of my generic engine so I'm kind of going for the best all round solution. Anyway, the problem... ----------------------------- I have a state "game" that generally updates the game (which is pong :P) and I have another state called "score" that happens when either the player or ai score. The problem is once a player has scored, the ball needs to be reset. I thought it would be best to do this in the score state but someone suggested that I create a seperate "ResetArena" state, which I think is an even better idea. Both of my ideas here require that the states access the ball. The ball is currently just a variable of the "game" state (which I'm sure is not such a good idea, after doing this :P). So what I need is some kind of way to access the ball from any state. ----------------------------- I thought about it for a while and I think that the best way would be to create a scene management system so that any state can just do something like SceneManager.FindEntity("Ball"). How have you over come this problem? Is my solution good... and what others are there? Thanks, - aCiD2
stevenmarky
stevenmarky
You could pass the main game object into your state setting functions,
SetStateGameStart(Game& game){ game.setBallPosition(0,0); game.setBallVelocity( }

acid2
acid2
I could but that wouldn't mean the solution would work with other states... Like a save game state, that would need to know the player position and stuff. Im not totally keen on that idea, it was like my inital idea - when someone scores then the "score" state is initalised with the game state as part of the constructor.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.