[Tutor] canvas -> CLASSES
ALAN GAULD
alan.gauld at btinternet.com
Thu May 10 23:26:55 CEST 2007
> T's reply:
> The maze is simply the backdrop. I've attached the new and improved code.
As I said in the last post I think the maze probably needs to
be quite a bit more than the backdrop. I think it knows about
the rules of movement within the maze - which routes are blocked,
where other players are sitting etc.
> > OK, So I'm asssuming these gifs represent something,
> um... actually, the .gif will be a photo that will be taken as
> part of the 'game'. ... the first pic will be the main pic as
> it goes around the maze. When the pic 'collides' with items
> that will be placed another pic will be displayed
OK, In that case it sounds like the gif is only how the object
will draw itself. The object is actually some kind of player,
which has a status which is reflected by the gif displayed?
So the player c;lass will have methods to play the game,
a status attribute, a collection of gifs to match the status,
a location of some kind and a draw method that displays
the appropriate gif when requested by the maze.
With those two class definitions in mind I'd suggest an
architecture where:
A maze is created and populated by players
The maze draws itself and then asks each player to draw itself.
Players then do something (whatever the game requires) and that
may involve asking the maze to move them to a new location.
The maze will look at their position relative to the layout of the
maze and the position of other players/objects. If the move can
be made it moves the player and sets its new location. The maze
then redaws itself, including asking the players/objects to redraw
themselves at their new positions. (If you want to get really smart
you could just redraw the sections of maze that have changed,
but that's quite tricky to manage reliably)
The whole thing could be controlled by an overall Game object
which contains the maze and a list of players (some or all of
which could be in the maze). The game object is responsible
for ensuring each player makes plays at the appropriate time
or receives the user events and matches them to a player
as appropriate.
Does that sound like a workable model?
BTW Have you looked at PyGame (www.pygame.org)
which has things like sprites etc which may make some of
this stuff easier.
HTH,
Alan G.
___________________________________________________________
Inbox full of unwanted email? Get leading protection and 1GB storage with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html
More information about the Tutor
mailing list