def heal(self, delta_time): # Handles healing. if self.healing and self.health < 20: self.health += 1 else: arcade.unschedule(self.heal) self.healing = False
def moveBall(self, delta_time): self.ball.position_y += 22/120 self.ball.radius -= 12/80 if self.ball.radius <= 11: arcade.unschedule(self.moveBall) self.hole = BlackHole(self.ball.position_x, self.ball.position_y, self.ball.radius, arcade.color.BLACK)
def regen_cooldown(self, delta_time): # Handles cooldown on shrinking charge-up self.charge_cooling = False if self.charge < 20: self.shrink_charging = True arcade.schedule(self.shrink_charge_up, SHRINK_CHARGE_UP_SPEED) arcade.unschedule(self.regen_cooldown)
def playerShootEffect(self, delta_time: float): global app import math if self.player_shoot_active == False: arcade.unschedule(self.playerShootEffect) return else: # shoot degrees = [90.6, 90.55, 90.5, 90.45, 90.4, 90.35, 90.3, 90.25, 90.2, 90.15, 90.1, 90.05, 90.0] start_degree = 90.6 change = 0.05 for i in range(43): degrees.append(start_degree-change) start_degree -= change for degree in degrees: bullet = PlayerBullet("images/player_sprite.png", 0.15) bullet_speed = 10 start_x = self.player.center_x start_y = self.player.center_y bullet.center_x = start_x bullet.center_y = start_y bullet.angle = degree bullet.change_x = math.cos(degree) * bullet_speed bullet.change_y = math.sin(degree) * bullet_speed self.player_bullets.append(bullet) self.all_sprites.append(bullet)
def game_over(self): self.gameover = True self.gameovertext = arcade.Sprite("images/gameover.png", 0.75) self.all_sprites.append(self.gameovertext) self.gameovertext.center_x = self.width / 2 self.gameovertext.center_y = self.height / 2 arcade.unschedule(self.add_enemy) arcade.unschedule(self.add_pickup)
def destroy(self): self.enemies_list = arcade.SpriteList() self.lotus_list = arcade.SpriteList() self.all_sprites = arcade.SpriteList() arcade.unschedule(self.add_enemy) arcade.unschedule(self.add_lotus)
def hurt_reset(self, delta_time): # Handles changing the character sprite back to normal after hurt time ends if self.alive: if not self.multiplied: self.player_list[0].texture = self.player_list[ 0].player_textures[0] else: self.player_list[0].texture = self.player_list[ 0].player_textures[2] arcade.unschedule(self.hurt_reset)
def multiplier_reset(self, delta_time): if self.player_list[0].texture == self.player_list[0].player_textures[ 3]: self.player_list[0].texture = self.player_list[0].player_textures[ 1] else: self.player_list[0].texture = self.player_list[0].player_textures[ 0] self.multiplied = False self.multiplier = 1 arcade.unschedule(self.multiplier_reset)
def shrink_charge_up(self, delta_time): # Handles charging the player's shrink meter. Must be off cool down to activate. Only goes up to 20, # must kill enemies for overcharge. if self.charge < 20 and self.alive: self.charge += 1 else: self.shrink_charging = False arcade.unschedule(self.shrink_charge_up) # If holding the shrink button and gains a charge, shrinks. if self.charge == 1 and self.rmb_down: self.shrink()
def add_a_ducky(self, dt: Optional[float] = None) -> None: """Add a ducky to the scene, register some events and start animating.""" if not POINTS_HINT: return ducky = _sprites.Ducky(choice(constants.DUCKY_LIST), 0.05) self.events.hover(ducky, ducky.expand) self.events.out(ducky, ducky.shrink) self.ducks.append(ducky) seq = self.sequence_gen(random=True) self.animations.fire(ducky, seq) if len(self.ducks) >= DUCKS: arcade.unschedule(self.add_a_ducky)
def spawn_explosion(self, delta_time): self.bombs_to_spawn -= 1 if self.bombs_to_spawn > 0: explosion = Explosion(self.explosion_texture_list) explosion.center_x = random.randrange(0, SCREEN_WIDTH) explosion.center_y = random.randrange(0, SCREEN_HEIGHT) explosion.update() self.explosion_list.append(explosion) arcade.play_sound(self.bomb_burst_sounds[random.randrange(8)], volume=.005) else: arcade.unschedule(self.spawn_explosion)
def unshrink(self): # Handles unshrinking. self.shrunk = False self.player_sprite.scale = sprite_scaling_player arcade.unschedule(self.shrink_charge_down) # If firing, switch to big bullets. if self.firing_small and self.lmb_down: arcade.unschedule(self.fire_small) arcade.schedule(self.fire_big, COOLDOWN_BIG) self.firing_big = True self.firing_small = False
def on_key_press(self, key, modifiers): global game """Handle user keyboard input Q: Quit the game P: Pause/Unpause the game I/J/K/L: Move Up, Left, Down, Right Arrows: Move Up, Left, Down, Right Arguments: symbol {int} -- Which key was pressed modifiers {int} -- Which modifiers were pressed """ if key == arcade.key.Q: # Quit immediately arcade.close_window() if key == arcade.key.P: self.paused = not self.paused pause_menu = PauseMenu(self) game.show_view(pause_menu) if key == arcade.key.SPACE: if self.BONUS_AVAILABLE: if not self.HARDMODE_ACTIVE: # can't use bonus in hardmode ;) self.score += 10000 self.bonus_text = "" self.BONUS_ACTIVE = True self.BONUS_AVAILABLE = False self.bonus_count = 0 self.bonus_start_time = time.time() # Ability effect self.enemy_spawn_time += 0.5 arcade.unschedule(self.add_enemy) arcade.schedule(self.add_enemy, self.enemy_spawn_time) self.enemy_pre_change_velocity = self.enemy_velocity self.enemy_velocity = self.bonus_velocity_change for enemy in self.enemies_list: enemy.velocity = self.bonus_velocity_change if key == arcade.key.A or key == arcade.key.LEFT: self.player.change_x = -self.player_velocity self.left_key_down = True elif key == arcade.key.D or key == arcade.key.RIGHT: self.player.change_x = self.player_velocity self.right_key_down = True elif (key == arcade.key.W or key == arcade.key.UP) and self.VERTICAL_MOVEMENT: self.player.change_y = self.player_velocity self.up_key_down = True elif (key == arcade.key.S or key == arcade.key.DOWN) and self.VERTICAL_MOVEMENT: self.player.change_y = -self.player_velocity self.down_key_down = True
def doWarpWhenEffectComplete(self, deltaTime: float): effectComplete: bool = self._warpEffect.isEffectComplete() self.logger.info(f'Is warp effect complete {deltaTime} {effectComplete=}') if effectComplete is True: unschedule(self.doWarpWhenEffectComplete) self._view.window.show_view(self._view) # # Callback to someone (presumably top level view) to let them know # it is time to warp; # self._warpTravelCallback(self._warpSpeed, self._destinationCoordinates)
def shrink(self): # Handles shrinking the player. self.player_sprite.scale = sprite_scaling_player_shrunk # Stop charging the shrink meter and start removing charge. arcade.unschedule(self.shrink_charge_up) arcade.schedule(self.shrink_charge_down, SHRINK_CHARGE_DOWN_SPEED) self.shrunk = True # If firing, switch to small bullets. if self.firing_big and self.lmb_down: arcade.unschedule(self.fire_big) self.firing_small = True self.firing_big = False arcade.schedule(self.fire_small, COOLDOWN_SMALL)
def shrink_charge_down(self, delta_time): # Handles how long the player can shrink. if self.charge <= 20: self.charge -= 1 # Give the player a little extra leeway if in overcharge. elif self.charge < 23: self.charge = 20 else: self.charge -= 3 if self.charge == 0: self.unshrink() if self.charge_cooling: arcade.unschedule(self.regen_cooldown) arcade.schedule(self.regen_cooldown, 5) self.charge_cooling = True
def on_update(self, delta_time): if self.grid_view and not self.pause: self.pause = True if not self.pause: if 'bfs' in self.path.keys(): if self.path_index_bfs_change < 0 and self.path_index_bfs >= self.path_index_bfs_change * -1: self.path_index_bfs += self.path_index_bfs_change elif self.path_index_bfs_change > 0 and self.path_index_bfs < len( self.path['bfs']) - self.path_index_bfs_change: self.path_index_bfs += self.path_index_bfs_change if self.astar_trace_number == self.astar_trace_len and self.astar_trace_animate: self.astar_trace_animate = 0 print("Trace reached the end") ar.unschedule(self.increase_step_trace) self.path_draw['astar'] = True
def on_key_release(self, symbol, modifier): if symbol == ar.key.KEY_1: if self.path_draw['bfs']: self.path_draw['bfs'] = False else: self.path_draw['bfs'] = True elif symbol == ar.key.KEY_2: if self.path_draw['astar']: self.path_draw['astar'] = False else: self.path_draw['astar'] = True elif symbol == ar.key.RIGHT or symbol == ar.key.LEFT: self.path_index_bfs_change = 0 elif symbol == ar.key.SPACE: if self.path_index_bfs_change: self.path_index_bfs_change = 0 else: self.path_index_bfs_change = self.anim_speed elif symbol == ar.key.T: if self.astar_trace_animate: self.astar_trace_animate = 0 ar.unschedule(self.increase_step_trace) print("Trace Off") else: self.astar_trace_animate = 1 ar.schedule(self.increase_step_trace, 1 / self.astar_trace_speed) print("Trace On") elif symbol == ar.key.R: self.path_index_bfs = 0 self.astar_trace_number = 0 self.astar_trace_shadow = list() elif symbol == ar.key.P: if self.pause: self.pause = False else: self.pause = True elif symbol == ar.key.G: if self.grid_view: self.grid_view = False else: self.grid_view = True elif symbol == ar.key.V: if self.astar_show_values: self.astar_show_values = False else: self.astar_show_values = True
def execute(self, cast): """ Implements the abstract execute method from Action class. """ self.cast = cast resources = cast['resources'] tower = cast['tower'][0] if len(resources) < 5: self.make_resource() if tower.cur_health <= 0: arcade.unschedule(self.create_zombie) self.spawn_difficulty = constants.DIFFICULTY self.speed_difficulty = constants.DIFFICULTY else: self.spawn_difficulty += constants.SPAWN_DIFFICULTY_MODIFIER self.speed_difficulty += constants.SPEED_DIFFICULTY_MODIFIER
def hardMode(self): #self.MYSTERY_EFFECT_ACTIVE = False #self.removeEffect() # Change level timer self.level_timer = self.hardmode_duration self.HARDMODE_ACTIVE = True #arcade.set_background_color(arcade.color.BLACK) self.hardmode_start_time = time.time() # Increase spawn rate self.enemy_spawn_time = (0.5 / (self.level * 0.7)) if self.level <= 12 else (0.5 / (self.level * 0.2)) arcade.unschedule(self.add_enemy) arcade.schedule(self.add_enemy, self.enemy_spawn_time)
def increaseLevel(self): self.level += 1 # HARD MODE if self.level % 3 == 0: # Stop all spawning for 5 seconds, give it some suspense, change background color to black, then start hard mode dropping self.hardMode() else: self.level_timer = 45 # Increase enemy movement speed slightly if not in hardmode if self.HARDMODE_ACTIVE == False: self.level_velocity_change += 0.2 # Increase spawn rate self.enemy_spawn_time -= self.enemy_spawn_time * 0.06 self.current_spawn_time = self.enemy_spawn_time arcade.unschedule(self.add_enemy) arcade.schedule(self.add_enemy, self.enemy_spawn_time)
def on_key_release(self, key, mod): if key == ar.key.SPACE: print(self.__str__()) elif key == ar.key.A: self.astar_find_path() elif key == ar.key.T: if self.astar_trace_animate: self.astar_trace_animate = 0 ar.unschedule(self.increase_step_trace) print("Trace Off") else: self.astar_trace_animate = 1 ar.schedule(self.increase_step_trace, 1 / self.astar_trace_speed) print("Trace On") elif key == ar.key.KEY_1: self.astar_heuristic = 'manhattan' print(f"Heuristic set to {self.astar_heuristic}") elif key == ar.key.KEY_2: self.astar_heuristic = 'euclid' print(f"Heuristic set to {self.astar_heuristic}")
def execute(self, cast): tower = cast['tower'][0] zombies = cast['zombies'] resource = cast['resource_counter'][0] hero = cast['hero'][0] turrets = cast['turrets'] if tower.get_current_health() <= 0 or hero.get_current_health() <= 0: add_enemy = self.script['update'][3] arcade.unschedule(add_enemy.create_zombie) if self.script['update'][3].wave == 'Survival': win_screen = WinView(self.start, tower, cast) self.window.show_view(win_screen) tower.cur_health = constants.TOWER_HEALTH else: death_screen = DeathView(self.start, tower) self.window.show_view(death_screen) tower.cur_health = constants.TOWER_HEALTH
def countdown(self, delta_time: float): if not self.paused: self.level_timer -= 1 if self.level_timer < 0 and self.HARDMODE_ACTIVE == True: self.HARDMODE_ACTIVE = False arcade.set_background_color(arcade.color.SKY_BLUE) self.enemy_spawn_time = self.current_spawn_time arcade.unschedule(self.add_enemy) arcade.schedule(self.add_enemy, self.enemy_spawn_time) self.hardmode_start_time = 0 try: self.increaseLevel() except Exception as e: print(f"ERROR: {e}") # enemy_velocity will be set back to normal automatically -- see velocity in add_enemy(), it checks for hardmode elif self.level_timer < 0 and self.HARDMODE_ACTIVE == False: try: self.increaseLevel() except Exception as e: print(f"ERROR: {e}") else: return
def on_key_press(self, symbol, modifier): if symbol == ar.key.RIGHT: self.path_index_bfs_change = self.anim_speed elif symbol == ar.key.LEFT: self.path_index_bfs_change = -1 * self.anim_speed elif symbol == ar.key.NUM_ADD: self.astar_trace_speed += 1 print( f"Trace animation refresh rate set to 1/{self.astar_trace_speed}" ) if self.astar_trace_animate: ar.unschedule(self.increase_step_trace) ar.schedule(self.increase_step_trace, 1 / self.astar_trace_speed) elif symbol == ar.key.NUM_SUBTRACT and self.astar_trace_speed > 1: self.astar_trace_speed -= 1 print( f"Trace animation refresh rate set to 1/{self.astar_trace_speed}" ) if self.astar_trace_animate: ar.unschedule(self.increase_step_trace) ar.schedule(self.increase_step_trace, 1 / self.astar_trace_speed)
def on_key_press(self, keypressed, modifier): if keypressed == arcade.key.W or keypressed == arcade.key.UP: self.player.change_y = 5 if keypressed == arcade.key.S or keypressed == arcade.key.DOWN: self.player.change_y = -5 if keypressed == arcade.key.A or keypressed == arcade.key.LEFT: self.player.change_x = -5 if keypressed == arcade.key.D or keypressed == arcade.key.RIGHT: self.player.change_x = 5 if keypressed == arcade.key.Q: arcade.close_window() if keypressed == arcade.key.P: if self.paused == False: arcade.unschedule(self.add_enemy) arcade.unschedule(self.add_star) arcade.unschedule(self.add_planet) arcade.unschedule(self.add_pickup) else: arcade.schedule(self.add_enemy, 0.35) arcade.schedule(self.add_star, 0.1) arcade.schedule(self.add_planet, 1.5) arcade.schedule(self.add_pickup, 10) self.paused = not self.paused if keypressed == arcade.key.SPACE: self.add_laser() if self.gamestarted == False: if keypressed == arcade.key.ENTER: self.gamestarted = True self.title.remove_from_sprite_lists() self.setup() if self.gameover == True: if keypressed == arcade.key.ENTER: self.gameover = False self.gameovertext.remove_from_sprite_lists() self.setup() if keypressed == arcade.key.ESCAPE: arcade.close_window()
def removeEffect(self): if self.effect == 1: self.MYSTERY_EFFECT_ACTIVE = False self.player._set_scale(0.25) self.player._set_collision_radius(self.player._get_collision_radius() * 2) self.mystery_effect_start_time = 0 self.effect = 0 elif self.effect == 2: arcade.unschedule(self.balloonEffect) self.MYSTERY_EFFECT_ACTIVE = False for enemy in self.enemies_list: enemy._set_scale(0.15) self.mystery_effect_start_time = 0 self.effect = 0 elif self.effect == 3: arcade.unschedule(self.shootBulletsEffect) self.MYSTERY_EFFECT_ACTIVE = False self.mystery_effect_start_time = 0 self.effect = 0 elif self.effect == 4: self.follow_effect_active = False self.VERTICAL_MOVEMENT = False self.mystery_effect_start_time = 0 self.effect = 0 for sprite in self.enemies_list: sprite.remove_from_sprite_lists() self.player.left = self.width/2 - 75 self.player.center_y = 40 elif self.effect == 5: self.shrinkray20 = False for enemy in self.enemies_list: enemy._set_scale(0.15) self.mystery_effect_start_time = 0 self.effect = 0 elif self.effect == 6: self.player_shoot_active = False arcade.unschedule(self.playerShootEffect) self.mystery_effect_start_time = 0 self.effect = 0
def stop_music(self): arcade.unschedule(self.__loop_play) self._current_music.stop() self._music_playing = False self._loop_playing = False
def new_wave(self): # This super clunky function is what determines which wave is happening if self.count >= 0 and self.count <= 9: return self.wave elif self.count >= 10 and self.count <= 19: if self.first_time == 1: self.wave_timer = time.time() arcade.unschedule(self.create_zombie) self.first_time = 0 if self.can_run == True: if len(self.cast['zombies']) == 0: if time.time() - self.wave_timer >= 10: self.begin_spawn() self.can_run = False self.wave = "Wave 2" return self.wave elif self.count >= 20 and self.count <= 39: if self.first_time == 0: self.wave_timer = time.time() arcade.unschedule(self.create_zombie) self.first_time = 1 self.can_run = True if self.can_run == True: if len(self.cast['zombies']) == 0: if time.time() - self.wave_timer >= 15: self.begin_spawn() self.can_run = False self.wave = "Wave 3" return self.wave elif self.count >= 40 and self.count <= 65: if self.first_time == 1: self.wave_timer = time.time() arcade.unschedule(self.create_zombie) self.first_time = 0 self.can_run = True if self.can_run == True: if len(self.cast['zombies']) == 0: if time.time() - self.wave_timer >= 15: self.begin_spawn() self.can_run = False self.wave = "Wave 4" return self.wave elif self.count >= 65 and self.count <= 90: if self.first_time == 0: self.wave_timer = time.time() arcade.unschedule(self.create_zombie) self.first_time = 1 self.can_run = True if self.can_run == True: if len(self.cast['zombies']) == 0: if time.time() - self.wave_timer >= 15: self.begin_spawn() self.can_run = False self.wave = "Wave 5" return self.wave elif self.count >= 90: if self.first_time == 1: self.wave_timer = time.time() arcade.unschedule(self.create_zombie) self.first_time = 0 self.can_run = True if self.can_run == True: if len(self.cast['zombies']) == 0: if time.time() - self.wave_timer >= 15: self.begin_spawn() self.can_run = False self.wave = "Survival" return self.wave
def followPlayer(self, delta_time: float): arcade.unschedule(self.followPlayer) self.follow_effect_active = True