Mercurial > mamba
changeset 357:ff1c39075452
Button and gate sprites
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 16 Sep 2011 23:43:33 +0200 |
parents | 5f6a23b62b85 |
children | 01365c849614 |
files | mamba/sprites.py |
diffstat | 1 files changed, 37 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/sprites.py Fri Sep 16 23:42:00 2011 +0200 +++ b/mamba/sprites.py Fri Sep 16 23:43:33 2011 +0200 @@ -243,6 +243,43 @@ head.shift_tile_and_pixels((other.tile_pos, self.direction)) +class ButtonSprite(SingleImageTileSprite): + image_name = 'button' + name = 'button' + tileset = 'lab' + + def __init__(self, other_id): + super(ButtonSprite, self).__init__(tile_char=None) + self.other_id = other_id + + def interact(self, world, segment): + head = world.snake.head + if segment is head: + other = world.get_sprite(self.other_id) + other.button_pushed() + + +class GateSprite(SingleImageTileSprite): + closed_name = 'closed_gate' + open_image = 'open_gate' + name = 'gate' + tileset = 'lab' + + def __init__(self): + self.image_name = self.closed_name + self.opened = False + super(GateSprite, self).__init__(tile_char=None) + + def get_solid(self, snake, segment): + return not self.opened + + def button_pushed(self): + self.opened = True + # Update image + self.image_name = self.open_image + self.image = self.load_image(self.image_name, mutators=()) + + class PuddleSprite(SingleImageTileSprite): image_name = 'puddle' name = 'puddle'