some workable stuff
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
extends AITemplate
|
||||
|
||||
func getDirection(position, enemyPosition) -> Vector2:
|
||||
return Vector2.ZERO
|
||||
return Vector2(enemyPosition - position).normalized()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[node name="BatSpawnable" instance=ExtResource("1_verf7")]
|
||||
maxHp = 10
|
||||
attackSpeed = 10.0
|
||||
speed = 100.0
|
||||
speed = 2000.0
|
||||
damage = 1
|
||||
priority = 1
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@ extends CharacterBody2D
|
||||
@export var speed : float = 0
|
||||
@export var damage : int = 0
|
||||
@export var priority : int = 0
|
||||
@export var canAttack : bool = true
|
||||
|
||||
@onready var ai : Node = $AI
|
||||
@onready var animatedSprite : AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
var isAlive : bool = true
|
||||
var isFacingLeft : bool = false
|
||||
var direction : Vector2 = Vector2.ZERO
|
||||
var enemy : CharacterBody2D = null
|
||||
|
||||
@@ -27,19 +29,28 @@ func _process(delta):
|
||||
return
|
||||
|
||||
if enemy != null:
|
||||
direction = ai.getDirection(position, enemy.position)
|
||||
direction = ai.getDirection(global_position, enemy.global_position)
|
||||
else:
|
||||
direction = Vector2.ZERO
|
||||
|
||||
if !isFacingLeft && velocity.x >= 0:
|
||||
isFacingLeft = true
|
||||
scale = Vector2(1, 1)
|
||||
elif isFacingLeft && velocity.x < 0:
|
||||
isFacingLeft = false
|
||||
scale = Vector2(-1, 1)
|
||||
|
||||
velocity = direction * speed * delta
|
||||
move_and_slide()
|
||||
|
||||
func attack(target):
|
||||
func attack():
|
||||
if !canAttack || !isAlive:
|
||||
return
|
||||
animatedSprite.play("attack")
|
||||
animatedSprite.connect("animation_finished", endAttack(target))
|
||||
animatedSprite.connect("animation_finished", endAttack)
|
||||
|
||||
func endAttack(target):
|
||||
target.receive_damage(damage)
|
||||
func endAttack():
|
||||
|
||||
animatedSprite.play("default")
|
||||
|
||||
func receive_damage(dmg):
|
||||
@@ -55,13 +66,13 @@ func receive_damage(dmg):
|
||||
func die():
|
||||
isAlive = false
|
||||
animatedSprite.play("death")
|
||||
animatedSprite.connect("animation_finished", self.fadeOut())
|
||||
animatedSprite.connect("animation_finished", fadeOut)
|
||||
|
||||
func fadeOut():
|
||||
var tween = Tween.new()
|
||||
add_child(tween)
|
||||
var tween = get_tree().create_tween()
|
||||
tween.tween_property(animatedSprite, "modulate", Color(0,0,0,0), 1)
|
||||
tween.tween_callback(clean())
|
||||
tween.tween_callback(clean)
|
||||
|
||||
|
||||
func clean():
|
||||
queue_free()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=36 format=3 uid="uid://kkfxguj0lr5a"]
|
||||
[gd_scene load_steps=37 format=3 uid="uid://kkfxguj0lr5a"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/Spawnables/template_spawnable.gd" id="1_rkej7"]
|
||||
[ext_resource type="Texture2D" uid="uid://f60ndepwmpj2" path="res://Assets/Bat/noBKG_BatAttack_strip.png" id="2_7ayi7"]
|
||||
@@ -150,7 +150,7 @@ animations = [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_bxitd")
|
||||
}],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": &"attack",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
@@ -185,7 +185,7 @@ animations = [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_7bunh")
|
||||
}],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": &"death",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
@@ -224,8 +224,12 @@ radius = 6.0
|
||||
height = 14.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_2l8j3"]
|
||||
radius = 7.0
|
||||
height = 22.0
|
||||
radius = 4.0
|
||||
height = 14.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_o2kl1"]
|
||||
radius = 2.0
|
||||
height = 16.0
|
||||
|
||||
[node name="TemplateSpawnable" type="CharacterBody2D"]
|
||||
collision_layer = 6
|
||||
@@ -234,7 +238,9 @@ script = ExtResource("1_rkej7")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = SubResource("SpriteFrames_k6v1d")
|
||||
frame_progress = 0.107531
|
||||
animation = &"attack"
|
||||
frame = 7
|
||||
frame_progress = 0.387978
|
||||
|
||||
[node name="BodyCollision" type="CollisionShape2D" parent="."]
|
||||
rotation = 1.5708
|
||||
@@ -243,8 +249,15 @@ shape = SubResource("CapsuleShape2D_5aviq")
|
||||
[node name="Attack" type="Area2D" parent="."]
|
||||
|
||||
[node name="AttackCollision" type="CollisionShape2D" parent="Attack"]
|
||||
position = Vector2(1, 1)
|
||||
rotation = 1.5708
|
||||
shape = SubResource("CapsuleShape2D_2l8j3")
|
||||
debug_color = Color(0.803922, 0, 0.180392, 0.419608)
|
||||
debug_color = Color(0.678431, 0.556863, 0.137255, 0.419608)
|
||||
|
||||
[node name="DamageCollision" type="CollisionShape2D" parent="Attack"]
|
||||
position = Vector2(2, 2)
|
||||
rotation = 1.5708
|
||||
shape = SubResource("CapsuleShape2D_o2kl1")
|
||||
debug_color = Color(0.639216, 0, 0.156863, 0.419608)
|
||||
|
||||
[node name="AI" type="Node" parent="."]
|
||||
|
||||
Reference in New Issue
Block a user