Dash is the best

This commit is contained in:
Rakarake 2023-03-28 22:23:44 +02:00
parent c2a16b1694
commit 7cb112a5c1
3 changed files with 34 additions and 13 deletions

View file

@ -1,14 +1,22 @@
extends Node
@onready var actor = get_parent().get_parent()
@export var intensity: float
# Set by owner
var direction: Vector2
# Input dir to velocity
@export var input_to_vel_x: Curve
# Y to the left side of 0.5 is up, and right of 0.5 is down
@export var input_to_vel_y: Curve
func enter(_args):
pass
func update(_delta):
actor.velocity = direction * intensity
var output_vel := Vector2.ZERO
output_vel.x = input_to_vel_x.sample(abs(direction.x)) * direction.x
output_vel.y = input_to_vel_y.sample(direction.y/2 + 0.5) * direction.y
print(input_to_vel_y.sample(direction.y))
actor.velocity = output_vel
actor.move_and_slide()

View file

@ -24,7 +24,8 @@ var double_jump_delay_initiated := false
@export var dash_time: float
var dash_time_tmp := dash_time
var used_double_jump := false
var double_jump_used := false
var dash_used := false
var looking_right := true
func _ready():
@ -62,7 +63,7 @@ func _physics_process(delta):
coyote_jump_tmp = coyote_jump
# Land
if current_state() in [air] && is_on_floor():
used_double_jump = false
double_jump_used = false
if buffer_jump_tmp > 0:
buffer_jump_tmp = 0
double_jump_delay_initiated = false
@ -70,6 +71,7 @@ func _physics_process(delta):
StatHub.stat_set({ "key": "player jumped buffered jump", "indicate": true })
else:
stm.transition(run)
dash_used = false
# Jump
if current_state() in [run] && Input.is_action_just_pressed("jump"):
do_jump()
@ -77,9 +79,9 @@ func _physics_process(delta):
# Double Jump
if current_state() in [air]:
if double_jump_delay_initiated:
if double_jump_delay_tmp <= 0 && !used_double_jump:
if double_jump_delay_tmp <= 0 && !double_jump_used:
double_jump_delay_initiated = false
used_double_jump = true
double_jump_used = true
do_jump()
StatHub.stat_set({ "key": "player did double jump", "indicate": true })
else:
@ -95,16 +97,17 @@ func _physics_process(delta):
# Walk left/right
if current_state() in [run, air]:
current_state().direction = get_dir().x
# Dash
if current_state() in [run, air] && Input.is_action_just_pressed("dash"):
# Do dash
if current_state() in [run, air] && Input.is_action_just_pressed("dash") && !dash_used:
dash_used = true
dash_time_tmp = dash_time
var dir := get_dir()
if dir.x == 0:
if dir == Vector2.ZERO:
if looking_right: dir.x = 1
else: dir.x = -1
stm.transition(dash)
current_state().direction = dir
# Done with dash
if current_state() in [dash]:
if dash_time_tmp <= 0:
stm.transition(air) # TODO: maybe ground?
@ -112,7 +115,6 @@ func _physics_process(delta):
dash_time_tmp -= delta
current_state().update(delta)
StatHub.stat_set({ "key": "player velocity", "value": str(velocity) })
func do_jump():

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=3 uid="uid://d3h0m3uadlf67"]
[gd_scene load_steps=25 format=3 uid="uid://d3h0m3uadlf67"]
[ext_resource type="Script" path="res://test_levels/TestEnemy/TestEnemy.gd" id="1_iu22y"]
[ext_resource type="Script" path="res://state_machine/StateMachine.gd" id="2_vs1li"]
@ -78,6 +78,16 @@ rise_curve = SubResource("Curve_6la85")
initial_velocity = 100.0
released_curve = SubResource("Curve_in7vf")
[sub_resource type="Curve" id="Curve_144jk"]
max_value = 200.0
_data = [Vector2(0, 103.636), 0.0, 0.0, 0, 0, Vector2(1, 200), 93.8756, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_sstom"]
max_value = 200.0
_data = [Vector2(0, 112.727), 0.0, 0.0, 0, 0, Vector2(0.495413, 49.0909), 0.0, 0.0, 0, 0, Vector2(1, 143.636), 0.0, 0.0, 0, 0]
point_count = 3
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fvb1y"]
size = Vector2(128.25, 128)
@ -105,7 +115,8 @@ double_jump_stats = SubResource("Resource_xpcfi")
[node name="Dash" type="Node" parent="StateMachine"]
script = ExtResource("8_afvah")
intensity = 300.0
input_to_vel_x = SubResource("Curve_144jk")
input_to_vel_y = SubResource("Curve_sstom")
[node name="Icon" type="Sprite2D" parent="."]
position = Vector2(-1, 0)