comparison skaapsteker/sprites/player.py @ 290:c68f2f3efc7f

Item dropping and swapping.
author Jeremy Thurgood <firxen@gmail.com>
date Fri, 08 Apr 2011 21:58:48 +0200
parents 8cac6ff88a9d
children 15b2be883a40
comparison
equal deleted inserted replaced
289:16ffe6f5dbb8 290:c68f2f3efc7f
1 """Class for dealing with the player""" 1 """Class for dealing with the player"""
2 2
3 import pygame.transform 3 import pygame.transform
4 import time 4 import time
5 5
6 from ..sprites.base import TILE_SIZE, PC_LAYER, MONSTER_LAYER 6 from ..sprites.base import find_sprite, TILE_SIZE, PC_LAYER, MONSTER_LAYER
7 from ..physics import Sprite 7 from ..physics import Sprite
8 from ..constants import Layers 8 from ..constants import Layers
9 from ..data import get_files, load_image 9 from ..data import get_files, load_image
10 from ..engine import PlayerDied 10 from ..engine import PlayerDied, ItemRepopulationEvent
11 11
12 12
13 class Player(Sprite): 13 class Player(Sprite):
14 14
15 collision_layer = PC_LAYER 15 collision_layer = PC_LAYER
198 if self.sprinting > 0: 198 if self.sprinting > 0:
199 return 199 return
200 self.sprinting = 2 200 self.sprinting = 2
201 self._sprint_start_time = time.time() 201 self._sprint_start_time = time.time()
202 202
203 def action_double_down(self):
204 print 'double down tap'
205
206 def action_double_right(self): 203 def action_double_right(self):
207 if self.sprinting > 0: 204 if self.sprinting > 0:
208 return 205 return
209 self.sprinting = 2 206 self.sprinting = 2
210 self._sprint_start_time = time.time() 207 self._sprint_start_time = time.time()
208
209 def action_double_up(self):
210 pass
211 211
212 def action_right(self): 212 def action_right(self):
213 if self.facing != 'right': 213 if self.facing != 'right':
214 self.facing = 'right' 214 self.facing = 'right'
215 self.set_image() 215 self.set_image()
225 self.deltav((0.0, -self.terminal_velocity[1])) 225 self.deltav((0.0, -self.terminal_velocity[1]))
226 self.on_solid = False 226 self.on_solid = False
227 227
228 def action_down(self): 228 def action_down(self):
229 print self._touching_actionables 229 print self._touching_actionables
230 for actionable in self._touching_actionables[:1]: 230 if self._touching_actionables:
231 actionable.player_action(self) 231 self._touching_actionables[0].player_action(self)
232 elif self.the_world.fox.item is not None:
233 self.drop_item()
232 234
233 235
234 def action_fire1(self): 236 def action_fire1(self):
235 # FIXME: Use the correct tail properties for this 237 # FIXME: Use the correct tail properties for this
236 if len(self.the_world.fox.tails) < 2: 238 if len(self.the_world.fox.tails) < 2:
289 sprint_image = image.copy() 291 sprint_image = image.copy()
290 sprint_image.blit(shockwave, (0, 0)) 292 sprint_image.blit(shockwave, (0, 0))
291 self._image_dict[sprint_key].append(sprint_image) 293 self._image_dict[sprint_key].append(sprint_image)
292 294
293 295
296 def drop_item(self):
297 my_item = self.the_world.fox.item
298 if my_item is None:
299 return
300 self.the_world.fox.item = None
301 world_item = getattr(self.the_world.items, my_item)
302 world_item.level = self.the_world.fox.level
303 world_item.pos = [a/b for a, b in zip(self.rect.center, TILE_SIZE)]
304 sprite_dict = world_item.copy()
305 sprite_dict.pop('level')
306 sprite_dict['name'] = my_item
307 sprite_dict['world'] = self.the_world
308 ItemRepopulationEvent.post(find_sprite(sprite_dict, 'items'))
309
310
294 def take_item(self, item): 311 def take_item(self, item):
295 my_item = self.the_world.fox.item 312 self.drop_item()
296 if my_item is not None:
297 print "I already have", my_item
298 return
299 getattr(self.the_world.items, item.name).level = "_limbo" 313 getattr(self.the_world.items, item.name).level = "_limbo"
300 self.the_world.fox.item = item.name 314 self.the_world.fox.item = item.name
301 item.kill() 315 item.kill()
302 print "took", item 316 print "took", item
303 317