Ejemplo n.º 1
0
def _move_sprite(moving_sprite: arcade.Sprite, walls: arcade.SpriteList):
    # Rotate
    moving_sprite.angle += moving_sprite.change_angle

    hit_list = check_for_collision_with_list(moving_sprite, walls)

    if len(hit_list) > 0:
        # Resolve any collisions by this weird kludge
        _circular_check(moving_sprite, walls)

    # --- Move in the y direction
    moving_sprite.center_y += moving_sprite.change_y

    # Check for wall hit
    hit_list_x = check_for_collision_with_list(moving_sprite, walls)
    # print(f"Post-y move {hit_list_x}")

    # If we hit a wall, move so the edges are at the same point
    if len(hit_list_x) > 0:
        if moving_sprite.change_y > 0:
            while check_for_collision_with_list(moving_sprite, walls):
                moving_sprite.center_y -= 1
        elif moving_sprite.change_y < 0:
            while check_for_collision_with_list(moving_sprite, walls):
                moving_sprite.center_y += 1
        was_falling = (abs(moving_sprite.change_y) > abs(
            moving_sprite.engine.gravity_constant))
        if was_falling:
            # they have been moving for more than one frame
            play_sound_effect('impact')
        moving_sprite.change_y = min(0.0, hit_list_x[0].change_y)

    moving_sprite.center_y = round(moving_sprite.center_y, 2)

    # --- Move in the x direction
    moving_sprite.center_x += moving_sprite.change_x

    check_again = True
    while check_again:
        check_again = False
        # Check for wall hit
        hit_list_y = check_for_collision_with_list(moving_sprite, walls)

        # If we hit a wall, move so the edges are at the same point
        if len(hit_list_y) > 0:
            change_x = moving_sprite.change_x
            if change_x > 0:
                while check_for_collision_with_list(moving_sprite, walls):
                    moving_sprite.center_x -= 1

            elif change_x < 0:
                while check_for_collision_with_list(moving_sprite, walls):
                    moving_sprite.center_x += 1

            else:
                raise AssertionError(
                    "Error, x collision while player wasn't moving.\n"
                    "Make sure you aren't calling multiple updates, like "
                    "a physics engine update and an all sprites list update.")
Ejemplo n.º 2
0
 def game_over(self, message: str, player: player_module.Player):
     """Kill the player and show some explanatory message."""
     play_sound_effect('death')
     player.score = 0
     for box in player.boxes:
         box.remove_gem()
     player.revive_after = 240
     player.death_message = message
     for other in self.players:
         if other != player:
             other.blocks.remove(player)
Ejemplo n.º 3
0
 def on_click(self, _x: float, _y: float):
     """Play sound effect and set state."""
     play_sound_effect('mouseclick')
     self.state = 'pressed'
Ejemplo n.º 4
0
 def on_release(self, _x: float, _y: float):
     """Play sound effect, update state and run callback."""
     play_sound_effect('mouserelease')
     self.fun()
     self.state = 'normal'
Ejemplo n.º 5
0
 def game_over(self, message: str, _player: player.Player = None):
     """Display the game over view with some explanatory message."""
     play_sound_effect('death')
     self.save()
     self.window.show_view(
         views.GameOver(message, [self.player.score], Game))