feat: 添加敌人并且追踪player,同时避免敌人重叠
This commit is contained in:
@@ -8,6 +8,7 @@ class_name Player
|
||||
@onready var dash_timer: Timer = $DashTimer
|
||||
@onready var dash_cooldown_timer: Timer = $DashCooldownTimer
|
||||
@onready var collision: CollisionShape2D = $CollisionShape2D
|
||||
@onready var trail: Trail = %Trail
|
||||
|
||||
var move_dir: Vector2
|
||||
var is_dashing := false
|
||||
@@ -24,12 +25,15 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
move_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
|
||||
var current_velocity := move_dir * 500
|
||||
var current_velocity := move_dir * stats.speed
|
||||
if is_dashing:
|
||||
current_velocity *= dash_speed_multi
|
||||
|
||||
position += current_velocity * delta
|
||||
|
||||
position.x = clamp(position.x, -1000, 1000)
|
||||
position.y = clamp(position.y, -500, 500)
|
||||
|
||||
if can_dash():
|
||||
start_dash()
|
||||
|
||||
@@ -54,6 +58,7 @@ func update_rotation() -> void:
|
||||
func start_dash() -> void:
|
||||
is_dashing = true
|
||||
dash_timer.start()
|
||||
trail.start_trail()
|
||||
visuals.modulate.a = 0.5
|
||||
collision.set_deferred("disabled",true)
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[gd_scene format=3 uid="uid://deqpkmjaerop3"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cgljr7wcstmyp" path="res://scenes/unit/players/player_well_rounded.tscn" id="1_t1ilm"]
|
||||
[ext_resource type="Resource" uid="uid://dhbwq0p1appau" path="res://resources/units/players/stats_player_brawler.tres" id="2_k813p"]
|
||||
[ext_resource type="Texture2D" uid="uid://dpxw8tsbgrfse" path="res://assets/sprites/Players/Player_2.png" id="2_tvi6w"]
|
||||
|
||||
[node name="PlayerBrawler" unique_id=2022554550 instance=ExtResource("1_t1ilm")]
|
||||
stats = ExtResource("2_k813p")
|
||||
|
||||
[node name="Sprite" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="2" unique_id=1925870318]
|
||||
texture = ExtResource("2_tvi6w")
|
||||
@@ -0,0 +1,11 @@
|
||||
[gd_scene format=3 uid="uid://3ous2yjlqlki"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cgljr7wcstmyp" path="res://scenes/unit/players/player_well_rounded.tscn" id="1_tex7i"]
|
||||
[ext_resource type="Resource" uid="uid://ceyne237du1" path="res://resources/units/players/stats_player_bunny.tres" id="2_da4ie"]
|
||||
[ext_resource type="Texture2D" uid="uid://dmox6e28kf6ax" path="res://assets/sprites/Players/Player_4.png" id="2_lbt10"]
|
||||
|
||||
[node name="PlayerBunny" unique_id=2022554550 instance=ExtResource("1_tex7i")]
|
||||
stats = ExtResource("2_da4ie")
|
||||
|
||||
[node name="Sprite" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="2" unique_id=1925870318]
|
||||
texture = ExtResource("2_lbt10")
|
||||
@@ -0,0 +1,11 @@
|
||||
[gd_scene format=3 uid="uid://qaqitaf84hdm"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cgljr7wcstmyp" path="res://scenes/unit/players/player_well_rounded.tscn" id="1_5054k"]
|
||||
[ext_resource type="Resource" uid="uid://cuj1u77pg06ah" path="res://resources/units/players/stats_player_crazy.tres" id="2_e1phh"]
|
||||
[ext_resource type="Texture2D" uid="uid://dq63ocnu3lset" path="res://assets/sprites/Players/Player_3}.png" id="2_ii53f"]
|
||||
|
||||
[node name="PlayerCrazy" unique_id=2022554550 instance=ExtResource("1_5054k")]
|
||||
stats = ExtResource("2_e1phh")
|
||||
|
||||
[node name="Sprite" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="2" unique_id=1925870318]
|
||||
texture = ExtResource("2_ii53f")
|
||||
@@ -0,0 +1,11 @@
|
||||
[gd_scene format=3 uid="uid://d0q8iu2ceyjde"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cgljr7wcstmyp" path="res://scenes/unit/players/player_well_rounded.tscn" id="1_tsqjv"]
|
||||
[ext_resource type="Resource" uid="uid://crhkwist448wy" path="res://resources/units/players/stats_player_knight.tres" id="2_rn052"]
|
||||
[ext_resource type="Texture2D" uid="uid://bt0lww88864ws" path="res://assets/sprites/Players/Player_5.png" id="2_t2hln"]
|
||||
|
||||
[node name="PlayerKnight" unique_id=2022554550 instance=ExtResource("1_tsqjv")]
|
||||
stats = ExtResource("2_rn052")
|
||||
|
||||
[node name="Sprite" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="2" unique_id=1925870318]
|
||||
texture = ExtResource("2_t2hln")
|
||||
@@ -1,18 +1,44 @@
|
||||
[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="Texture2D" uid="uid://cproxhccob85g" path="res://assets/sprites/Players/Player_1.png" id="2_etcc1"]
|
||||
[ext_resource type="Script" uid="uid://b5makasbbi1ov" path="res://scenes/unit/players/player.gd" id="2_xa7el"]
|
||||
[ext_resource type="Resource" uid="uid://btnfef0ui2ju8" path="res://resources/units/players/stats_player_well_rounded.tres" id="3_xa7el"]
|
||||
[ext_resource type="Script" uid="uid://bkfe6nn8yxhbq" path="res://scenes/unit/players/trail.gd" id="4_0kki1"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_ht2l1"]
|
||||
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_etcc1"]
|
||||
radius = 30.0
|
||||
|
||||
[node name="PlayerWellRounded" unique_id=2022554550 instance=ExtResource("1_wkafa")]
|
||||
collision_mask = 2
|
||||
script = ExtResource("2_xa7el")
|
||||
dash_duration = 0.4
|
||||
dash_speed_multi = 2.7
|
||||
dash_cooldown = 1.5
|
||||
stats = ExtResource("3_xa7el")
|
||||
|
||||
[node name="Trail" type="Line2D" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="0" unique_id=1482185349 node_paths=PackedStringArray("player")]
|
||||
unique_name_in_owner = true
|
||||
top_level = true
|
||||
position = Vector2(0, -31)
|
||||
width = 40.0
|
||||
width_curve = SubResource("Curve_ht2l1")
|
||||
script = ExtResource("4_0kki1")
|
||||
player = NodePath("../..")
|
||||
|
||||
[node name="Shadow" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="1" unique_id=2136480859]
|
||||
z_index = 1
|
||||
|
||||
[node name="Sprite" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="2" unique_id=1925870318]
|
||||
z_index = 1
|
||||
texture = ExtResource("2_etcc1")
|
||||
|
||||
[node name="CollisionShape2D" parent="." index="1" unique_id=139786467]
|
||||
visible = false
|
||||
position = Vector2(0, -31)
|
||||
shape = SubResource("CircleShape2D_etcc1")
|
||||
|
||||
@@ -22,4 +48,8 @@ one_shot = true
|
||||
[node name="DashCooldownTimer" type="Timer" parent="." index="4" unique_id=278610339]
|
||||
one_shot = true
|
||||
|
||||
[node name="TrailTimer" type="Timer" parent="." index="5" unique_id=2006934730]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[connection signal="timeout" from="DashTimer" to="." method="_on_dash_timer_timeout"]
|
||||
[connection signal="timeout" from="TrailTimer" to="Visuals/Trail" method="_on_trail_timer_timeout"]
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
extends Line2D
|
||||
class_name Trail
|
||||
|
||||
@export var player: Player
|
||||
@export var trail_length := 25
|
||||
@export var trail_duration := 1.0
|
||||
|
||||
@onready var trail_timer: Timer = %TrailTimer
|
||||
|
||||
var pointers_array: Array[Vector2] = []
|
||||
var is_active := false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if not is_active:
|
||||
return
|
||||
|
||||
pointers_array.append(player.global_position)
|
||||
if pointers_array.size() > trail_length:
|
||||
pointers_array.pop_front()
|
||||
|
||||
points = pointers_array
|
||||
|
||||
func start_trail() -> void:
|
||||
is_active = true
|
||||
clear_points()
|
||||
pointers_array.clear()
|
||||
trail_timer.start(trail_duration)
|
||||
|
||||
|
||||
func _on_trail_timer_timeout() -> void:
|
||||
is_active = false
|
||||
clear_points()
|
||||
pointers_array.clear()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://bkfe6nn8yxhbq
|
||||
Reference in New Issue
Block a user