def fire(self): if self.stun_timer: self.animation_list.play('HurtFire', self.animation_list.current_frame) else: self.animation_list.play('Fire') if self.fire_timer <= 0: utility.play_sound(self.fire_sound[random.randint(0, 2)], PLAYER_CHANNEL) if self.velocity[:] != vector.Vector2d.zero: bullet_velocity = vector.Vector2d(self.velocity) bullet_velocity.set_magnitude(self.bullet_speed) new_bullet = bullet.Bullet(self.position, bullet_velocity, self.effects_group, self.bullet_damage, self.bullet_bound_style, self.bullet_collide_style) new_bullet.set_owner(self) if self.reflect_bonus and self.damage_bonus: new_bullet.animation_list.play('DamageReflect') elif self.bullet_collide_style == COLLIDE_STYLE_REFLECT: new_bullet.animation_list.play('Reflect') elif self.bullet_damage > 1: new_bullet.animation_list.play('Damage') self.bullet_group.add(new_bullet) self.fire_timer = self.reset_fire_timer if self.dual_shot: if self.velocity: bullet_velocity = vector.Vector2d(self.velocity * -1) bullet_velocity.set_magnitude(self.bullet_speed) new_bullet = bullet.Bullet( (self.position), (bullet_velocity), self.effects_group, self.bullet_damage, self.bullet_bound_style, self.bullet_collide_style) new_bullet.set_owner(self) if self.reflect_bonus and self.damage_bonus: new_bullet.animation_list.play('DamageReflect') elif self.bullet_collide_style == COLLIDE_STYLE_REFLECT: new_bullet.animation_list.play('Reflect') elif self.bullet_damage > 1: new_bullet.animation_list.play('Damage') self.bullet_group.add(new_bullet)
def fire(self): ''' player shooting. including bullets and bomb as power increases, the bullets from player will enhances. max enhences will applies when power = 4 ''' if not self.fire_cold_down: if 0 <= self.power: b = bullet.Bullet(self.parent, 'flow1') b.position = self.position b.damage = 2 b.velocity = vector.objVector(0, -2000 * MEASURE_UNIT) self.parent.bullet_group.add(b) if 1 <= self.power: b1 = bullet.Bullet(self.parent, 'track1') b1.position = self.position + vector.objVector(-30, 100) b1.damage = 0.2 b1.velocity = vector.objVector(0, -2000 * MEASURE_UNIT) b2 = bullet.Bullet(self.parent, 'track1') b2.position = self.position + vector.objVector(20, 100) b2.damage = 0.2 b2.velocity = vector.objVector(0, -2000 * MEASURE_UNIT) self.parent.bullet_group.add(b1) self.parent.bullet_group.add(b2) if 2 <= self.power: b1 = bullet.Bullet(self.parent, 'track2') b1.position = self.position + vector.objVector(-50, 100) b1.damage = 0.3 b1.velocity = vector.objVector(0, -2000 * MEASURE_UNIT) b2 = bullet.Bullet(self.parent, 'track2') b2.position = self.position + vector.objVector(40, 100) b2.damage = 0.3 b2.velocity = vector.objVector(0, -2000 * MEASURE_UNIT) self.parent.bullet_group.add(b1) self.parent.bullet_group.add(b2) if 3 <= self.power: b1 = bullet.Bullet(self.parent, 'flow1') b1.position = self.position + vector.objVector(20, 0) b1.damage = 1 b1.velocity = vector.objVector(0, -2000 * MEASURE_UNIT) b2 = bullet.Bullet(self.parent, 'flow1') b2.position = self.position + vector.objVector(-20, 0) b2.damage = 1 b2.velocity = vector.objVector(0, -2000 * MEASURE_UNIT) self.parent.bullet_group.add(b1) self.parent.bullet_group.add(b2) if 4 <= self.power: b = bullet.Bullet(self.parent, 'flow2') b.position = self.position + vector.objVector(0, -30) b.damage = 0.5 b.velocity = vector.objVector(0, -3000 * MEASURE_UNIT) self.parent.bullet_group.add(b) self.fire_cold_down = FRAME_PER_SECOND / 15
def event_handler(self): for event in pygame.event.get(): if event.type == 12: pygame.quit() sys.exit() elif event.type == settings.ENEMY1_CREAT_EVENT: enemy1 = enemy.EnemySmall() self.enemy_group.add(enemy1) elif event.type == settings.ENEMY2_CREAT_EVENT: enemy2 = enemy.EnemyMid() self.enemy_group2.add(enemy2) elif event.type == settings.HERO_FIRE_EVENT: bullet1 = bullet.Bullet(self.my_plane.rect.centerx,self.my_plane.rect.top) settings.music_event(r'%s\material\sound\bullet.wav'% settings.BASE_DIR) self.bullet_group.add(bullet1) key_pressed = pygame.key.get_pressed() if key_pressed[pygame.K_w] or key_pressed[pygame.K_UP] : self.my_plane.move_up() if key_pressed[pygame.K_s] or key_pressed[pygame.K_DOWN]: self.my_plane.move_down() if key_pressed[pygame.K_a] or key_pressed[pygame.K_LEFT]: self.my_plane.move_left() if key_pressed[pygame.K_d] or key_pressed[pygame.K_RIGHT]: self.my_plane.move_right()
def give_bonus(self): stars_to_create = 15 while stars_to_create: stars_to_create -= 1 temp_bullet = bullet.Bullet(self.position, (BULLET_SPEED, 0), self.effects_group, 0, BOUND_STYLE_KILL, COLLIDE_STYLE_NOVA) temp_bullet.set_life_timer(13) temp_bullet.animation_list.play('Nova') temp_bullet.velocity.set_angle(stars_to_create * 24) # Bullet damage doesn't matter since these bullets automatically # kill whatever they touch temp_bullet.set_owner(self.object_collided_with) self.object_collided_with.bullet_group.add(temp_bullet)
def fire(self): for i in range(4): bullet1 = bullet.Bullet() bullet1.rect.centerx = self.rect.centerx bullet1.rect.bottom = self.rect.top - 20