Tutorial 17 Enemy AI and Stats

This commit is contained in:
Alan Youngblood
2024-11-20 17:22:31 -05:00
parent 23a693d4a9
commit 24bc047855
14 changed files with 88 additions and 22 deletions

View File

@ -3,6 +3,7 @@ extends KinematicBody2D
var velocity = Vector2.ZERO
var input_vector = Vector2.ZERO
var roll_vector = Vector2.DOWN
var stats = PlayerStats
const ACCELERATION = 500
const MAX_SPEED = 80
@ -21,8 +22,10 @@ onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
onready var swordHitbox = $HitboxPivot/SwordHitbox
onready var hurtBox = $Hurtbox
func _ready():
stats.connect("no_health", self, "queue_free")
animationTree.active = true
swordHitbox.knockback_vector = roll_vector
@ -90,3 +93,9 @@ func attack_aninimation_finished():
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Hurtbox_area_entered(area):
stats.health -= 1
hurtBox.start_invincibility(0.5)
hurtBox.create_hit_effect()

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=54 format=2]
[gd_scene load_steps=56 format=2]
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
[ext_resource path="res://Player/Player.png" type="Texture" id=2]
[ext_resource path="res://Overlap/Hitbox.tscn" type="PackedScene" id=3]
[ext_resource path="res://Player/SwordHitbox.gd" type="Script" id=4]
[ext_resource path="res://Overlap/Hurtbox.tscn" type="PackedScene" id=5]
[sub_resource type="CapsuleShape2D" id=1]
radius = 4.0
@ -641,6 +642,10 @@ graph_offset = Vector2( -10, -78 )
[sub_resource type="CapsuleShape2D" id=40]
height = 12.0
[sub_resource type="CapsuleShape2D" id=52]
radius = 5.0
height = 6.0
[node name="Player" type="KinematicBody2D"]
collision_layer = 2
script = ExtResource( 1 )
@ -698,4 +703,14 @@ script = ExtResource( 4 )
shape = SubResource( 40 )
disabled = true
[node name="Hurtbox" parent="." instance=ExtResource( 5 )]
collision_layer = 4
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
position = Vector2( 0, -4 )
shape = SubResource( 52 )
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
[editable path="HitboxPivot/SwordHitbox"]
[editable path="Hurtbox"]

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Stats.tscn" type="PackedScene" id=1]
[node name="PlayerStats" instance=ExtResource( 1 )]
max_health = 4