def player_enemy_interactions(player, enemy): if not CollisionsFinder.object_collision(player, enemy): return player_halfway_point = player.x_coordinate + .5 * player.length enemy_halfway_point = enemy.x_coordinate + .5 * enemy.length last_enemy = HistoryKeeper.get_last(enemy.name) last_player = HistoryKeeper.get_last("player") if (last_enemy or last_player) is None: return is_sidescrolling_collision = CollisionsFinder.is_sidescrolling__collision( player, enemy) is_leftside_movement_collision = last_player.right_edge < last_enemy.x_coordinate landing_collision = player_halfway_point < enemy_halfway_point knockback_is_left = is_sidescrolling_collision or is_leftside_movement_collision or landing_collision
def on_platform(platform, player, is_player): is_platform_collision = CollisionsFinder.object_collision( player, platform) if player.bottom == platform.y_coordinate: return is_platform_collision # print(HistoryKeeper.get_las("player")) if not is_player or len(HistoryKeeper.get("player")) <= 1: return is_platform_collision # If this logic isn't in place last_player_y_coordinate could be below the platform's y_coordinate, which would make it do gravity # EX: (platform y coordinate is 400) player's bottom goes from 399 to 401 putting it at 400, but last player bottom would be 401 causing gravity last_player = HistoryKeeper.get_last("player") if last_player is None: return return is_platform_collision and last_player.bottom <= platform.y_coordinate
def deceleration_figure_outter(self, key): if not self.on_platform: return last_player = HistoryKeeper.get_last("player") if last_player is not None and last_player.controlls[ key] and not self.controlls[key]: self.is_decelerating = True self.x_before_decelerating = self.x_coordinate
def is_sidescrolling__collision(unmoving_object, sidescrolling_object): prev_object_iteration = HistoryKeeper.get_last( sidescrolling_object.name) if prev_object_iteration is None: return False object_sidescrolled = prev_object_iteration.x_coordinate > sidescrolling_object.x_coordinate return CollisionsFinder.object_collision( unmoving_object, sidescrolling_object) and object_sidescrolled
def platform_rightside_collision(player, platform): # So player doesn't go from in and out of platform see on_platform for me details if player.x_coordinate == platform.right_edge: return True last_player = HistoryKeeper.get_last("player") if last_player is None: return False is_side_collision = CollisionsFinder.is_side_collision( player, platform) return is_side_collision and last_player.x_coordinate >= platform.right_edge
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()
def decelerate(self): self.time_affected_by_deceleration += VelocityCalculator.time current_change = PhysicsEngine.distance_change( self.running_velocity, self.running_deceleration, self.time_affected_by_deceleration) last_player = HistoryKeeper.get_last("player") prev_change = PhysicsEngine.distance_change( self.running_velocity, self.running_deceleration, last_player.time_affected_by_deceleration) if prev_change > current_change: self.is_decelerating = False self.time_affected_by_deceleration = 0 return self.x_coordinate = (current_change + self.x_before_decelerating if self.is_facing_right else self.x_before_decelerating - current_change)
def give_score(player: Player): last_player = HistoryKeeper.get_last("player") if last_player.x_coordinate > player.x_coordinate: last_player.x_coordinate = player.x_coordinate ScoreKeeper.current_distance -= VelocityCalculator.calc_distance(player.running_velocity) is_moving_right = player.x_coordinate > last_player.x_coordinate if is_moving_right or player.game_is_sidescrolling: last_player.x_coordinate = player.x_coordinate ScoreKeeper.current_distance += VelocityCalculator.calc_distance(player.running_velocity) if ScoreKeeper.current_distance > ScoreKeeper.distance_traveled: difference = ScoreKeeper.current_distance - ScoreKeeper.distance_traveled ScoreKeeper.score += difference / 10 ScoreKeeper.distance_traveled = ScoreKeeper.current_distance HUD.show_score(ScoreKeeper.score // 1)
def platform_leftside_collision(player: GameObject, platform: GameObject): # So player doesn't go from in and out of platform see on_platform for me details if player.right_edge == platform.x_coordinate: return True last_player = HistoryKeeper.get_last("player") if last_player is None: return False if not CollisionsFinder.is_side_collision(player, platform): return False leftside_collision = (last_player.right_edge <= platform.x_coordinate or CollisionsFinder.is_sidescrolling__collision( player, platform)) return leftside_collision
def draw_everything(player: Player, enemies, platforms, game_is_paused): player.draw() player.item.render() player.shield.render() for x in range(len(enemies)): enemy = enemies[x] enemy.name = f"enemy{x}" HistoryKeeper.add(enemy, enemy.name, True) if enemy.is_within_screen and enemy.current_health > 0: enemy.player = player enemy.draw() enemy.item.render() enemy.shield.render() HUD.show_enemy_health(enemy) if HistoryKeeper.get_last( enemy.name ).current_health > 0 and enemy.current_health <= 0: UtilityFunctions.draw_font("+100", pygame.font.Font( 'freesansbold.ttf', 10), x_coordinate=enemy.x_coordinate, y_coordinate=enemy.y_coordinate) ScoreKeeper.score += 100 for x in range(len(platforms)): platform = platforms[x] if platform.is_within_screen: platform.name = f"platform{x}" HistoryKeeper.add(platform, platform.name, True) platform.draw() HistoryKeeper.add(player, "player", True) HUD.render_pause_button(game_is_paused) HUD.show_character_health(player) ScoreKeeper.give_score(player)
def get_degrees(self): last_time = HistoryKeeper.get_last("whip drawing"+self.player.name) return (last_time / self.full_animation_time) * 180
def is_continuous_event(self, event, event_name): HistoryKeeper.add(event, event_name, False) if HistoryKeeper.get_last(event_name) and event: return True return False