def resolve_mines_and_bullet(self, bullet): for mine in self.level.mines: if cd.sprite_collide(mine, bullet): self.level.play_sound("tank_explode") self.bullet_explode(bullet) self.mine_explode(mine) break
def resolve_powerups(self): for powerup in self.level.powerups: for player in self.level.player_tanks: if not powerup.taken: if powerup.can_take(player) and cd.sprite_collide(player, powerup): self.level.play_sound("pickup", 0.2) powerup.take(player) player.taking.add(powerup)
def resolve_explosions(self): for explosion in self.level.explosions: for mine in self.level.mines: if not mine.expired() and explosion.damages and cd.sprite_collide(explosion, mine): self.level.play_sound("tank_explode") self.mine_explode(mine) for shield in self.level.shields: if shield.active and explosion.damages and cd.sprite_collide(shield, explosion): self.level.play_sound("shield_die") shield.die() explosion.damaged.add(shield.tank) for tank in self.level.all_tanks(): if explosion.damages and not tank in explosion.damaged and cd.sprite_collide(tank, explosion): #self.level.stats.bullet_hit(explosion.bullet, tank) if self.tank_damage(tank): self.level.play_sound("tank_explode") # TODO, add a bullet origin to explosions so they can be # credited to the correct player. #self.level.stats.kill(explosion.bullet, tank) explosion.damaged.add(tank)
def left_click(self, position, pressed): for toolbar in self.toolbars: rect = pygame.Rect(toolbar.position, (toolbar.width, toolbar.height)) if rect.collidepoint(position): toolbar.left_click(position, pressed) if self.mode == MODE_ADD: entity = self.get_entity(position) # make sure the entity doesn't intersect any others for other_entity in self.entities: if cd.sprite_collide(entity, other_entity): return # make sure the entity creation is in bounds if not sphere_in_bounds(position, entity.data.ratio / 2, editor_constants.EDITOR_AREA_BOUNDS): return if entity.name != "PLAYER" or not self.player_exists: self.add_action(AddEntityAction, entity) elif self.mode == MODE_SELECT: for entity in self.entities: if entity.contains_point(position): ctrl = (pressed[pygame.K_LCTRL] or pressed[pygame.K_RCTRL]) self.selection_click(entity, ctrl) break elif self.mode == MODE_TILE: for tile in self.tiles: if cd.sprite_contains(tile, position.scale(constants.TILE_SIZE)): tile.toggle_type() elif self.mode == MODE_WAYPOINT: ctrl = (pressed[pygame.K_LCTRL] or pressed[pygame.K_RCTRL]) if ctrl: if self.waypoint_entity_selected is not None: self.add_action(AddWaypointAction, self.waypoint_entity_selected, Entity("WAYPOINT", editor_constants.WAYPOINT_DATA, position, self.font_manager)) else: for entity in self.entities: if entity.name == "ENEMY" and entity.contains_point(position): if self.waypoint_entity_selected is not None: self.waypoint_entity_selected.select(False) self.waypoint_entity_selected = entity entity.select(True)
def resolve_tanks_and_mine(self, mine): for tank in self.level.all_tanks(): if not mine.exploding and not mine.expired() and not tank.dead and mine.active() and cd.sprite_collide(tank, mine.collision_circle): self.level.play_sound("tank_explode") self.mine_attack(mine, tank)