class_name PlatformerPlayerGroundMove extends PlatformerPlayerMove ## Move that controls a player actor while grounded # ----------------------------------------------------------------------------------------------- # # ----------------------------------------------------------------------------------------------- # ## Called when the actor controller has started performing the move ## @param delta_seconds Elapsed time since the previous frame func _move_started() -> void: enable_gravity(true) # ----------------------------------------------------------------------------------------------- # ## Called once per physics frame to update the state of the simulation ## @param delta_seconds Time that has elapsed since the last physics frame func _physics_process(delta_seconds : float) -> void: # If the actor is grounded, reset the jump count if self.is_grounded: platformer_actor_controller.consecutive_jump_count = 0 else: # If the actor just fell, ground controls no longer apply var jumped : bool = false switch_to_air_move(jumped) return print("Mooh") # Standard left/right movement of the actor _handle_horizontal_movement(delta_seconds) # Begin dashing if the player hits the dash key and it's enabled if Input.is_action_just_pressed("dash"): if actor_abilities.can_dash: switch_to_dash_move() return # If the player pressed the jump key, we'll be airborne with upward velocity # Jump count can be 0 if the game is a "doom guy" simulator. if Input.is_action_just_pressed("jump"): print("Jump pressed") if actor_controller.consecutive_jump_count < actor_abilities.jump_count: var jumped : bool = true switch_to_air_move(jumped) return # Pressing down while standing still will switch to a squatting stance if Input.is_action_just_pressed("down"): var horizontal_velocity : float = get_horizontal_velocity() if horizontal_velocity >= actor_abilities.speed_for_floor_slide: switch_to_slide_move() return elif (horizontal_velocity < actor_abilities.walking_speed) and (actor_abilities.can_squat): switch_to_squat_move() return # ----------------------------------------------------------------------------------------------- # ## Movement logic to move the actor to the left and right ## @param delta_seconds Amount of time that has passed since the last physics frame func _handle_horizontal_movement(delta_seconds : float) -> void: var horizontal_input = ( Input.get_action_strength("move_right") - Input.get_action_strength("move_left") ) #print("Horizontal input: %d " % horizontal_input) # Determine the speed at which the player wants to move and the highest # possible speed the actor could achieve (used to calculate acceleration) var fastest_speed = _get_movement_speed() var target_speed = fastest_speed * horizontal_input # The maximum possible acceleration is specified by the actor's abilities, # as time the actor would need to reach top speed var acceleration = fastest_speed / actor_abilities.seconds_to_full_speed accelerate_to_velocity(target_speed, acceleration, delta_seconds) # Turn the actor towards the direction the player is directing var horizontal_direction : float = get_horizontal_velocity() if horizontal_direction < actor_abilities.walking_speed * -0.1: actor_controller.facing_direction = -1.0 elif horizontal_direction > actor_abilities.walking_speed * 0.1: actor_controller.facing_direction = +1.0 # ----------------------------------------------------------------------------------------------- # ## Returns the speed at which the actor should move ## @returns The speed at which the actor should move func _get_movement_speed() -> float: if self.actor_abilities.can_sprint and Input.is_action_held("sprint"): return self.actor_abilities.running_speed else: return self.actor_abilities.walking_speed