Esempio n. 1
0
    def movement(self):
        if not self.can_move:
            return

        if self.is_flinching:
            self.flinch()
            self.color = (250, 0, 0)
            self.item.stop_item_usage()
            self.shield.stop_item_usage()
            return

        else:
            self.color = self.black

        self.figure_out_blocking()

        self.use_item_if_can()

        self.change_direction_if_necessary()

        if CollisionsFinder.object_collision(self, self.player):
            return

        elif CollisionsFinder.object_collision(self, self.player):
            self.x_coordinate = self.player.x_coordinate - self.length

        if not self.is_moving_left:
            self.x_coordinate += VelocityCalculator.calc_distance(
                self.velocity)

        if self.is_moving_left:
            self.x_coordinate -= VelocityCalculator.calc_distance(
                self.velocity)
Esempio n. 2
0
    def render_players_and_platforms(platforms, player):
        is_rightside_collision = False
        is_leftside_collision = False
        player_is_on_platform = False
        platform_player_on = None
        platform_collided_into = None

        for x in range(len(platforms)):
            platform = platforms[x]
            if not platform.is_within_screen:
                continue
            if CollisionsFinder.platform_rightside_collision(player, platform):
                is_rightside_collision = True
                platform_collided_into = platform

            if CollisionsFinder.platform_leftside_collision(player, platform):
                is_leftside_collision = True
                platform_collided_into = platform

            if CollisionsFinder.on_platform(platform, player, True):
                player_is_on_platform = True
                platform_player_on = platform

        GameRenderer.platform_side_collisions(player, platform_collided_into,
                                              is_rightside_collision,
                                              is_leftside_collision)
        # Keep this after platform_side_collisions because
        GameRenderer.platform_top_mechanics(player, platform_player_on,
                                            player_is_on_platform)
        player.movement()
Esempio n. 3
0
 def _render_enemy(enemy: SimpleEnemy):
     platform = enemy.platform_on
     if not CollisionsFinder.on_platform(platform, enemy, False):
         PhysicsEngine.do_gravity(enemy)
     else:
         enemy.is_on_platform = CollisionsFinder.on_platform(
             platform, enemy, False)
         enemy.platform_on = platform
         enemy.movement()
Esempio n. 4
0
    def test_platform_collision(self):
        platform = Platform()
        self.assertEquals(True, CollisionsFinder.platform_collision(self.get_test_players(
            1), platform), "Should be a True because both x and y are inside/ right on platform")

        self.assertEquals(False, CollisionsFinder.platform_collision(self.get_test_players(
            2), platform), "Should be False becuase x coordinate is outside platform")

        self.assertEquals(False, CollisionsFinder.platform_collision(self.get_test_players(
            3), platform), "Should be False becuase y coordinate is outside platform")
Esempio n. 5
0
    def test_on_platform(self):
        platform = Platform()
        player = Player()
        player.y_coordinate = 400 - player.height
        player.x_coordinate = platform.x_coordinate

        self.assertEquals(True, CollisionsFinder.on_platform(
            platform, player, 399), "Want true since player on platform")

        player.x_coordinate = platform.x_coordinate - 1
        player.y_coordinate = 400 - player.height - 1
        self.assertEquals(False, CollisionsFinder.on_platform(platform, player, False),
                          f"Want false since player at ({player.x_coordinate},{player.y_coordinate}) and platform at ({platform.x_coordinate}, {platform.y_coordinate})")
Esempio n. 6
0
    def test_platform_boundaries(self):
        platform = Platform()
        player = self.get_test_players(1)
        last_player_x_coordinate = platform.x_coordinate - 3
        self.assertEquals(False, CollisionsFinder.platform_right_boundary(player, platform, last_player_x_coordinate), f"Should be False since last_player_x_coordinate" +
                          f" {last_player_x_coordinate} is less than platform right edge {platform.length + platform.x_coordinate}")

        self.assertEquals(True, CollisionsFinder.platform_left_boundary(player, platform, last_player_x_coordinate - player.height), f"Should be True since last_player_x_coordinate" +
                          f" {last_player_x_coordinate - player.height} is less than platform start {platform.x_coordinate + player.height}")

        last_player_x_coordinate = platform.x_coordinate + platform.length + 3
        self.assertEquals(True, CollisionsFinder.platform_right_boundary(player, platform, last_player_x_coordinate), f"Should be True since last_player_x_coordinate" +
                          f" {last_player_x_coordinate} is greater than platforms right edge {platform.length + platform.x_coordinate}")

        self.assertEquals(False, CollisionsFinder.platform_left_boundary(player, platform, last_player_x_coordinate - player.height), f"Should be False since last_player_x_coordinate" +
                          f" {last_player_x_coordinate - player.height} is greater than platforms start {platform.x_coordinate}")
Esempio n. 7
0
    def change_direction_based_on_player(self):
        player_on_enemy_platform = CollisionsFinder.on_platform(
            self.platform_on, self.player, True)
        # There should be a decent gap between the enemy and the player, so the enemy isn't inside the player
        min_gap = self.length * .13
        if not player_on_enemy_platform:
            return

        if self.right_edge + min_gap < self.player.right_edge:
            self.is_moving_left = False
            self.is_facing_right = True
        if self.x_coordinate - min_gap > self.player.right_edge:
            self.is_moving_left = True
            self.is_facing_right = False
Esempio n. 8
0
 def player_is_within_range(self):
     length = self.length
     x_coordinate = self.x_coordinate
     # Setting it to max to see if it was the max_length would it hit the player
     self.length = self.item.max_length + length
     if not self.is_facing_right:
         self.x_coordinate -= self.item.max_length
     if CollisionsFinder.object_length_collision(self, self.player):
         self.length = length
         self.x_coordinate = x_coordinate
         return True
     else:
         self.length = length
         self.x_coordinate = x_coordinate
         return False