Initial commit

This commit is contained in:
luke358
2026-05-17 18:42:51 +08:00
commit b678b90883
143 changed files with 2926 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
extends Unit
class_name Player
@export var dash_duration := 0.4
@export var dash_speed_multi := 2.7
@export var dash_cooldown := 1.5
@onready var dash_timer: Timer = $DashTimer
@onready var dash_cooldown_timer: Timer = $DashCooldownTimer
@onready var collision: CollisionShape2D = $CollisionShape2D
var move_dir: Vector2
var is_dashing := false
var dash_available := true
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
dash_timer.wait_time = dash_duration
dash_cooldown_timer.wait_time = dash_cooldown
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
move_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
var current_velocity := move_dir * 500
if is_dashing:
current_velocity *= dash_speed_multi
position += current_velocity * delta
if can_dash():
start_dash()
update_animations()
update_rotation()
func update_animations() -> void:
if move_dir.length() > 0:
anim_player.play("move")
else:
anim_player.play("idle")
func update_rotation() -> void:
if move_dir == Vector2.ZERO:
return
if move_dir.x >= 0.1:
visuals.scale = Vector2(-0.5,0.5)
else:
visuals.scale = Vector2(0.5,0.5)
func start_dash() -> void:
is_dashing = true
dash_timer.start()
visuals.modulate.a = 0.5
collision.set_deferred("disabled",true)
func can_dash() -> bool:
return not is_dashing and \
dash_cooldown_timer.is_stopped() and \
Input.is_action_just_pressed("dash") and \
move_dir != Vector2.ZERO
func _on_dash_timer_timeout() -> void:
is_dashing = false
visuals.modulate.a = 1.0
move_dir = Vector2.ZERO
collision.set_deferred("disabled", false)
dash_cooldown_timer.start()
+1
View File
@@ -0,0 +1 @@
uid://b5makasbbi1ov
@@ -0,0 +1,25 @@
[gd_scene format=3 uid="uid://cgljr7wcstmyp"]
[ext_resource type="PackedScene" uid="uid://d2l68snnemcet" path="res://scenes/unit/unit.tscn" id="1_wkafa"]
[ext_resource type="Script" uid="uid://b5makasbbi1ov" path="res://scenes/unit/players/player.gd" id="2_xa7el"]
[sub_resource type="CircleShape2D" id="CircleShape2D_etcc1"]
radius = 30.0
[node name="PlayerWellRounded" unique_id=2022554550 instance=ExtResource("1_wkafa")]
script = ExtResource("2_xa7el")
dash_duration = 0.4
dash_speed_multi = 2.7
dash_cooldown = 1.5
[node name="CollisionShape2D" parent="." index="1" unique_id=139786467]
position = Vector2(0, -31)
shape = SubResource("CircleShape2D_etcc1")
[node name="DashTimer" type="Timer" parent="." index="3" unique_id=968231365]
one_shot = true
[node name="DashCooldownTimer" type="Timer" parent="." index="4" unique_id=278610339]
one_shot = true
[connection signal="timeout" from="DashTimer" to="." method="_on_dash_timer_timeout"]