def ricochet(self): self.bounces += 1 if self.bounces > self.bounce_limit: self.destroy() else: sound.play_sfx("bullet_bonk") self.shooter_id = -1
def explode(self): main.effects.append(Effect("explosion2", self.x + 0.5, self.y + 0.5)) for x in range(floor(-MINEWALLRANGE), ceil(MINEWALLRANGE + 1)): for y in range(floor(-MINEWALLRANGE), ceil(MINEWALLRANGE + 1)): tx = max(min(int(self.x + x), FIELDWIDTH - 1), 0) ty = max(min(int(self.y + y - 1), FIELDHEIGHT - 1), 0) if sqrt(x**2 + y**2) <= MINEWALLRANGE and main.map[tx][ty] in [ None, "dwall1", "dwall2", "dwall3" ]: main.map[tx][ty] = None main.effects.append( Effect("smoke1", self.x + x + 0.5, self.y + y - 0.5, False, sqrt(x**2 + y**2) * 3)) main.mines.remove(self) main.draw_to_bg(main.assets["scorch_mine"], self.x + 0.5, self.y + 0.5) for m in main.mines: if sqrt((self.x - m.x)**2 + (self.y - m.y)**2) <= MINERANGE: m.explode() for t in main.tanks: if sqrt((self.x - t.x)**2 + (self.y - (t.y + 1))**2) <= MINERANGE: t.destroy() self.callback() main.redraw_shadow() sound.play_sfx("explosion")
def place_mine(self): if self.mines_placed < self.mine_limit and not self.dead and not self.stop and ( int(self.x + 0.5), int(self.y + 1.5)) not in [ (m.x, m.y) for m in main.mines ]: main.mines.append( Mine(int(self.x + 0.5), int(self.y + 1.5), self.mine_callback)) self.mines_placed += 1 sound.play_sfx("mine_place")
def destroy(self): # return if not self.dead: self.dead = True main.effects.append(Effect("explosion1", self.x + 0.5, self.y + 1)) main.draw_to_bg(main.assets["scorch_tank"], self.x + 0.5, self.y + 1.5) sound.remove_mission_loop(self.type) sound.play_sfx("explosion") if main.tanks.index(self) != 0: sound.play_sfx("tank_hit")
def shoot(self): x = self.x + cos(self.aim * 2 * pi) y = self.y + sin(self.aim * 2 * pi) if not self.dead and not self.stop and self.bullets_shot < self.bullet_limit and main.map[ int(x + 0.5)][int(y + 0.5)] == None: if self.shot_cooldown <= 0: self.shot_cooldown = TANKSHOTCOOLDOWN main.bullets.append( Bullet(x, y, self.aim, self.bullet_bounce, self.rocket, main.tanks.index(self), self.bullet_callback)) self.bullets_shot += 1 sound.play_sfx("tank_shoot") else: self.shot_queue += 1
def tick(self, tick_time): if not self.dead: try: self.ai(self, tick_time) except: pass if self.shot_queue > 0 and self.shot_cooldown <= 0: self.shot_queue -= 1 self.shoot() self.shot_cooldown = TANKSHOTCOOLDOWN else: self.shot_cooldown -= 1 self.moving = self.movement != [0, 0] if self.moving: self.body_target = atan2(self.movement[1], self.movement[0]) / 2 / pi self.movement = [0, 0] if abs(self.body_target - self.body) > 0.25: self.body += copysign(0.5, self.body_target - self.body) if abs(self.body_target - self.body) < TANKBODYSPEED: self.body = self.body_target elif self.moving: self.body += copysign(TANKBODYSPEED, self.body_target - self.body) if abs(self.aim_target - self.aim) > 0.5: self.aim += copysign(1, self.aim_target - self.aim) self.aim += (self.aim_target - self.aim) * self.aim_speed if self.moving: self.track_counter += TRACKSPEED * self.speed self.move_sound_counter += MOVESOUNDSPEED * self.speed if self.move_sound_counter >= 1: self.move_sound_counter -= 1 sound.play_sfx("tank_move")
def _play_special(self): soundd = self.animFolder sound.play_sfx('sounds/sfx/' + soundd + '/special.wav')
def _play_jump(self): soundd = self.animFolder sound.play_sfx('sounds/sfx/' + soundd + '/jump.wav')
def _play_attack(self): soundd = self.animFolder sound.play_sfx('sounds/sfx/' + soundd + '/hit (%s).wav' % random.randint(1, 7))
def update(self): evman = eventmanager.get() if evman.MOUSE1CLICK != False: event = evman.MOUSE1CLICK clickpoint = event.pos #StartMenu if not self.show_instructions and not self.show_options and not self.show_level: #new game if self.newgame_button.get_rect().collidepoint(clickpoint): #self.currentLevel = 0 self.show_level = True #load game elif self.loadgame_button.get_rect().collidepoint(clickpoint): if os.path.isfile('save'): self.loadLevel = True #options elif self.options_button.get_rect().collidepoint(clickpoint): self.show_instructions = False self.show_options = True #exit elif self.quit_button.get_rect().collidepoint(clickpoint): print("Exiting....") sys.exit(0) #isntructions elif self.instructions_button.get_rect().collidepoint(clickpoint): self.show_options = False self.show_instructions = True #Options Menu elif self.show_options: if self.volup_button.get_rect().collidepoint(clickpoint): #clicked bgm vol up sound.set_bgm_vol(sound.get_bgm_vol() + 10) sys.stdout.write('BGM vol: %s\n' % (sound.get_bgm_vol())) elif self.voldown_button.get_rect().collidepoint(clickpoint): #clicked bgm vol down sound.set_bgm_vol(sound.get_bgm_vol() - 10) sys.stdout.write('BGM vol: %s\n' % (sound.get_bgm_vol())) elif self.volupFX_button.get_rect().collidepoint(clickpoint): #clicked sfx vol up sound.set_sfx_vol(sound.get_sfx_vol() + 10) sound.play_sfx('sounds/sfx/punch.wav') sys.stdout.write('SFX vol: %s\n' % (sound.get_sfx_vol())) elif self.voldownFX_button.get_rect().collidepoint(clickpoint): #clicked sfx vol down sound.set_sfx_vol(sound.get_sfx_vol() - 10) sound.play_sfx('sounds/sfx/punch.wav') sys.stdout.write('SFX vol: %s\n' % (sound.get_sfx_vol())) elif self.gammaUp_button.get_rect().collidepoint(clickpoint): #clicked gamma up if self.gamma < 2.5: self.gamma = self.gamma + .1 pygame.display.set_gamma(self.gamma) sys.stdout.write('Gamma: %s\n' % (self.gamma)) elif self.gammaDown_button.get_rect().collidepoint(clickpoint): #clicked gamma down if self.gamma > 0.2: self.gamma = self.gamma - .1 pygame.display.set_gamma(self.gamma) sys.stdout.write('Gamma: %s\n' % (self.gamma)) elif self.options_back_button.get_rect().collidepoint(clickpoint): #clicked back self.show_options = False #Options Menu elif self.show_level: if self.lvltut.get_rect().collidepoint(clickpoint): self.setLevel(0) elif self.lvl1.get_rect().collidepoint(clickpoint): self.setLevel(1) elif self.lvl2.get_rect().collidepoint(clickpoint): self.setLevel(2) elif self.lvl3.get_rect().collidepoint(clickpoint): self.setLevel(3) elif self.lvl4.get_rect().collidepoint(clickpoint): self.setLevel(4) elif self.lvl5.get_rect().collidepoint(clickpoint): self.setLevel(5) #if on instructions go back to StartMenu else: if self.back_button.get_rect().collidepoint(clickpoint): if self.show_instructions: self.show_instructions = False elif self.show_options: self.show_options = False
def destroy(self): main.effects.append( Effect("particle1", self.x + 0.5, self.y + 1, False)) self.callback() main.bullets.remove(self) sound.play_sfx("bullet_crash")
def update(self): evman = eventmanager.get() if evman.MOUSE1CLICK != False: event = evman.MOUSE1CLICK clickpoint = event.pos #StartMenu if not self.show_instructions and not self.show_options and not self.show_level: #new game if self.newgame_button.get_rect().collidepoint(clickpoint): #self.currentLevel = 0 self.show_level = True #load game elif self.loadgame_button.get_rect().collidepoint(clickpoint): if os.path.isfile('save'): self.loadLevel = True #options elif self.options_button.get_rect().collidepoint(clickpoint): self.show_instructions = False self.show_options = True #exit elif self.quit_button.get_rect().collidepoint(clickpoint): print("Exiting....") sys.exit(0) #isntructions elif self.instructions_button.get_rect().collidepoint( clickpoint): self.show_options = False self.show_instructions = True #Options Menu elif self.show_options: if self.volup_button.get_rect().collidepoint(clickpoint): #clicked bgm vol up sound.set_bgm_vol(sound.get_bgm_vol() + 10) sys.stdout.write('BGM vol: %s\n' % (sound.get_bgm_vol())) elif self.voldown_button.get_rect().collidepoint(clickpoint): #clicked bgm vol down sound.set_bgm_vol(sound.get_bgm_vol() - 10) sys.stdout.write('BGM vol: %s\n' % (sound.get_bgm_vol())) elif self.volupFX_button.get_rect().collidepoint(clickpoint): #clicked sfx vol up sound.set_sfx_vol(sound.get_sfx_vol() + 10) sound.play_sfx('sounds/sfx/punch.wav') sys.stdout.write('SFX vol: %s\n' % (sound.get_sfx_vol())) elif self.voldownFX_button.get_rect().collidepoint(clickpoint): #clicked sfx vol down sound.set_sfx_vol(sound.get_sfx_vol() - 10) sound.play_sfx('sounds/sfx/punch.wav') sys.stdout.write('SFX vol: %s\n' % (sound.get_sfx_vol())) elif self.gammaUp_button.get_rect().collidepoint(clickpoint): #clicked gamma up if self.gamma < 2.5: self.gamma = self.gamma + .1 pygame.display.set_gamma(self.gamma) sys.stdout.write('Gamma: %s\n' % (self.gamma)) elif self.gammaDown_button.get_rect().collidepoint(clickpoint): #clicked gamma down if self.gamma > 0.2: self.gamma = self.gamma - .1 pygame.display.set_gamma(self.gamma) sys.stdout.write('Gamma: %s\n' % (self.gamma)) elif self.options_back_button.get_rect().collidepoint( clickpoint): #clicked back self.show_options = False #Options Menu elif self.show_level: if self.lvltut.get_rect().collidepoint(clickpoint): self.setLevel(0) elif self.lvl1.get_rect().collidepoint(clickpoint): self.setLevel(1) elif self.lvl2.get_rect().collidepoint(clickpoint): self.setLevel(2) elif self.lvl3.get_rect().collidepoint(clickpoint): self.setLevel(3) elif self.lvl4.get_rect().collidepoint(clickpoint): self.setLevel(4) elif self.lvl5.get_rect().collidepoint(clickpoint): self.setLevel(5) #if on instructions go back to StartMenu else: if self.back_button.get_rect().collidepoint(clickpoint): if self.show_instructions: self.show_instructions = False elif self.show_options: self.show_options = False