def player_hit(self): """Method called when the player is hit by an ennemy ship or bullet. Make a recovery time for the ship after collision""" if not(self.playership.recover): AudioManager.play_sound("explosion") self.life -= 1 self.playership.recover = True self.score_multiplier = 1
def destroy(self): """Called when the ennemy is destroyed. Might spawn a bonus.""" AudioManager.play_sound("explosion2") if random.random() < POWERUP_SPAWN_RATE: ef = get_random_powerup()() hitbox = Rectangle(self.hitbox.x, self.hitbox.y, 32, 32) pw = WorldPowerUp(hitbox, ef, random.random() < POWERUP_MYSTERY_RATE) self.world.powerups.append(pw)
def apply_effect(self, effect): AudioManager.play_sound("powerup") if effect.effecttype is not None and effect.effecttype in self.powerup_sockets: self.powerup_sockets[effect.effecttype].remove(self) self.powerup_sockets.pop(effect.effecttype) effect.apply(self) self.powerup_sockets[effect.effecttype] = effect if effect.time > 0: print("BITE") self.time_effects[effect] = effect.time
def handle_event(self, event): if event.type == SDL_QUIT: sys.exit("Closing the game...") self.running = False elif event.type == SDL_KEYDOWN and event.key.repeat == 0: key = event.key.keysym.sym if key == SDLK_UP: self.world.playership.vely = -self.playership.maxspeed elif key == SDLK_DOWN: self.world.playership.vely = self.playership.maxspeed elif key == SDLK_LEFT: self.world.playership.velx = -self.playership.maxspeed elif key == SDLK_RIGHT: self.world.playership.velx = self.playership.maxspeed elif key == SDLK_SPACE: self.shooting = True elif key == SDLK_p and self.playership.shootingdelay > 0: self.playership.shootingdelay /= 2 elif key == SDLK_m: self.playership.shootingdelay *= 2 elif key == SDLK_ESCAPE: self.running = False elif key == SDLK_F1: self.debug_info = not self.debug_info elif key == SDLK_F2: # self.pause = not self.pause AudioManager.play_sound("bleep") pauseState = Pause(self.graphics, self) pauseState.run() AudioManager.play_sound("bleep") self.clock.tick() elif key == SDLK_e: self.test_effect1.apply(self.playership) elif key == SDLK_r: self.test_effect2.apply(self.playership) elif event.type == SDL_KEYUP: key = event.key.keysym.sym if key == SDLK_RIGHT: if self.playership.velx > 0: self.playership.velx = 0 elif key == SDLK_LEFT: if self.playership.velx < 0: self.playership.velx = 0 elif key == SDLK_DOWN: if self.playership.vely > 0: self.playership.vely = 0 elif key == SDLK_UP: if self.playership.vely < 0: self.playership.vely = 0 elif key == SDLK_SPACE: self.shooting = False
def __init__(self, x, y, velx=0, vely=-900, damage=8): self.hitbox = Rectangle(x, y, 8, 8) self.velx = velx # px/s self.vely = vely self.damage = damage AudioManager.play_sound("laser")