]> Untitled Git - frog-ninja.git/commitdiff
Added player dash
authorClifton Palmer <clifton.james.palmer@protonmail.com>
Sun, 4 May 2025 08:47:25 +0000 (11:47 +0300)
committerClifton Palmer <clifton.james.palmer@protonmail.com>
Sun, 4 May 2025 08:47:25 +0000 (11:47 +0300)
player/player.gd
texture/grid.png

index d00302d27df62c58c8efece5016250bc22a871ac..d08f491a1fbbe25220a7980c9fd3a899bfce495b 100644 (file)
@@ -1,10 +1,13 @@
 extends CharacterBody3D
 class_name Player
 
+##########
+# settings
+##########
 
-# player settings
 @export_group("Movement")
-@export var walk_speed := 10.0
+@export var walk_speed := 8.0
+@export var dash_length := 10.0
 
 @export var air_speed := 3.0
 @export var acceleration := 50.0
@@ -23,6 +26,9 @@ class_name Player
 @export_range(0.0, 10.0) var joystick_sensitivity_x := 4.0
 @export_range(0.0, 10.0) var joystick_sensitivity_y := 2.0
 
+######
+# init
+######
 
 @onready var _camera_pivot: Node3D = %camera_pivot
 @onready var _camera: Camera3D = %camera
@@ -43,12 +49,12 @@ var _player_speed: float = walk_speed
 
 func _ready() -> void:
        _camera_spring.spring_length = camera_distance
+       
+       
 
-
-func _physics_process(delta: float) -> void:
-       _process_camera(delta)
-       _process_player(delta)
-
+#######
+# input
+#######
 
 func _unhandled_input(event: InputEvent) -> void:
        # If user clicks on the window, capture the mouse and direct the camera with it
@@ -60,6 +66,7 @@ func _unhandled_input(event: InputEvent) -> void:
                _camera_input_method = CAMERA_MOUSE_INPUT
                _camera_input_direction = event.screen_relative * mouse_sensitivity
        elif event is InputEventJoypadMotion:
+               # TODO: add these settings!
                _camera_input_method = CAMERA_JOYSTICK_INPUT
                _camera_input_direction = Input.get_vector("camera-left", "camera-right", "camera-up", "camera-down")
                _camera_input_direction *= Vector2(joystick_sensitivity_x, -joystick_sensitivity_y)
@@ -68,12 +75,22 @@ func _unhandled_input(event: InputEvent) -> void:
 func _input(event: InputEvent):
        if event.is_action_pressed("player-dash"):
                _skin.transition_dash()
+               _player_dash()
        elif event.is_action_pressed("player-slash"):
                _skin.sword_visible()
                _skin.transition_slash()
        elif event.is_action_pressed("player-shoot"):
                _skin.gun_visible()
                _skin.transition_gunfire()
+               
+
+##########
+# movement
+##########
+
+func _physics_process(delta: float) -> void:
+       _process_camera(delta)
+       _process_player(delta)
 
 
 # Get the XZ input direction based on player's input relative to the camera
@@ -156,3 +173,14 @@ func _process_player(delta: float) -> void:
                velocity += get_gravity() * air_speed * delta
 
        move_and_slide()
+
+#########
+# actions
+#########
+
+func _player_dash():
+       var move_direction := _get_player_move_direction()
+       if move_direction != Vector3.ZERO:
+               var dash_local_pos = move_direction * dash_length
+               # TODO: check if valid position, crop the vector to last valid position
+               global_position += dash_local_pos
index f7cc6f2c70323af211ae983b9e4e3663d43b7336..7cc12f777b28b4b5d909d78f37754720fcab6b85 100644 (file)
Binary files a/texture/grid.png and b/texture/grid.png differ