Mercurial > mamba
changeset 225:af95fbc8ef5c
Snakes should be impermeable. So now they are.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Wed, 14 Sep 2011 23:02:45 +0200 |
parents | 0dfa3f52742b |
children | cd5377697c9e |
files | mamba/snake.py |
diffstat | 1 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/snake.py Wed Sep 14 22:43:37 2011 +0200 +++ b/mamba/snake.py Wed Sep 14 23:02:45 2011 +0200 @@ -24,6 +24,7 @@ self.speed = 120.0 # pixel / s self.frac_ds = 0.0 self.mutation = None + self.coiled = True head = property(fget=lambda self: self.segments[0]) tail = property(fget=lambda self: self.segments[-1]) @@ -72,6 +73,7 @@ tile_state = self.head.get_tile_state() shifted, ds = self.head.shift_head(ds) if shifted: + self.coiled = False self.head.shifted_tile() else: break @@ -87,6 +89,7 @@ if not self.check_uturn(): self.head.set_orientation(self.orientation) + self.check_self_crash() for segment in self.segments: segment.shift_pixels(ds) world.interact(segment) @@ -106,6 +109,13 @@ def set_orientation(self, orientation): self.orientation = orientation + def check_self_crash(self): + if self.coiled: + return + collides = spritecollide(self.head, self.segment_group, False) + if [s for s in collides if s not in self.segments[:2]]: + self.crash() + def crash(self): SnakeDiedEvent.post()