Dash is the best
This commit is contained in:
parent
c2a16b1694
commit
7cb112a5c1
|
@ -1,14 +1,22 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
@onready var actor = get_parent().get_parent()
|
@onready var actor = get_parent().get_parent()
|
||||||
@export var intensity: float
|
|
||||||
|
|
||||||
# Set by owner
|
# Set by owner
|
||||||
var direction: Vector2
|
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):
|
func enter(_args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func update(_delta):
|
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()
|
actor.move_and_slide()
|
||||||
|
|
|
@ -24,7 +24,8 @@ var double_jump_delay_initiated := false
|
||||||
@export var dash_time: float
|
@export var dash_time: float
|
||||||
var dash_time_tmp := dash_time
|
var dash_time_tmp := dash_time
|
||||||
|
|
||||||
var used_double_jump := false
|
var double_jump_used := false
|
||||||
|
var dash_used := false
|
||||||
var looking_right := true
|
var looking_right := true
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
@ -62,7 +63,7 @@ func _physics_process(delta):
|
||||||
coyote_jump_tmp = coyote_jump
|
coyote_jump_tmp = coyote_jump
|
||||||
# Land
|
# Land
|
||||||
if current_state() in [air] && is_on_floor():
|
if current_state() in [air] && is_on_floor():
|
||||||
used_double_jump = false
|
double_jump_used = false
|
||||||
if buffer_jump_tmp > 0:
|
if buffer_jump_tmp > 0:
|
||||||
buffer_jump_tmp = 0
|
buffer_jump_tmp = 0
|
||||||
double_jump_delay_initiated = false
|
double_jump_delay_initiated = false
|
||||||
|
@ -70,6 +71,7 @@ func _physics_process(delta):
|
||||||
StatHub.stat_set({ "key": "player jumped buffered jump", "indicate": true })
|
StatHub.stat_set({ "key": "player jumped buffered jump", "indicate": true })
|
||||||
else:
|
else:
|
||||||
stm.transition(run)
|
stm.transition(run)
|
||||||
|
dash_used = false
|
||||||
# Jump
|
# Jump
|
||||||
if current_state() in [run] && Input.is_action_just_pressed("jump"):
|
if current_state() in [run] && Input.is_action_just_pressed("jump"):
|
||||||
do_jump()
|
do_jump()
|
||||||
|
@ -77,9 +79,9 @@ func _physics_process(delta):
|
||||||
# Double Jump
|
# Double Jump
|
||||||
if current_state() in [air]:
|
if current_state() in [air]:
|
||||||
if double_jump_delay_initiated:
|
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
|
double_jump_delay_initiated = false
|
||||||
used_double_jump = true
|
double_jump_used = true
|
||||||
do_jump()
|
do_jump()
|
||||||
StatHub.stat_set({ "key": "player did double jump", "indicate": true })
|
StatHub.stat_set({ "key": "player did double jump", "indicate": true })
|
||||||
else:
|
else:
|
||||||
|
@ -95,16 +97,17 @@ func _physics_process(delta):
|
||||||
# Walk left/right
|
# Walk left/right
|
||||||
if current_state() in [run, air]:
|
if current_state() in [run, air]:
|
||||||
current_state().direction = get_dir().x
|
current_state().direction = get_dir().x
|
||||||
# Dash
|
# Do dash
|
||||||
if current_state() in [run, air] && Input.is_action_just_pressed("dash"):
|
if current_state() in [run, air] && Input.is_action_just_pressed("dash") && !dash_used:
|
||||||
|
dash_used = true
|
||||||
dash_time_tmp = dash_time
|
dash_time_tmp = dash_time
|
||||||
var dir := get_dir()
|
var dir := get_dir()
|
||||||
if dir.x == 0:
|
if dir == Vector2.ZERO:
|
||||||
if looking_right: dir.x = 1
|
if looking_right: dir.x = 1
|
||||||
else: dir.x = -1
|
else: dir.x = -1
|
||||||
stm.transition(dash)
|
stm.transition(dash)
|
||||||
current_state().direction = dir
|
current_state().direction = dir
|
||||||
|
# Done with dash
|
||||||
if current_state() in [dash]:
|
if current_state() in [dash]:
|
||||||
if dash_time_tmp <= 0:
|
if dash_time_tmp <= 0:
|
||||||
stm.transition(air) # TODO: maybe ground?
|
stm.transition(air) # TODO: maybe ground?
|
||||||
|
@ -112,7 +115,6 @@ func _physics_process(delta):
|
||||||
dash_time_tmp -= delta
|
dash_time_tmp -= delta
|
||||||
|
|
||||||
current_state().update(delta)
|
current_state().update(delta)
|
||||||
|
|
||||||
StatHub.stat_set({ "key": "player velocity", "value": str(velocity) })
|
StatHub.stat_set({ "key": "player velocity", "value": str(velocity) })
|
||||||
|
|
||||||
func do_jump():
|
func do_jump():
|
||||||
|
|
|
@ -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://test_levels/TestEnemy/TestEnemy.gd" id="1_iu22y"]
|
||||||
[ext_resource type="Script" path="res://state_machine/StateMachine.gd" id="2_vs1li"]
|
[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
|
initial_velocity = 100.0
|
||||||
released_curve = SubResource("Curve_in7vf")
|
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"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fvb1y"]
|
||||||
size = Vector2(128.25, 128)
|
size = Vector2(128.25, 128)
|
||||||
|
|
||||||
|
@ -105,7 +115,8 @@ double_jump_stats = SubResource("Resource_xpcfi")
|
||||||
|
|
||||||
[node name="Dash" type="Node" parent="StateMachine"]
|
[node name="Dash" type="Node" parent="StateMachine"]
|
||||||
script = ExtResource("8_afvah")
|
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="."]
|
[node name="Icon" type="Sprite2D" parent="."]
|
||||||
position = Vector2(-1, 0)
|
position = Vector2(-1, 0)
|
||||||
|
|
Loading…
Reference in a new issue