comparison skaapsteker/sprites/player.py @ 335:c6552e9fc2e1

Added aburage.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 09 Apr 2011 12:15:19 +0200
parents 971c1726c530
children c8fd82ff0c71
comparison
equal deleted inserted replaced
334:5c53da24a012 335:c6552e9fc2e1
37 self.flying = False 37 self.flying = False
38 self._load_images() 38 self._load_images()
39 self.inventory_image = None 39 self.inventory_image = None
40 # We muck with these in load for convience, so ensure they're right 40 # We muck with these in load for convience, so ensure they're right
41 self.the_world = the_world 41 self.the_world = the_world
42 self._me = the_world.fox
42 self.set_facing('left') 43 self.set_facing('left')
43 self.set_image() 44 self.set_image()
44 self.set_pos((0, 0)) 45 self.set_pos((0, 0))
45 self._collisions_seen = 0 46 self._collisions_seen = 0
46 self._last_collide = [] 47 self._last_collide = []
47 self._layer = Layers.PLAYER 48 self._layer = Layers.PLAYER
48 49
49 def set_image(self): 50 def set_image(self):
50 key = self._make_key(len(self.the_world.fox.tails)) 51 key = self._make_key(len(self._me.tails))
51 images = self._image_dict[key] 52 images = self._image_dict[key]
52 if self._animation_frame >= len(images): 53 if self._animation_frame >= len(images):
53 self._animation_frame = 0.0 54 self._animation_frame = 0.0
54 if self.rect: 55 if self.rect:
55 cur_pos = self.collide_rect.midbottom 56 cur_pos = self.collide_rect.midbottom
165 self._collisions_seen = 0 166 self._collisions_seen = 0
166 elif other in self._last_collide: 167 elif other in self._last_collide:
167 self._collisions_seen += 1 168 self._collisions_seen += 1
168 if hasattr(other, 'collided_player'): 169 if hasattr(other, 'collided_player'):
169 other.collided_player(self) 170 other.collided_player(self)
170 print 'Health', self.the_world.fox.cur_health 171 print 'Health', self._me.cur_health
171 172
172 173
173 def damage(self, damage): 174 def damage(self, damage):
174 self.the_world.fox.cur_health -= damage 175 self._me.cur_health -= damage
175 self._soundsystem.play_sound('yelp') 176 self._soundsystem.play_sound('yelp')
176 if self.the_world.fox.cur_health <= 0: 177 if self._me.cur_health <= 0:
177 PlayerDied.post() 178 PlayerDied.post()
178 179
179 def restore(self): 180 def restore(self):
180 """Restore player to max health (for restarting levels, etc.)""" 181 """Restore player to max health (for restarting levels, etc.)"""
181 self.the_world.fox.cur_health = self.the_world.fox.max_health 182 self._me.cur_health = self._me.max_health
182 183
183 def set_pos(self, pos): 184 def set_pos(self, pos):
184 self.rect.midbottom = pos[0] * TILE_SIZE[0] + self.rect_offset[0], (pos[1] + 1) * TILE_SIZE[1] + self.rect_offset[1] 185 self.rect.midbottom = pos[0] * TILE_SIZE[0] + self.rect_offset[0], (pos[1] + 1) * TILE_SIZE[1] + self.rect_offset[1]
185 self.collide_rect.midbottom = pos[0] * TILE_SIZE[0], (pos[1] + 1) * TILE_SIZE[1] 186 self.collide_rect.midbottom = pos[0] * TILE_SIZE[0], (pos[1] + 1) * TILE_SIZE[1]
186 187
228 229
229 def action_down(self): 230 def action_down(self):
230 print self._touching_actionables 231 print self._touching_actionables
231 if self._touching_actionables: 232 if self._touching_actionables:
232 self._touching_actionables[0].player_action(self) 233 self._touching_actionables[0].player_action(self)
233 elif self.the_world.fox.item is not None: 234 elif self._me.item is not None:
234 self.drop_item() 235 self.drop_item()
235 236
236 237
237 def action_fire1(self): 238 def action_fire1(self):
238 # FIXME: Use the correct tail properties for this 239 # FIXME: Use the correct tail properties for this
239 if len(self.the_world.fox.tails) < 2: 240 if len(self._me.tails) < 2:
240 # Only have a bite attack 241 # Only have a bite attack
241 print 'attacking' 242 print 'attacking'
242 self.attacking = 2 243 self.attacking = 2
243 # Reset the animation clock 244 # Reset the animation clock
244 self._last_time = time.time() 245 self._last_time = time.time()
296 self._image_dict[sprint_key].append(sprint_image) 297 self._image_dict[sprint_key].append(sprint_image)
297 298
298 299
299 300
300 def discard_item(self): 301 def discard_item(self):
301 self.the_world.fox.item = None 302 self._me.item = None
302 303
303 304
304 def get_sprite(self, set_level): 305 def get_sprite(self, set_level):
305 my_item = self.the_world.fox.item 306 my_item = self._me.item
306 if my_item is None: 307 if my_item is None:
307 return None 308 return None
308 world_item = getattr(self.the_world.items, my_item) 309 world_item = getattr(self.the_world.items, my_item)
309 if set_level: 310 if set_level:
310 world_item.level = self.the_world.fox.level 311 world_item.level = self._me.level
311 world_item.pos = [a/b for a, b in zip(self.rect.center, TILE_SIZE)] 312 world_item.pos = [a/b for a, b in zip(self.rect.center, TILE_SIZE)]
312 sprite_dict = world_item.copy() 313 sprite_dict = world_item.copy()
313 sprite_dict.pop('level') 314 sprite_dict.pop('level')
314 sprite_dict['name'] = my_item 315 sprite_dict['name'] = my_item
315 sprite_dict['world'] = self.the_world 316 sprite_dict['world'] = self.the_world
325 326
326 327
327 def take_item(self, item): 328 def take_item(self, item):
328 self.take_item_by_name(item.name) 329 self.take_item_by_name(item.name)
329 # We create a scaled version of the image for the inventory display 330 # We create a scaled version of the image for the inventory display
330 item.kill() 331 item.remove()
331 print "took", item 332 print "took", item
332 333
333 334
334 def make_inventory_image(self): 335 def make_inventory_image(self):
335 sprite = self.get_sprite(False) 336 sprite = self.get_sprite(False)
347 348
348 349
349 def take_item_by_name(self, item_name): 350 def take_item_by_name(self, item_name):
350 self.drop_item() 351 self.drop_item()
351 getattr(self.the_world.items, item_name).level = "_limbo" 352 getattr(self.the_world.items, item_name).level = "_limbo"
352 self.the_world.fox.item = item_name 353 self._me.item = item_name
353 self.make_inventory_image() 354 self.make_inventory_image()
354 355
355 356
356 def has_item(self, item): 357 def has_item(self, item):
357 return self.the_world.fox.item == item 358 return self._me.item == item
358 359
359 360
360 def add_actionable(self, actionable): 361 def add_actionable(self, actionable):
361 self._touching_actionables.append(actionable) 362 self._touching_actionables.append(actionable)
363
364
365 def eat_aburage(self):
366 self._me.tofu += 1
367