def transfer_item() -> None: """The animation of giving the item to a player.""" item = c.TRANSFER_ITEM player = u.player_in_front() if item: #always update animation item.disappear_animation() #item rise and disappear if item.is_visible() and item.is_on_platform() and item.is_left_of_p1( ): item.dest_y = item.y + item.disappear_limit item.toggle_disappear() #item over player, item not visible at this point if not item.is_visible() and item.is_at_disappear_limit(): item.opacity = item.min_opacity item.move_over_player() #item over player, much closer to it, item becomes visible at this point if item.is_over_p1() and item.is_at_disappear_limit(): item.dest_y = player.y # over shoot the dest_y to allow the floating players to grab the items item.y, item.dest_y = player.y + item.disappear_limit, player.y - c.SCREEN_H item.toggle_disappear() #item is at the same spot as the player, x and y axes if item.is_at_or_below_p1(): player.item = item c.TRANSFER_ITEM = None #remove reference as c.TRANSFER_ITEM
def draw_problem(problem: Any) -> None: """Draw the problem.""" player = u.player_in_front() #TODO, uncomment this line for future complexity additions if not u.movement(player): # if not u.any_movement() and c.QUESTIONS: problem.box.draw() c.PROBLEM_BATCH.draw()
def on_key_release(symbol, modifiers): # options screen if u.is_options_screen(): if symbol == key.UP: options.selector_up() elif symbol == key.DOWN: options.selector_down() elif symbol == key.B: c.SCREEN = Screens.TITLE elif symbol == key.LEFT: options.selector_left() elif symbol == key.RIGHT: options.selector_right() elif symbol == key.SPACE: options.toggle_item() # title screen elif u.is_title_screen(): if symbol == key.UP: title.selector_up() elif symbol == key.DOWN: title.selector_down() #make a selection elif symbol == key.ENTER: if title.is_game_selected(): c.SCREEN = Screens.GAME elif title.is_options_selected(): c.SCREEN = Screens.OPTIONS # game screen elif u.is_game_screen(): """ Digits: 1 Letters: ABDFOSUX Arrows: Left Right Up """ player = u.player_in_front() if symbol == key.B: c.SCREEN = Screens.TITLE elif not u.any_movement(): if symbol == key._1: if not problem.showing: #TODO, # determine what item the player will get, # pass it to the problem instance # the problem class should update itself based on the item passed to it. problem.question.draw() problem.toggle() player.use_item() yammy.wave_wand() c.TRANSFER_ITEM = u.remove_item_from_platform() i.add_item() elif symbol == key.LEFT: u.rotate_players_left() elif symbol == key.RIGHT: u.rotate_players_right() elif symbol == key.UP: c.PLAYERS = u.mix(c.PLAYERS) #plus one point elif symbol == key.O: u.right_answer(player) u.rotate_players_left() if problem.showing: problem.toggle() problem.decided = False # clear the flag #delete prior problem letter sprites #minus one point elif symbol == key.X: u.wrong_answer(player) if player.item: player.item.poof() player.item = None u.rotate_players_left() if problem.showing: problem.toggle() problem.decided = False # clear the flag #delete prior problem letter sprites elif symbol == key.A: u.rotate_items_left() elif symbol == key.D: u.rotate_items_right() elif symbol == key.S: c.ALL_ITEMS = u.mix(c.ALL_ITEMS) elif symbol == key.U: player.use_item()
def move_over_player(self) -> None: """Move item to trailing position behind player.""" player = u.player_in_front() new_spot = player._trail_right_pos() self.x, self.dest_x = new_spot, new_spot
def is_over_p1(self) -> bool: """Is the item directly overhead player 1?""" return self.y >= u.player_in_front().y
def is_at_or_below_p1(self) -> bool: """Is item at or below player 1 on y-axis?""" return self.y <= u.player_in_front().y
def is_left_of_p1(self) -> bool: """Is the item to the left of player in front?""" return self.x < u.player_in_front().x