[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] State Machine Organization



Here's what I'm thinking of doing now, though I'm lost as to how to actually implement it.

there will be 2 primary game states, Battle and  Walking.  these will be implemented as classes that inherit from PGU's states.
I'm not even thinking about the Battle state at the moment.  Each location, be it World map, Town1, Castle4, or whatever will be a state that inherits from Walking.
so the hot-spot tiles (stairs, map boundaries etc) will load a new Location state.  I *think* the NPCs themselves need to also be a state-machine of sorts. they get updated on every tick of the location, when they are talking, their update method will pass data back and forth with the menu system, if they're not, they'll be walking around... Back in the main Location state, we're checking if there is a menu in effect. if there is we're passing keyboard events to it instead of to walking, and we're rendering it to the screen.. I think that'll work if I can only figure out how to code it :P

Andre


On 7/4/07, Laura Creighton <lac@xxxxxxxxxx> wrote:
In a message of Wed, 04 Jul 2007 14:38:46 -0300, "Giuliano Vilela" writes:
>------=_Part_146600_24953701.1183570726405
>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>Content-Transfer-Encoding: 7bit
>Content-Disposition: inline
>
>Definetly some of my concerns too... Looking foward to the posts here =)
>
>On 7/4/07, Andre LeBlanc <andrepleblanc@xxxxxxxxx > wrote:
>>
>> I've spent the past 24 hours or so looking through the source for the P
>GU
>> Engine and Phil's Pyweek3 example code, and its convinced me that I nee
>d to
>> do alot of re-writing.  I'm trying to figure out how to best organize t
>he
>> various states of my RPG, but I'm a little stuck.  should a state be
>> responsible for all of the rendering at a given time?  for example in t
>he
>> case of a top-down RPG, Walking around town is a state, being in a batt
>le is
>> a state, but what about talking to an npc or a vendor in a town?  This
>would
>> have to bring up menus for the user to navigate, but the scenery in the
> town
>> should still be painting. NPCs can walk around while you are talking to
> a
>> shop owner, so should that be a separate state?  I like the way the 'ro
>oms'
>> were subclassed and imported for the pyweek3 game and that's what I'm g
>oing
>> for, but how would you transition between these 2 states, if indeed the
>y
>> should be separate.
>>
>>

Ah, i think you want these to be views, not states.
And the users should have the choice to 'bring up a walking around
view' and 'bring up a haggling with storekeeper view' etc.
Now if you are in location L3-the-volcano, and there is no
shopkeeper associated with L3-the-volcano, then  bringing up the
shopkeeper view should probably prodice the 'there is nobody here
to haggle with' message, but that is still a view.

You want to keep your game state in this thing that is called your
Model, and then have many ways to view (Views) your game state.

Laura