def update(self): self.background.update(self.screen) self.menubar.update(self.screen, self.suns) x, y = pygame.mouse.get_pos() # Draws from right to left for row in self.cells: for cell in reversed(row): cell.update(self.screen) # Transparent image of chosen plant if cell.isempty() and self.plant_choice is not None \ and cell.rect.collidepoint((x, y)) and \ self.plant_choice.__class__.__name__ != "Shovel": # In the middle of the cell self.screen.blit( transform_image(self.plant_choice_image), cell.get_middle_pos(self.plant_choice_image)) self.lawnmowers_update() # Start drawing from right top for zombie in sorted(self.zombies.sprites(), key=lambda z: z.row * c.XCells + z.col): zombie.update(self.screen) self.zombie_targeting() # Draw choice near the mouse if self.plant_choice is not None: self.screen.blit(self.plant_choice_image, (x - self.plant_choice_image.get_width() / 2, y - self.plant_choice_image.get_height())) self.projectiles.update(self.screen) self.projectile_collisions_check() self.suns_group.update(self.screen)
def _draw(self, screen): image = self.image if self.next_white: image = transform_image(image, r=64, g=64, b=64, alpha=5, special_flag=BLEND_RGBA_ADD) self.next_white -= 1 screen.blit(image, self.rect)
def _draw(self, screen): """ Rotates and draws sun on the display :param screen: Surface """ self.angle += 1 self.angle %= 360 image = pygame.transform.rotate(self.image, self.angle) c = self.rect.center self.rect = image.get_rect() self.rect.center = c # Make sun transparent after time image = transform_image(image=image, alpha=255 if self.despawn_time > fps * 5 else int(self.despawn_time / fps / 5 * 255)) screen.blit(image, self.rect)
def take_damage(self, bullet): """ Takes damage from bullet and removes it Also makes self image blue if projectile.__class__ == SnowProjectile :param bullet: Projectile :return: None """ bullet.deal_damage(self) self.check_alive() bullet.kill() if bullet.__class__.__name__ == "SnowProjectile": self.frozen = bullet.freeze_time # Freezes zombie self.image = transform_image(self.image, r=0, g=0, b=128, alpha=5, special_flag=BLEND_RGBA_ADD) self.frozen_sound.play() self.shot = True
def update(self, screen): """ Called every tick Updates zombie Either makes zombie go or attack Regarding freeze caused py SnowPea's Which makes everything slower :param screen: pygame.display :return: None """ # Placed separately not to over complicate if/else statements if self.incinerated: self.incinerated -= 1 if self.incinerated % self.animation_frame == 0: self.image = next(self.ignited) self._draw(screen) if self.incinerated == 0: self.kill() return self.counter += 1 # Walk animation # Or damage infliction if self.counter % self.animation_frame == 0: self.image = next(self.images) # If zombie is frozen makes its image blue if self.frozen: self.frozen -= 1 self.image = transform_image(self.image, r=0, g=0, b=128, alpha=5, special_flag=BLEND_RGBA_ADD) # If zombie is hit makes it lighter if self.shot: self.shot = False self.image = transform_image(self.image, r=64, g=64, b=64, alpha=5, special_flag=BLEND_RGBA_ADD) if not self.busy(): # If zombie is not eating # Movement if not self.frozen: self.x -= self.speed else: self.x -= self.frozen_speed self.rect.x = int(self.x) + 1 # Using flooring because pygame rect doesn't support not-int coordinates else: # Damage infliction if (not self.frozen and self.counter % self.reload == 0) or \ (self.counter % self.frozen_reload == 0): random.choice(self.chomps).play() self.deal_damage() if self.counter % self.groan == 0: random.choice(self.groans).play() self.counter %= lcm(self.reload, self.animation_frame, self.groan) # Update cell on the game field self.col = int( (self.rect.x - c.pads["game"][0] + c.sizes["cell"][0] / 2) // c.sizes["cell"][0]) self._draw(screen)