# 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.

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

##### Share on other sites
there was a thread here yesterday.

try searching the forums for fsm or smc (finite state machine or state machine compiler)

##### 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

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

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.

1. 1
Rutin
19
2. 2
JoeJ
15
3. 3
4. 4
5. 5

• 24
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631699
• Total Posts
3001776
×