changeset 252:8198492745b1

Try not to let head wander during teleporting (it's bad for your health).
author Simon Cross <hodgestar@gmail.com>
date Thu, 15 Sep 2011 01:21:49 +0200
parents 5b61360745a5
children 2a969e3445ae
files mamba/snake.py mamba/sprites.py
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/snake.py	Thu Sep 15 00:59:06 2011 +0200
+++ b/mamba/snake.py	Thu Sep 15 01:21:49 2011 +0200
@@ -5,7 +5,7 @@
 from pygame.sprite import Group, spritecollide
 
 from mamba.constants import TILE_SIZE, UP, DOWN, LEFT, RIGHT
-from mamba.sprites import BaseSprite
+from mamba.sprites import BaseSprite, tile_sizify
 from mamba.engine import SnakeDiedEvent, LevelCompletedEvent
 from mamba import mutators
 
@@ -182,6 +182,11 @@
     def get_tile_state(self):
         return self.tile_pos, self.orientation
 
+    def get_distance(self):
+        rx, ry = self.rect.topleft
+        x, y = tile_sizify(self.tile_pos)
+        return max(abs(rx - x), abs(ry - y))
+
     def shift_tile(self, tile_state):
         """Shift this segment to the tile the other one was on.
 
@@ -191,6 +196,11 @@
         self.set_tile_pos(tile_pos)
         self.orientation = orientation
 
+    def shift_tile_and_pixels(self, tile_state):
+        ds = self.get_distance()
+        self.shift_tile(tile_state)
+        self.shift_pixels(ds)
+
     def shifted_tile(self):
         pass
 
--- a/mamba/sprites.py	Thu Sep 15 00:59:06 2011 +0200
+++ b/mamba/sprites.py	Thu Sep 15 01:21:49 2011 +0200
@@ -236,7 +236,7 @@
         head = world.snake.head
         if segment is head and head.orientation == self.direction:
             other = world.get_sprite(self.other_id)
-            head.shift_tile((other.tile_pos, self.direction))
+            head.shift_tile_and_pixels((other.tile_pos, self.direction))
 
 
 class PuddleSprite(SingleImageTileSprite):