Jump to content
  • Advertisement
Sign in to follow this  
Omar Alvi

state machines

This topic is 5093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
I'm going to refer your post to the General Programming forum, where you'll probably get a better response than Game Design.

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!