feat: 1. 添加charge冲锋敌人动画和攻击脚本
2. 添加shoot射击敌人攻击脚本
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
extends Node2D
|
||||
class_name ChargeBehabior
|
||||
|
||||
@export var enemy: Enemy
|
||||
@export var anim_effects: AnimationPlayer
|
||||
@export var prep_time := 1.0
|
||||
@export var cooldown := 3.0
|
||||
|
||||
|
||||
var current_cooldown := 0.0
|
||||
var charge_attack_position := Vector2.ZERO
|
||||
var is_charging := false
|
||||
func _ready() -> void:
|
||||
current_cooldown = cooldown
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if enemy == null:
|
||||
return
|
||||
|
||||
if is_charging:
|
||||
enemy.global_position = enemy.global_position.move_toward(charge_attack_position, (enemy.stats.speed * 5) * delta)
|
||||
|
||||
if enemy.global_position.distance_to(charge_attack_position) < 50:
|
||||
end_charge()
|
||||
else:
|
||||
if current_cooldown > 0:
|
||||
current_cooldown -= delta
|
||||
else:
|
||||
if is_instance_valid(Global.player):
|
||||
charge_attack_position = Global.player.global_position
|
||||
start_charge()
|
||||
|
||||
|
||||
func start_charge() -> void:
|
||||
enemy.can_move = false
|
||||
anim_effects.play("charge")
|
||||
await anim_effects.animation_finished
|
||||
is_charging = true
|
||||
|
||||
func end_charge() -> void:
|
||||
is_charging = false
|
||||
current_cooldown = cooldown
|
||||
enemy.can_move = true
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://bnmw1uhp71ipe
|
||||
@@ -43,12 +43,17 @@ func get_move_direction() -> Vector2:
|
||||
return direction
|
||||
|
||||
func update_rotate() -> void:
|
||||
if is_instance_valid(Global.player):
|
||||
|
||||
print("11111111")
|
||||
|
||||
if !is_instance_valid(Global.player):
|
||||
return
|
||||
|
||||
var player_pos := Global.player.position
|
||||
|
||||
var moving_right := global_position.x < player_pos.x
|
||||
|
||||
print(moving_right, '111111')
|
||||
visuals.scale = Vector2(-0.5,0.5) if moving_right else Vector2(0.5,0.5)
|
||||
|
||||
func can_move_forwards_player() -> bool:
|
||||
|
||||
@@ -3,9 +3,62 @@
|
||||
[ext_resource type="PackedScene" uid="uid://bfuqhhe8r8asg" path="res://scenes/unit/enemy/enemy_chaser_slow.tscn" id="1_ksdef"]
|
||||
[ext_resource type="Resource" uid="uid://delxlqjos3br" path="res://resources/units/enemies/stats_enemy_charger.tres" id="2_4i178"]
|
||||
[ext_resource type="Texture2D" uid="uid://emsi6ifyt0vf" path="res://assets/sprites/Enemies/Enemy_5.png" id="2_knpng"]
|
||||
[ext_resource type="Script" uid="uid://bnmw1uhp71ipe" path="res://scenes/unit/enemy/charge_behavior.gd" id="4_4i178"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_4i178"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Visuals/Sprite:modulate")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_1som8"]
|
||||
resource_name = "charge"
|
||||
length = 0.7
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Visuals/Sprite:modulate")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1), Color(0.8509804, 0.2901961, 0.4509804, 1), Color(1, 1, 1, 1), Color(0.8509804, 0.2901961, 0.4509804, 1), Color(1, 1, 1, 1), Color(0.8509804, 0.2901961, 0.4509804, 1), Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_eecfj"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_4i178"),
|
||||
&"charge": SubResource("Animation_1som8")
|
||||
}
|
||||
|
||||
[node name="EnemyCharger" unique_id=2092979720 instance=ExtResource("1_ksdef")]
|
||||
stats = ExtResource("2_4i178")
|
||||
|
||||
[node name="Sprite" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="1" unique_id=1925870318]
|
||||
texture = ExtResource("2_knpng")
|
||||
|
||||
[node name="CollisionShape2D" parent="HurtboxComponent" parent_id_path=PackedInt32Array(1155790880) index="0" unique_id=880029571]
|
||||
visible = false
|
||||
|
||||
[node name="CollisionShape2D" parent="HitboxComponent" parent_id_path=PackedInt32Array(151235566) index="0" unique_id=906401181]
|
||||
visible = false
|
||||
|
||||
[node name="ChargeBehavior" type="Node2D" parent="." index="10" unique_id=1772502108 node_paths=PackedStringArray("enemy", "anim_effects")]
|
||||
script = ExtResource("4_4i178")
|
||||
enemy = NodePath("..")
|
||||
anim_effects = NodePath("../AnimationEffects")
|
||||
|
||||
[node name="AnimationEffects" type="AnimationPlayer" parent="." index="11" unique_id=2036684046]
|
||||
libraries/ = SubResource("AnimationLibrary_eecfj")
|
||||
|
||||
@@ -3,9 +3,20 @@
|
||||
[ext_resource type="PackedScene" uid="uid://bfuqhhe8r8asg" path="res://scenes/unit/enemy/enemy_chaser_slow.tscn" id="1_tty1r"]
|
||||
[ext_resource type="Resource" uid="uid://bnknrm368mpwb" path="res://resources/units/enemies/stats_enemy_shooter.tres" id="2_6k67w"]
|
||||
[ext_resource type="Texture2D" uid="uid://4mllmwdfhmce" path="res://assets/sprites/Enemies/Enemy_4.png" id="2_tev67"]
|
||||
[ext_resource type="Script" uid="uid://y47blv3332q8" path="res://scenes/unit/enemy/shooting_behavior.gd" id="4_6k67w"]
|
||||
[ext_resource type="PackedScene" uid="uid://bmhud2e0x287r" path="res://scenes/projectiles/projectile_enemy.tscn" id="5_kpiq8"]
|
||||
|
||||
[node name="EnemyShooter" unique_id=2092979720 instance=ExtResource("1_tty1r")]
|
||||
stats = ExtResource("2_6k67w")
|
||||
|
||||
[node name="Sprite" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="1" unique_id=1925870318]
|
||||
texture = ExtResource("2_tev67")
|
||||
|
||||
[node name="FirePos" type="Marker2D" parent="Visuals" parent_id_path=PackedInt32Array(395976388) index="2" unique_id=815261850]
|
||||
position = Vector2(-92, -50)
|
||||
|
||||
[node name="ShootingBehavior" type="Node2D" parent="." index="10" unique_id=1533506602 node_paths=PackedStringArray("enemy", "fire_pos")]
|
||||
script = ExtResource("4_6k67w")
|
||||
enemy = NodePath("..")
|
||||
fire_pos = NodePath("../Visuals/FirePos")
|
||||
projectile_scene = ExtResource("5_kpiq8")
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
extends Node2D
|
||||
class_name ShootingBehavior
|
||||
|
||||
@export var enemy: Enemy
|
||||
@export var fire_pos: Marker2D
|
||||
@export var cooldown := 3.0
|
||||
@export var projectile_count := 3
|
||||
@export var arc_angle := 45.0
|
||||
@export var projectile_scene: PackedScene
|
||||
@export var projectile_speed := 1800.0
|
||||
|
||||
var current_cooldown := 0.0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
current_cooldown = cooldown
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if enemy == null:
|
||||
return
|
||||
|
||||
if current_cooldown > 0:
|
||||
current_cooldown -= delta
|
||||
else:
|
||||
shoot()
|
||||
current_cooldown = cooldown
|
||||
|
||||
func shoot() -> void:
|
||||
if not is_instance_valid(Global.player):
|
||||
return
|
||||
|
||||
enemy.can_move = false
|
||||
|
||||
var direction := enemy.global_position.direction_to(Global.player.global_position)
|
||||
|
||||
var start_angle := -arc_angle / 2.0
|
||||
var angle_step := arc_angle / float(projectile_count - 1 if projectile_count > 1 else 0.0)
|
||||
|
||||
for i in range(projectile_count):
|
||||
var projectile := projectile_scene.instantiate() as Projectile
|
||||
get_tree().root.add_child(projectile)
|
||||
projectile.global_position = fire_pos.global_position
|
||||
|
||||
var rotate_direction := direction.rotated(deg_to_rad(start_angle + angle_step * i))
|
||||
var velocity := rotate_direction * projectile_speed
|
||||
projectile.set_projectile(velocity, enemy.stats.damage, false, 0, enemy)
|
||||
|
||||
|
||||
await get_tree().create_timer(1).timeout
|
||||
enemy.can_move = true
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://y47blv3332q8
|
||||
Reference in New Issue
Block a user