def fire(self, level): if self.fire_delay == 0: play_sound("fire") self.fire_delay = SPIDER_FIRE_DELAY fire_direction = get_direction(self.attached) level.objects.append(Projectile(self.screen, self.x, self.y, fire_direction[0]*-SPIDER_PROJECTILE_SPEED, fire_direction[1]*-SPIDER_PROJECTILE_SPEED, SPIDER_DAMAGE, "energy")) return
def startMovement(self): if self.target is None: return direction = util.get_direction(self.precisePos, self.target) speed = self.getCurrSpeed() for i in range(2): self.vel[i] = direction[i] * speed
def fire(self, level): if self.fire_delay == 0: play_sound("fire") self.fire_delay = SPIDER_FIRE_DELAY fire_direction = get_direction(self.attached) level.objects.append( Projectile(self.screen, self.x, self.y, fire_direction[0] * -SPIDER_PROJECTILE_SPEED, fire_direction[1] * -SPIDER_PROJECTILE_SPEED, SPIDER_DAMAGE, "energy")) return
def update(self): self.handle_move_frame() if self.prev_gun is not self.gun: if self.gun is type(Pistol): self.image = pygame.image.load( 'PlayerSprites/Images/handgun/move/survivor-move_handgun_0.png' ) elif self.gun is type(AssualtRifle1) or type(AssualtRifle2): self.image = pygame.image.load( 'PlayerSprites/Images/rifle/move/survivor-move_rifle_0.png' ) elif self.gun is type(SubMachine2) or type(SubMachine1): self.image = pygame.image.load( 'PlayerSprites/Images/shotgun/move/survivor-move_shotgun_0.png' ) self.image = pygame.transform.scale(self.image, (50, 33)) self.rect = self.image.get_rect() self.rect.center = self.loc.as_tuple() self.prev_gun = self.gun self.sensor_reset_time -= 1 self.bullet_time -= 1 self.shoot_delay -= 1 if self.sensor_reset_time < 0: self.sensor_range = 150 self.last_loc = PixelLoc(self.rect.x, self.rect.y) self.rect.x, self.rect.y = self.loc.as_tuple() self.sensor_circle.center = self.loc.as_tuple() x, y = pygame.mouse.get_pos() if self.is_bot(): if self.goal: self.direction = get_direction(self.loc, self.goal.to_pixel()) else: self.direction = get_direction(self.loc, PixelLoc(x, y)) self.dirty = 1 self.rotate()
def resolveBattle(self, result): for i in range(2): self.pendingBattle[i].stop() if i == 0: temp = [1, 0] else: temp = [0, 1] temp2 = util.get_direction(self.pendingBattle[temp[0]].precisePos, self.pendingBattle[temp[1]].precisePos) retreat = [] for j in range(2): retreat.append(temp2[j] * RETREAT_DISTANCE) if result[i] == 1: for j in range(2): self.pendingBattle[i].addToPos[j] += retreat[j]
def on_notify(self,event): message = None color = C_MENU ### Combat events ### if event.event_type == EVENT_ATTACK: color = C_COMBAT_MSG if event.hit: if event.degree == 1: adjective = 'glancing' elif event.degree == 2: adjective = 'solid' elif event.degree == 3: adjective = 'well-placed' else: adjective = 'critical' if event.killed: message = '%s landed a %s hit, killing %s' % \ (event.actor.creature.name, adjective, event.target.creature.breed.name) else: message = '%s landed a %s hit on %s, dealing %i damage' % \ (event.actor.creature.name, adjective, event.target.creature.name, event.dealt) else: message = '%s missed %s' % \ (event.actor.creature.name, event.target.creature.name) ### Trait events ### elif event.event_type == EVENT_ADD_TRAIT: message = 'Trait \'%s\' added to %s' % \ (event.trait.name, event.body_part.name) color = C_EFFECT_MSG elif event.event_type == EVENT_REMOVE_TRAIT: message = "Trait \'%s\' removed from %s" % \ (event.trait.name, event.body_part.name) color = C_EFFECT_MSG ### Word events ### elif event.event_type == EVENT_INSCRIBE: message = "You feel the powers of %s %s through your %s" % \ (event.word.name, event.word.verb, event.body_part.name) color = event.word.color elif event.event_type == EVENT_ERASE: message = "You feel the powers of %s leave your %s" % \ (event.word.name, event.body_part.name) color = event.word.color ### Ability events ### elif event.event_type == EVENT_RESOLVE_ABILITY: message = event.ability.message if event.ability.color: color = event.ability.color elif event.event_type == EVENT_CANCEL: message = "Canceled" ### Misc events ### elif event.event_type == EVENT_WAKE_UP: if self.game.player.fov(event.actor): message = "%s wakes up"%event.actor.creature.name color = C_MENU elif event.event_type == EVENT_NOTICE: message = "%s notices you"%event.actor.creature.name color = C_MENU elif event.event_type == EVENT_STUMBLE: if event.actor == self.game.player: message = "You stumble loudly" color = C_MENU elif event.event_type == EVENT_HEAR: if (event.actor == self.game.player and event.pos != event.actor.pos): direction = util.get_direction(event.actor.x, event.actor.y, *event.pos) message = "You hear something to the %s"%direction color = C_MENU elif event.event_type == EVENT_HARVEST: message = "Player harvested a corpse!" color = event.majority_material.color elif event.event_type == EVENT_HEAL: message = "Player healed %s" % event.part.name color = C_EFFECT_MSG ### Debug events ### elif event.event_type == EVENT_TOGGLE_GHOST: message = "Ghost mode %s" % \ ('disabled','enabled')[event.enabled] color = C_DEBUG_MSG elif event.event_type == EVENT_EXPLORE_EXPLORABLE: message = "Reachable tiles explored" color = C_DEBUG_MSG elif event.event_type == EVENT_EXPLORE_ALL: message = "Map explored" color = C_DEBUG_MSG elif event.event_type == EVENT_PRINT_POS: message = "Player at (%i,%i)" % event.entity.pos color = C_DEBUG_MSG elif event.event_type == EVENT_PRINT_ROOM: room = self.game.cur_level.get_room_at(*event.pos) if room: message = "In room %i, tags: %s" % \ (room.room_id, ', '.join(room.tags)) else: message = "Not in a room" color = C_DEBUG_MSG else: logger.warning('Failed to handle %s'%event.event_type.upper()) if message and color: message_lines = textwrap.wrap(message, LOG_W-2) for line in message_lines: self.lines.append((message,color)) logger.info(message) print message