# HG changeset patch # User Simon Cross # Date 1316042509 -7200 # Node ID 8198492745b1d389ef059679c6cefc9cc1e79d4c # Parent 5b61360745a5f2b06ae3f6c9944d127038d48183 Try not to let head wander during teleporting (it's bad for your health). diff -r 5b61360745a5 -r 8198492745b1 mamba/snake.py --- 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 diff -r 5b61360745a5 -r 8198492745b1 mamba/sprites.py --- 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):