annotate mamba/snake.py @ 78:b1019923cb12

Direction control for snake.
author Simon Cross <hodgestar@gmail.com>
date Sun, 11 Sep 2011 18:29:49 +0200
parents
children f602a8c3d173
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
78
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
1 """The player snake object."""
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
2
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
3 from mamba.sprite import BaseSprite
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
4
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
5
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
6 class Snake(BaseSprite):
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
7
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
8 UP, DOWN, LEFT, RIGHT = range(4)
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
9
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
10 def __init__(self, tile_pos, orientation):
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
11 super(Snake, self).__init__("snake/"
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
12 "snake-head-mouth-open-r.png")
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
13 self.set_tile_pos(tile_pos)
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
14 self.set_orientation(orientation)
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
15
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
16 def set_orientation(self, orientation):
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
17 self._orientation = orientation
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
18 print ["UP", "DOWN", "LEFT", "RIGHT"][orientation]
b1019923cb12 Direction control for snake.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
19 # TODO: update image