Skip to content

Commit

Permalink
add basic dash
Browse files Browse the repository at this point in the history
should be remade or seen with particles on dash spot
  • Loading branch information
qvintopus committed Sep 11, 2024
1 parent dbbac07 commit 976a231
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ weapon_down={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
]
}
dash={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}

[layer_names]

Expand Down
4 changes: 3 additions & 1 deletion scenes/actors/actor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ libraries = {
"": SubResource("AnimationLibrary_tbujk")
}

[node name="MoverTopDown2D" type="Node2D" parent="." node_paths=PackedStringArray("character_body")]
[node name="MoverTopDown2D" type="Node2D" parent="." node_paths=PackedStringArray("character_body", "time_dash")]
script = ExtResource("5_3rf64")
character_body = NodePath("..")
actor_stats_resource = SubResource("Resource_qmsly")
input_resource = SubResource("Resource_oyd13")
axis_multiplier = Vector2(1, 0.5)
time_dash = NodePath("../TimerDash")

[node name="SpriteFlip" type="Node" parent="." node_paths=PackedStringArray("mover_2d", "flip_node")]
script = ExtResource("8_7uvby")
Expand All @@ -151,3 +152,4 @@ flash_animation = &"flash"
sound_resource_damage = ExtResource("11_wwbua")
sprite_flip = NodePath("../SpriteFlip")
dead_vfx_parent_path = NodePath("../..")
[node name="TimerDash" type="Timer" parent="."]
23 changes: 23 additions & 0 deletions scripts/actor/MoverTopDown2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ extends Node2D
@export var input_resource:InputResource
## Used for faking angled perspective movement
@export var axis_multiplier:Vector2 = Vector2(1.0, 1.0)
## Dash timer
@export var time_dash:Timer
## Speed of The Dash
@export var dash_speed:int = 88
## Dash cooldown before new dash
@export var dash_cooldown:float = 0.8

## Projected maximal velocity
var target_velocity:Vector2
## Ammount of velocity acceleration
var acceleration:float
## Dashing status
var is_dashing:bool = false


## Way to disable functionality during the gameplay
Expand All @@ -25,6 +33,9 @@ func set_enabled(value:bool)->void:

func _ready()->void:
set_enabled(enabled)
if time_dash:
time_dash.wait_time = 1.0
time_dash.timeout.connect(reset_dash)

func _physics_process(delta:float)->void:
target_velocity = actor_stats_resource.max_speed * input_resource.axis * axis_multiplier
Expand All @@ -39,3 +50,15 @@ func _physics_process(delta:float)->void:
## Adds an impulse to velocity, like a kickback
func add_impulse(impulse:Vector2)->void:
character_body.velocity += impulse

## Adds a dash impulse to velocity, like a controlled kickback
func add_dash(direction:Vector2)->void:
if !time_dash || is_dashing:
return
if !is_dashing:
character_body.velocity += direction * dash_speed
is_dashing = true
time_dash.start()

func reset_dash()->void:
is_dashing = false
4 changes: 4 additions & 0 deletions scripts/actor/PlayerInput.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ func _physics_process(_delta:float)->void:
var weapon_switch_dir:int = int(Input.is_action_just_released("weapon_up")) - int(Input.is_action_just_released("weapon_down"))
if weapon_switch_dir != 0:
mover.input_resource.set_switch_weapon(weapon_switch_dir)

# Dashing
if (Input.is_action_pressed("dash")):
mover.add_dash(axis)

0 comments on commit 976a231

Please sign in to comment.