Пример #1
0
 def test_generate_platform_x_coordinate(self):
     last_platform = Platform()
     last_platform.x_coordinate = 100
     new_platform = Platform()
     new_platform.length = 100
     for x in range(250):
         last_platform.length = random.randint(50, 340)
         time_spent_in_air = 1
         new_platform_x_coordinate = generate_platform_x_coordinate(time_spent_in_air, Player.running_velocity, last_platform, new_platform)
         max_distance = time_spent_in_air * Player.running_velocity
         got_distance = new_platform_x_coordinate - (last_platform.x_coordinate + last_platform.length)
         jump_makeable =  max_distance >= got_distance
         self.assertTrue(jump_makeable, f"The jump should be makeable for the player max: {max_distance} vs got: {got_distance}")
         
         players_location = screen_length * .2
         last_platform_midpoint = last_platform.length * .5
         max_space_apart = screen_length - players_location - new_platform.length - last_platform_midpoint
         gotten_space_apart = new_platform_x_coordinate - (last_platform.x_coordinate + last_platform.length)
         platform_on_screen = gotten_space_apart <= max_space_apart
         self.assertTrue(platform_on_screen, f"The next platform should be on the screen when the player reaches the halfway point of the first platform want: {max_space_apart} vs gotten: {gotten_space_apart}")
Пример #2
0
    def generate_platform(platforms: Platform, player: Player, gravity):
        # IMPORTANT: order has to be height, lengths, y_coordinate, x_coordinate, randomize_platform_terrain()
        # Length and height dictate y_coordinate, y_coordinate dictates x_coordinate, and randomize_platform_terrain()
        # Changes the length so it can't be changed back by the generate_platform_length()
        # TODO change back
        # new_platform = Platform()
        last_platform = platforms[len(platforms) - 1]
        # new_platform.height = generate_platform_height()
        # new_platform.length = generate_platform_length()
        # new_platform.y_coordinate = generate_platform_y_coordinate(player, last_platform, new_platform)

        # new_platform.platform_color = (0, 250, 0)
        # players_time_in_air = player.time_in_air(new_platform.y_coordinate, last_platform.y_coordinate, gravity)
        # new_platform.x_coordinate = generate_platform_x_coordinate(players_time_in_air, player.running_velocity, last_platform, new_platform)
        # randomize_platform_terrain(new_platform)

        # platforms.append(new_platform)
        new_platform = Platform()
        new_platform.x_coordinate = last_platform.right_edge
        platforms.append(new_platform)
        return platforms
Пример #3
0
    def reset_variables():
        enemy = SimpleEnemy(GameRunner.doggo)
        # TODO change back
        # enemy.is_within_screen = False
        GameRunner.enemies = []
        platform = Platform()
        # TODO change back, but just wanna test movements
        platform.x_coordinate = 0
        platform.length = screen_length

        enemy.platform_on = platform
        GameRunner.platforms = [platform]
        GameRunner.doggo = Player()
        GameRunner.doggo.y_coordinate = platform.y_coordinate + 70 + GameRunner.doggo.height
        Player.attributes = GameObject.find_all_attributes(Player())
        print(Player.attributes)
        SimpleEnemy.attributes = GameObject.find_all_attributes(SimpleEnemy())
        Platform.attributes = GameObject.find_all_attributes(Platform())
        GameRunner.doggo.y_coordinate = GameRunner.platforms[
            0].y_coordinate - GameRunner.doggo.height - 100
        WallOfDeath.reset()
        ScoreKeeper.reset()
        HistoryKeeper.reset()