def draw_on_surface(self, surface, game_board): if not self.start_explosion: time_before = self.time self.time = pygame.time.get_ticks() elapsed = self.time - time_before self.x_position -= int(elapsed * self.speed) self.image.rect.left = int(self.x_position) if random.randint(1, 6) == 6: time_now = pygame.time.get_ticks() if self.last_fire_time + self.fire_time_delay < time_now: bullet = BulletSprite(False) bullet.image.rect.left = self.image.rect.left + self.image.rect.width / 2 - 4 bullet.image.rect.top = self.image.rect.top + self.image.rect.height / 2 - 9 bullet.rect = bullet.image.rect game_board.enemy_group.add(bullet) self.last_fire_time = time_now super(EnemySprite, self).draw_on_surface(surface, game_board) else: if self.explosion_frame != 15: tmp_rect = self.image.rect self.image = ImageObject('explosion-%d.png' % self.explosion_frame) self.image.rect = tmp_rect self.explosion_frame += 1 super(EnemySprite, self).draw_on_surface(surface, game_board)
def fire_bullet(self, bullets_group): time_now = pygame.time.get_ticks() if self.last_fire_time + self.fire_delay < time_now: bullet = BulletSprite() bullet.image.rect.left = self.image.rect.left + self.image.rect.width / 2 bullet.image.rect.top = self.image.rect.top + (self.image.rect.height / 2 - 9) bullets_group.add(bullet) self.last_fire_time = time_now
def draw_on_surface(self, surface, game_board): if self.image.rect.left > 480: self.image.rect.left -= 1 self.pause_till = pygame.time.get_ticks() + 4500 if self.pause_till and self.pause_till < pygame.time.get_ticks(): self.image.rect.left -= 1 self.image.rect.top -= 1 if self.image.rect.top < -self.image.rect.height: game_board.enemy_group.remove(self) game_board.attempts_left -= 1 else: if self.moving_up: if self.image.rect.top > 0: self.image.rect.top -= 1 else: self.moving_up = False else: if self.image.rect.top < 470 - self.image.rect.height: self.image.rect.top += 1 else: self.moving_up = True if random.randint(1, 5) == 5: time_now = pygame.time.get_ticks() if self.last_fire_time + self.fire_time_delay < time_now: bullet = BulletSprite(False) bullet.image.rect.left = self.image.rect.left + self.image.rect.width / 2 if self.hole == 1: bullet.image.rect.top = self.image.rect.top + self.image.rect.height / 2 - 34 self.hole = 2 else: bullet.image.rect.top = self.image.rect.top + self.image.rect.height / 2 + 20 self.hole = 1 bullet.rect = bullet.image.rect game_board.enemy_group.add(bullet) self.last_fire_time = time_now super(BossSprite, self).draw_on_surface(surface, game_board)