comparison skaapsteker/sprites/player.py @ 632:0675f390653c

Initial port to Python 3 and Pygame 2.
author Simon Cross <hodgestar@gmail.com>
date Fri, 20 Jan 2023 20:01:06 +0100
parents 1fdfc7f03d98
children
comparison
equal deleted inserted replaced
631:672e6e7ecfe9 632:0675f390653c
181 self._last_time = time.time() 181 self._last_time = time.time()
182 else: 182 else:
183 self._last_time = time.time() 183 self._last_time = time.time()
184 else: 184 else:
185 old_frame = self._animation_frame 185 old_frame = self._animation_frame
186 self._animation_frame += abs(v_x) / 300 186 self._animation_frame += abs(v_x) // 300
187 time_diff = time.time() - self._last_time 187 time_diff = time.time() - self._last_time
188 if int(self._animation_frame) - int(old_frame) > 0: 188 if int(self._animation_frame) - int(old_frame) > 0:
189 # Check time diff 189 # Check time diff
190 if time_diff < 0.10: 190 if time_diff < 0.10:
191 # Delay animation frame jump 191 # Delay animation frame jump
192 self._animation_frame -= abs(v_x) / 300 192 self._animation_frame -= abs(v_x) // 300
193 else: 193 else:
194 self._last_time = time.time() 194 self._last_time = time.time()
195 elif time_diff > 0.20: 195 elif time_diff > 0.20:
196 # Force animation frame jump 196 # Force animation frame jump
197 self._animation_frame = old_frame + 1 197 self._animation_frame = old_frame + 1
233 # Prune stale objects from the list 233 # Prune stale objects from the list
234 self._last_collide.remove(obj) 234 self._last_collide.remove(obj)
235 continue 235 continue
236 clip = obj.collide_rect.clip(self.collide_rect) 236 clip = obj.collide_rect.clip(self.collide_rect)
237 clip_area += clip.width * clip.height 237 clip_area += clip.width * clip.height
238 if clip.width > TILE_SIZE[0] / 2 and \ 238 if clip.width > TILE_SIZE[0] // 2 and \
239 self.collide_rect.bottom < obj.collide_rect.top + TILE_SIZE[1] / 3: 239 self.collide_rect.bottom < obj.collide_rect.top + TILE_SIZE[1] // 3:
240 delta = self.rect.bottom - self.collide_rect.bottom 240 delta = self.rect.bottom - self.collide_rect.bottom
241 self.collide_rect.bottom = obj.collide_rect.top - 1 241 self.collide_rect.bottom = obj.collide_rect.top - 1
242 self.rect.bottom = self.collide_rect.bottom + delta 242 self.rect.bottom = self.collide_rect.bottom + delta
243 self.init_pos() 243 self.init_pos()
244 return # Jump out of this case 244 return # Jump out of this case
292 if self._me.cur_health <= 0: 292 if self._me.cur_health <= 0:
293 PlayerDied.post() 293 PlayerDied.post()
294 294
295 def steal_life(self, damage_done): 295 def steal_life(self, damage_done):
296 if 'steal' in self._me.tails: 296 if 'steal' in self._me.tails:
297 self._me.cur_health += damage_done * len(self._me.tails) / 32 297 self._me.cur_health += damage_done * len(self._me.tails) // 32
298 self._me.cur_health = min(self._me.cur_health, self._me.max_health) 298 self._me.cur_health = min(self._me.cur_health, self._me.max_health)
299 299
300 def restore(self): 300 def restore(self):
301 """Restore player to max health (for restarting levels, etc.)""" 301 """Restore player to max health (for restarting levels, etc.)"""
302 self._me.cur_health = self._me.max_health 302 self._me.cur_health = self._me.max_health
545 if sprite is None: 545 if sprite is None:
546 self.inventory_image = None 546 self.inventory_image = None
547 image = sprite.image 547 image = sprite.image
548 if image.get_width() > image.get_height(): 548 if image.get_width() > image.get_height():
549 new_width = FoxHud.INVENTORY_SIZE 549 new_width = FoxHud.INVENTORY_SIZE
550 new_height = int(image.get_height() * (float(FoxHud.INVENTORY_SIZE) / image.get_width())) 550 new_height = int(image.get_height() * (float(FoxHud.INVENTORY_SIZE) // image.get_width()))
551 else: 551 else:
552 new_height = FoxHud.INVENTORY_SIZE 552 new_height = FoxHud.INVENTORY_SIZE
553 new_width = int(image.get_width() * (float(FoxHud.INVENTORY_SIZE) / image.get_height())) 553 new_width = int(image.get_width() * (float(FoxHud.INVENTORY_SIZE) // image.get_height()))
554 if image.get_width() <= FoxHud.INVENTORY_SIZE and image.get_height() <= FoxHud.INVENTORY_SIZE: 554 if image.get_width() <= FoxHud.INVENTORY_SIZE and image.get_height() <= FoxHud.INVENTORY_SIZE:
555 self.inventory_image = image 555 self.inventory_image = image
556 else: 556 else:
557 self.inventory_image = pygame.transform.smoothscale(image, (new_width, new_height)) 557 self.inventory_image = pygame.transform.smoothscale(image, (new_width, new_height))
558 sprite.kill() # ensure we don't leak into the scene at any point 558 sprite.kill() # ensure we don't leak into the scene at any point
588 fan.remove() 588 fan.remove()
589 self._me.has_fan = True 589 self._me.has_fan = True
590 self.shape = 'human_with_fan' 590 self.shape = 'human_with_fan'
591 self._me.shape = self.shape 591 self._me.shape = self.shape
592 self.set_image() 592 self.set_image()
593