def move(self, enemy, player): to_update = [] if len(self.player_bullets) > 0: to_delete = [] player_bullet_speed = [0, -600] player_bullet_speed = frametime.modify_speed(player_bullet_speed) enemies = enemy.getEnemies() to_delete = [] to_update += self.player_bullets for i in range(len(self.player_bullets)): self.screen.blit(self.blackSurface, self.player_bullets[i]) self.player_bullets[i] = self.player_bullets[i].move(player_bullet_speed) self.screen.blit(self.bullet, self.player_bullets[i]) # If bullet goes off the top of the screen if self.player_bullets[i].top < 0: to_delete.append(i) # If bullet hits an enemy collision = self.player_bullets[i].collidelist([x.enemyrect for x in enemies]) if collision != -1: to_delete.append(i) to_update.append(enemy.remove(collision)) for x in to_delete: self.player_bullet_remove(x) to_update += self.enemy_bullets if len(self.enemy_bullets) > 0: to_delete = [] enemy_bullet_speed = [0, 400] enemy_bullet_speed = frametime.modify_speed(enemy_bullet_speed) prect = player.get_player_rect() for i in range(len(self.enemy_bullets)): self.screen.blit(self.blackSurface, self.enemy_bullets[i]) self.enemy_bullets[i] = self.enemy_bullets[i].move(enemy_bullet_speed) self.screen.blit(self.bullet, self.enemy_bullets[i]) # If bullet goes off the top of the screen if self.enemy_bullets[i].bottom > properties.height: to_delete.append(i) collision = self.enemy_bullets[i].colliderect(prect) if collision: to_delete.append(i) player.give_damage(10) for x in to_delete: self.enemy_bullet_remove(x) to_update += self.player_bullets to_update += self.enemy_bullets return to_update
def move_right(self): to_update = [] to_update += [self.pshiprect] if self.pshiprect.right < self.width: move_right = [325, 0] move_right = frametime.modify_speed(move_right) self.screen.blit(self.blackSurface, self.pshiprect) self.pshiprect = self.pshiprect.move(move_right) self.screen.blit(self.pship, self.pshiprect) to_update += [self.pshiprect] return to_update
def move_left(self): to_update = [] to_update += [self.pshiprect] if self.pshiprect.left > 0: move_left = [-325, 0] move_left = frametime.modify_speed(move_left) self.screen.blit(self.blackSurface, self.pshiprect) self.pshiprect = self.pshiprect.move(move_left) self.screen.blit(self.pship, self.pshiprect) to_update += [self.pshiprect] return to_update
def update(self, bullet): self.fire(bullet) #fires if possible move_speed = [0, 150] move_speed = frametime.modify_speed(move_speed) self.enemyrect = self.enemyrect.move(move_speed)