2 Replies - 295 Views - Last Post: 31 July 2014 - 07:08 AM Rate Topic: -----

#1 Lt_Twig  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 05-March 14

Making a python state machine

Posted 30 July 2014 - 10:21 AM

I figured now would be a good time to build this so that I had a legitimate system to test my components on. I was wondering what would be the best way to to build a game state machine in python.

I made one in c++, but I don't think it could be done the same way in python. What I did was create a class for the state machine, created an abstract State class, and then for each game state I needed I created a class for each state (each class inheriting from the abstract State class). The machine would hold each state in a single vector and would pop and switch states whenever a change between states would be made.

I searched around the web looking for some good python examples, but they are all string based states which I wouldn't mind doing but it would make certain things more complicated for me. If there's a way to make it class based that would be great. And some pseudo code would be appreciative too.

Is This A Good Question/Topic? 0
  • +

Replies To: Making a python state machine

#2 DK3250  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 105
  • Joined: 27-December 13

Re: Making a python state machine

Posted 30 July 2014 - 11:16 PM

If you look for litterature, chapter 7 in "Beginning Game Development with Python and Pygame" is realy one big example of a state driven game with AI.
The book also introduces many aspects of Pygame - a great and important module for game development in Python.

Unfortunately, the book do not cover Sprites and Sprites handling in Pygame - this is a really big mimus; Sprites are very important and I cannot grasp why Sprites is not even mentioned in the book.
Was This Post Helpful? 0
  • +
  • -

#3 Lt_Twig  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 05-March 14

Re: Making a python state machine

Posted 31 July 2014 - 07:08 AM

View PostDK3250, on 30 July 2014 - 11:16 PM, said:

If you look for litterature, chapter 7 in "Beginning Game Development with Python and Pygame" is realy one big example of a state driven game with AI.
The book also introduces many aspects of Pygame - a great and important module for game development in Python.

Unfortunately, the book do not cover Sprites and Sprites handling in Pygame - this is a really big mimus; Sprites are very important and I cannot grasp why Sprites is not even mentioned in the book.


Well I'll be using py-sfml, so their manual might have something with sprites in it. But I'll take anything that has material on state machines, thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1