comparison mamba/snake.py @ 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 ec23ecbbd1c6
children 59166ae6e864
comparison
equal deleted inserted replaced
251:5b61360745a5 252:8198492745b1
3 import random 3 import random
4 4
5 from pygame.sprite import Group, spritecollide 5 from pygame.sprite import Group, spritecollide
6 6
7 from mamba.constants import TILE_SIZE, UP, DOWN, LEFT, RIGHT 7 from mamba.constants import TILE_SIZE, UP, DOWN, LEFT, RIGHT
8 from mamba.sprites import BaseSprite 8 from mamba.sprites import BaseSprite, tile_sizify
9 from mamba.engine import SnakeDiedEvent, LevelCompletedEvent 9 from mamba.engine import SnakeDiedEvent, LevelCompletedEvent
10 from mamba import mutators 10 from mamba import mutators
11 11
12 12
13 INITIAL_SEGMENT_COUNT = 4 13 INITIAL_SEGMENT_COUNT = 4
180 self.update_image() 180 self.update_image()
181 181
182 def get_tile_state(self): 182 def get_tile_state(self):
183 return self.tile_pos, self.orientation 183 return self.tile_pos, self.orientation
184 184
185 def get_distance(self):
186 rx, ry = self.rect.topleft
187 x, y = tile_sizify(self.tile_pos)
188 return max(abs(rx - x), abs(ry - y))
189
185 def shift_tile(self, tile_state): 190 def shift_tile(self, tile_state):
186 """Shift this segment to the tile the other one was on. 191 """Shift this segment to the tile the other one was on.
187 192
188 Also reset the position to be the center of the tile. 193 Also reset the position to be the center of the tile.
189 """ 194 """
190 tile_pos, orientation = tile_state 195 tile_pos, orientation = tile_state
191 self.set_tile_pos(tile_pos) 196 self.set_tile_pos(tile_pos)
192 self.orientation = orientation 197 self.orientation = orientation
198
199 def shift_tile_and_pixels(self, tile_state):
200 ds = self.get_distance()
201 self.shift_tile(tile_state)
202 self.shift_pixels(ds)
193 203
194 def shifted_tile(self): 204 def shifted_tile(self):
195 pass 205 pass
196 206
197 def shift_pixels(self, distance): 207 def shift_pixels(self, distance):