Sign in to follow this  
Omar Alvi

state machines

Recommended Posts

Omar Alvi    100
Hello people, I have a question regarding state machines. Ahhh i really wanted to discus this with an experieced game developer. Duhh and i tried getting on the IRC channel only to find out that my pathetic ISP is banned......damm. Anyways i wanted to ask how to make use of state machines. Uptil now i havent been making diagrams just think about the states and how to do trasition between them ...and most of the time i realise that i missed out something, then i see the behaviour of the object visually and if its not desired keep making changes till i get it right. Ahhh but thas not neat approach the code is dirtly as well so can anyone give me any pointers.....take a hypothetical character who can walk(left and right), run(left and right) and can die... the character walks normally but when it sees the hero it runs towards him......this is a 2d game i forgot to mention......and when the hero hits this character it dies.......i have animation sequences for walking left, walking right, running left, runing right, and death sequence of that character....can anyone help please.....i can do this on my own but i want to learn the neat way of doing it by using state machines and state diagrams..thanks

Share this post


Link to post
Share on other sites
TechnoGoth    2937
Well, I think I understand what you are asking but i'll break down as I see it and explain a method of solving this problem.

Okay
Character Alone - Walk Left or Right
Character See Player - Run Towards player
Character Dead - remove character

Right there you can clearly see that you have 3 states, those 3 states represent all possible situations a character can be in. In each of those states you have two actions Look, and move.

How the state transitions would work is like this.
State 1 - Alone
State 2 - See Player
State 3 - dead

1 - Look - If can see player - state = 2
2 - Look - If can not see player - state = 1

The move actions would be random in state one and towards the player in state 2. As to how to program this it depends on your code but the typical way to program state machines is using singeltons.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this