def update(delta_time): """Updates the lose menu state.""" for event in coda.event.listing(): if coda.event.quit_game(event): coda.stop() elif coda.event.mouse_l_button_down(event): if MY.Button.collides_with_point(coda.event.mouse_position()): coda.state.change(0)
def update(delta_time): """Update method for Intro state.""" for event in coda.event.listing(): if coda.event.quit_game(event): coda.stop() elif coda.event.mouse_l_button_down(event): if MY.button.collides_with_point(coda.event.mouse_position()): click_button()
def update(delta_time): """Update method for boss battle state.""" enemy_player = get_enemy_player() for event in coda.event.listing(): if coda.event.quit_game(event): coda.stop() elif coda.event.key_down(event, 'a'): MY.test += 1 CONSOLE.write(str(MY.test)) elif (coda.event.mouse_l_button_down(event) and MY.current_phase == PLAY_PHASE and MY.current_player == MY.player1): for item in MY.player1.hand: if item.object.collides_with_point( coda.event.mouse_position()): MY.current_player.play_card(enemy_player, item, CONSOLE) MY.player1.hand.remove(item) MY.current_phase += 1 break for item in MY.player1.hand: if item.object.collides_with_point(coda.event.mouse_position()): coda.actions.clear(item.object) coda.actions.add(item.object, "scale", 1.2, 0.2) else: coda.actions.clear(item.object) coda.actions.add(item.object, "scale", 1, 0.2) if MY.current_phase == DRAW_PHASE: MY.current_player.hand.append(DECK.draw_card()) MY.current_phase += 1 CONSOLE.write(MY.current_player.name + " has drawn a card") elif MY.current_phase == PLAY_PHASE and MY.current_player == MY.player2: resolve_turn() MY.current_phase += 1 elif MY.current_phase == ATTACK_PHASE: enemy_player.health.base -= MY.current_player.attack.value() MY.current_phase += 1 CONSOLE.write(MY.current_player.name + " dealt " + str(MY.current_player.attack.value()) + " to " + get_enemy_player().name) elif MY.current_phase == RESOLVE_PHASE: if MY.current_player.health.value() <= 0: CONSOLE.write(enemy_player.name + " has won the game!") MY.current_phase = GAME_OVER return elif enemy_player.health.value() <= 0: CONSOLE.write(MY.current_player.name + " has won the game!") MY.current_phase = GAME_OVER return MY.current_player.remove_expired_effects(MY.curent_turn, enemy_player) enemy_player.remove_expired_effects(MY.curent_turn, MY.current_player) MY.current_player = enemy_player MY.current_phase = DRAW_PHASE MY.curent_turn += 1 CONSOLE.write("It is now " + MY.current_player.name + "'s turn")
def update(delta_time): """update method for the quiz game. involves button logic and events.""" for event in coda.event.listing(): if coda.event.quit_game(event): coda.stop() elif coda.event.mouse_l_button_down(event): for index in range(len(MY.buttons)): if MY.buttons[index].collides_with_point( coda.event.mouse_position()): if index == MY.correct_answer_index: MY.answered_correctly = MY.answered_correctly + 1 # hard difficulty MY.grade_text.text = "Grade: " + str( int(MY.answered_correctly / MY.question_number * 100)) + "%" set_up_question() break
def update(delta_time): """Update method for Intro state.""" print(delta_time) for event in coda.event.listing(): if coda.event.quit_game(event): coda.stop() elif coda.event.mouse_l_button_down(event): if MY.button.collides_with_point(coda.event.mouse_position()): MY.selection += 1 if MY.selection > 5: MY.selection = 1 play_sound(MY.selection) if OBJ.collides_with_point(coda.event.mouse_position()): coda.actions.add(OBJ, "scale", 4, 0.2) else: coda.actions.add(OBJ, "scale", 1, 0.2) OBJ.update(delta_time)
def update(delta_time): """Update method for shooter state.""" for event in coda.event.listing(): if coda.event.quit_game(event): coda.stop() elif coda.event.key_down(event, " "): SOUND_LASER[coda.utilities.rand(0, len(SOUND_LASER) - 1)].play() fire_bullet(1) elif coda.event.key_down(event, coda.pygame.K_RETURN): SOUND_LASER[coda.utilities.rand(0, len(SOUND_LASER) - 1)].play() fire_bullet(2) #Process rotation movement for player 1 if coda.event.key_held_down("a"): MY.player1.add_rotation(SHIP_ROTATE_SPEED * delta_time) elif coda.event.key_held_down("d"): MY.player1.add_rotation(-SHIP_ROTATE_SPEED * delta_time) #Process forward and backward movement of player 1 if coda.event.key_held_down("w"): MY.player1.add_velocity(MY.player1.rotation, SHIP_ACCEL, SHIP_MAX_SPEED) elif coda.event.key_held_down("s"): MY.player1.add_velocity(MY.player1.rotation, -SHIP_ACCEL, SHIP_MAX_SPEED) #Process rotation movement for player 2 if coda.event.key_held_down(coda.pygame.K_LEFT): MY.player2.add_rotation(SHIP_ROTATE_SPEED * delta_time) elif coda.event.key_held_down(coda.pygame.K_RIGHT): MY.player2.add_rotation(-SHIP_ROTATE_SPEED * delta_time) #Process forward and backward movement of player 2 if coda.event.key_held_down(coda.pygame.K_UP): MY.player2.add_velocity(MY.player2.rotation, SHIP_ACCEL, SHIP_MAX_SPEED) elif coda.event.key_held_down(coda.pygame.K_DOWN): MY.player2.add_velocity(MY.player2.rotation, -SHIP_ACCEL, SHIP_MAX_SPEED) MY.player1.update(delta_time) MY.player2.update(delta_time) for i in range(len(MY.asteroids)): if MY.asteroids[i].active: MY.asteroids[i].update(delta_time) screen_wrap(MY.asteroids[i], MY.window) # Check if players are outside of the screen! screen_wrap(MY.player1, MY.window) screen_wrap(MY.player2, MY.window) # Update bullets for i in range(len(MY.bullets)): # ignore if not active if MY.bullets[i].active: MY.bullets[i].update(delta_time) # Destroy bullets that hit the screen edge. if screen_wrap(MY.bullets[i], MY.window): MY.bullets[i].active = False continue for j in range(len(MY.asteroids)): if MY.bullets[i].collides_with(MY.asteroids[j]): MY.bullets[i].active = False #check collisions if MY.bullet_owner[i] == 1 and MY.bullets[i].collides_with(MY.player2): MY.player2_hp = MY.player2_hp - 1 MY.bullets[i].active = False SOUND_EXPLOSIONS[coda.utilities.rand(0, len(SOUND_EXPLOSIONS) - 1)].play() elif MY.bullet_owner[i] == 2 and MY.bullets[i].collides_with(MY.player1): MY.player1_hp = MY.player1_hp - 1 MY.bullets[i].active = False SOUND_EXPLOSIONS[coda.utilities.rand(0, len(SOUND_EXPLOSIONS) - 1)].play() for asteroid in MY.asteroids: if MY.player1.collides_with(asteroid): MY.player1.velocity = coda.Vector2(0, 0) if MY.player2.collides_with(asteroid): MY.player2.velocity = coda.Vector2(0, 0) # Check win condition if MY.player1_hp < 1: coda.state.change(2) elif MY.player2_hp < 1: coda.state.change(1)
def update(delta_time): """Update method for boss battle state.""" for event in coda.event.listing(): if coda.event.quit_game(event): coda.stop() elif coda.event.key_down(event, " "): MY.player_logic.current_state = 1 x_value = 0 y_value = 0 temp = 35 MY.boss_logic.update(delta_time) MY.player_logic.update(delta_time) if MY.player_dir == coda.dir.UP: x_value = MY.player.location.x y_value = MY.player.location.y - temp elif MY.player_dir == coda.dir.DOWN: x_value = MY.player.location.x y_value = MY.player.location.y + temp elif MY.player_dir == coda.dir.LEFT: x_value = MY.player.location.x - temp y_value = MY.player.location.y elif MY.player_dir == coda.dir.RIGHT: x_value = MY.player.location.x + temp y_value = MY.player.location.y MY.player_hitbox.location = coda.Vector2(x_value, y_value) for wall in MY.walls: if MY.player.collides_with(wall): if MY.player.collision[coda.dir.DOWN]: MY.player.snap_to_object_y(wall, coda.dir.DOWN) continue if MY.player.collision[coda.dir.LEFT]: MY.player.snap_to_object_x(wall, coda.dir.LEFT) continue if MY.player.collision[coda.dir.RIGHT]: MY.player.snap_to_object_x(wall, coda.dir.RIGHT) continue if MY.player.collision[coda.dir.UP]: MY.player.snap_to_object_y(wall, coda.dir.UP) continue count = -1 for bullet in MY.bullets: count += 1 if bullet.active: if MY.bullet_owner[count] == BOSS and bullet.collides_with(MY.player): MY.player_health -= 5 bullet.active = False continue elif MY.bullet_owner[count] == PLAYER and bullet.collides_with(MY.boss): MY.boss_health -= 5 bullet.active = False continue for wall in MY.walls: if bullet.collides_with(wall): bullet.active = False continue if MY.player_hitbox.active and MY.boss.collides_with(MY.player_hitbox): MY.boss_health -= 10 MY.player_hitbox.active = False