Mercurial > skaapsteker
comparison skaapsteker/sprites/player.py @ 620:6cc0d54df531
Some light cleanup.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Fri, 06 May 2011 16:59:23 +0200 |
parents | 62569f486ede |
children | 851c8726696c |
comparison
equal
deleted
inserted
replaced
619:4ffa9d159588 | 620:6cc0d54df531 |
---|---|
1 """Class for dealing with the player""" | 1 """Class for dealing with the player""" |
2 | 2 |
3 import time | |
4 | |
3 import pygame.transform | 5 import pygame.transform |
4 import time | 6 from pygame.constants import BLEND_RGBA_MULT |
5 | 7 |
6 from ..sprites.base import (find_sprite, Monster, NPC, Item, Doorway, TILE_SIZE, | |
7 PC_LAYER, MONSTER_LAYER, PROJECTILE_LAYER) | |
8 from ..sprites.projectiles import Fireball, Lightning | |
9 from ..sprites.items import BreakableItem | |
10 from ..physics import Sprite | 8 from ..physics import Sprite |
11 from ..constants import Layers, FoxHud, DOUBLE_TAP_TIME | 9 from ..constants import Layers, FoxHud, DOUBLE_TAP_TIME |
12 from ..data import get_files, load_image | 10 from ..data import get_files, load_image |
13 from ..engine import PlayerDied, AddSpriteEvent, OpenNotification | 11 from ..engine import PlayerDied, AddSpriteEvent, OpenNotification |
14 | 12 |
15 from pygame.constants import BLEND_RGBA_MULT | 13 from .base import (find_sprite, Monster, NPC, Item, Doorway, TILE_SIZE, |
14 PC_LAYER, MONSTER_LAYER, PROJECTILE_LAYER) | |
15 from .projectiles import Fireball, Lightning | |
16 from .items import BreakableItem | |
17 | |
18 | |
16 | 19 |
17 class Player(Sprite): | 20 class Player(Sprite): |
18 | 21 |
19 collision_layer = PC_LAYER | 22 collision_layer = PC_LAYER |
20 collides_with = set([MONSTER_LAYER, PROJECTILE_LAYER]) | 23 collides_with = set([MONSTER_LAYER, PROJECTILE_LAYER]) |
54 self.inventory_image = None | 57 self.inventory_image = None |
55 # We muck with these in load for convience, so ensure they're right | 58 # We muck with these in load for convience, so ensure they're right |
56 self.the_world = the_world | 59 self.the_world = the_world |
57 self.shape = the_world.fox.shape | 60 self.shape = the_world.fox.shape |
58 self._me = the_world.fox | 61 self._me = the_world.fox |
59 self.set_facing('left') | 62 self.facing = 'left' |
60 self.set_image() | 63 self.set_image() |
61 self.set_pos((0, 0)) | 64 self.set_pos((0, 0)) |
62 self._collisions_seen = 0 | 65 self._collisions_seen = 0 |
63 self._last_collide = [] | 66 self._last_collide = [] |
64 self._layer = Layers.PLAYER | 67 self._layer = Layers.PLAYER |
212 self.init_pos() | 215 self.init_pos() |
213 self._last_collide = [] | 216 self._last_collide = [] |
214 self._collisions_seen = 0 | 217 self._collisions_seen = 0 |
215 | 218 |
216 def set_facing(self, new_facing): | 219 def set_facing(self, new_facing): |
217 self.facing = new_facing | 220 if self.facing != new_facing: |
221 self.facing = new_facing | |
222 self.set_image() | |
218 | 223 |
219 def collided(self, other): | 224 def collided(self, other): |
220 if self.attacking and hasattr(other, 'damage'): | 225 if self.attacking and hasattr(other, 'damage'): |
221 # FIXME: Check if we're facing the right way | 226 # FIXME: Check if we're facing the right way |
222 other.damage(5) | 227 other.damage(5) |
254 def set_pos(self, pos): | 259 def set_pos(self, pos): |
255 self.rect.midbottom = pos[0] * TILE_SIZE[0] + self.rect_offset[0], (pos[1] + 1) * TILE_SIZE[1] + self.rect_offset[1] | 260 self.rect.midbottom = pos[0] * TILE_SIZE[0] + self.rect_offset[0], (pos[1] + 1) * TILE_SIZE[1] + self.rect_offset[1] |
256 self.collide_rect.midbottom = pos[0] * TILE_SIZE[0], (pos[1] + 1) * TILE_SIZE[1] | 261 self.collide_rect.midbottom = pos[0] * TILE_SIZE[0], (pos[1] + 1) * TILE_SIZE[1] |
257 | 262 |
258 def action_left(self): | 263 def action_left(self): |
259 if self.facing != 'left': | 264 self.set_facing('left') |
260 self.facing = 'left' | |
261 self.set_image() | |
262 if self.shape != 'fox': | 265 if self.shape != 'fox': |
263 self.deltav((-300.0, 0.0)) | 266 self.deltav((-300.0, 0.0)) |
264 elif self.sprinting > 0: | 267 elif self.sprinting > 0: |
265 self.sprinting = 1 | 268 self.sprinting = 1 |
266 self.deltav((-900.0, 0.0)) | 269 self.deltav((-900.0, 0.0)) |
318 else: | 321 else: |
319 # Back out of transformation | 322 # Back out of transformation |
320 self.shape = self._me.shape | 323 self.shape = self._me.shape |
321 | 324 |
322 def action_right(self): | 325 def action_right(self): |
323 if self.facing != 'right': | 326 self.set_facing('right') |
324 self.facing = 'right' | |
325 self.set_image() | |
326 if self.shape != 'fox': | 327 if self.shape != 'fox': |
327 self.deltav((300.0, 0.0)) | 328 self.deltav((300.0, 0.0)) |
328 elif self.sprinting > 0: | 329 elif self.sprinting > 0: |
329 self.sprinting = 1 # Flag so stopping works | 330 self.sprinting = 1 # Flag so stopping works |
330 self.deltav((900.0, 0.0)) | 331 self.deltav((900.0, 0.0)) |