Demo: Refactor agents, add health, hitbox and hurtbox
This commit is contained in:
parent
a839be1ada
commit
1d35d84ec5
File diff suppressed because it is too large
Load Diff
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_n83hi")]
|
[node name="Bobby" instance=ExtResource("1_n83hi")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_y7pic")
|
texture = ExtResource("2_y7pic")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_y7pic")
|
texture = ExtResource("2_y7pic")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_y7pic")
|
texture = ExtResource("2_y7pic")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_y7pic")
|
texture = ExtResource("2_y7pic")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_y7pic")
|
texture = ExtResource("2_y7pic")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_y7pic")
|
texture = ExtResource("2_y7pic")
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_115kp")]
|
[node name="Bobby" instance=ExtResource("1_115kp")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_cb5f2")
|
texture = ExtResource("2_cb5f2")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_cb5f2")
|
texture = ExtResource("2_cb5f2")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_cb5f2")
|
texture = ExtResource("2_cb5f2")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_cb5f2")
|
texture = ExtResource("2_cb5f2")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_cb5f2")
|
texture = ExtResource("2_cb5f2")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_cb5f2")
|
texture = ExtResource("2_cb5f2")
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_fkh4o")]
|
[node name="Bobby" instance=ExtResource("1_fkh4o")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_r3phr")
|
texture = ExtResource("2_r3phr")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_r3phr")
|
texture = ExtResource("2_r3phr")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_r3phr")
|
texture = ExtResource("2_r3phr")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_r3phr")
|
texture = ExtResource("2_r3phr")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_r3phr")
|
texture = ExtResource("2_r3phr")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_r3phr")
|
texture = ExtResource("2_r3phr")
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_y8fj3")]
|
[node name="Bobby" instance=ExtResource("1_y8fj3")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_iv43q")
|
texture = ExtResource("2_iv43q")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_iv43q")
|
texture = ExtResource("2_iv43q")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_iv43q")
|
texture = ExtResource("2_iv43q")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_iv43q")
|
texture = ExtResource("2_iv43q")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_iv43q")
|
texture = ExtResource("2_iv43q")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_iv43q")
|
texture = ExtResource("2_iv43q")
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_afx5l")]
|
[node name="Bobby" instance=ExtResource("1_afx5l")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_e51r0")
|
texture = ExtResource("2_e51r0")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_e51r0")
|
texture = ExtResource("2_e51r0")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_e51r0")
|
texture = ExtResource("2_e51r0")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_e51r0")
|
texture = ExtResource("2_e51r0")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_e51r0")
|
texture = ExtResource("2_e51r0")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_e51r0")
|
texture = ExtResource("2_e51r0")
|
||||||
|
|
|
@ -3,22 +3,22 @@
|
||||||
[ext_resource type="PackedScene" uid="uid://ooigbfhfy4wa" path="res://demo/agents/agent_base.tscn" id="1_l180o"]
|
[ext_resource type="PackedScene" uid="uid://ooigbfhfy4wa" path="res://demo/agents/agent_base.tscn" id="1_l180o"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cw8s50856x8ct" path="res://demo/assets/agent_melee_simple.png" id="2_bvbes"]
|
[ext_resource type="Texture2D" uid="uid://cw8s50856x8ct" path="res://demo/assets/agent_melee_simple.png" id="2_bvbes"]
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_l180o")]
|
[node name="AgentMeleeSimple" instance=ExtResource("1_l180o")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_bvbes")
|
texture = ExtResource("2_bvbes")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_bvbes")
|
texture = ExtResource("2_bvbes")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_bvbes")
|
texture = ExtResource("2_bvbes")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_bvbes")
|
texture = ExtResource("2_bvbes")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_bvbes")
|
texture = ExtResource("2_bvbes")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_bvbes")
|
texture = ExtResource("2_bvbes")
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_oa4xm")]
|
[node name="Bobby" instance=ExtResource("1_oa4xm")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_37lvn")
|
texture = ExtResource("2_37lvn")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_37lvn")
|
texture = ExtResource("2_37lvn")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_37lvn")
|
texture = ExtResource("2_37lvn")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_37lvn")
|
texture = ExtResource("2_37lvn")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_37lvn")
|
texture = ExtResource("2_37lvn")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_37lvn")
|
texture = ExtResource("2_37lvn")
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_2ir76")]
|
[node name="Bobby" instance=ExtResource("1_2ir76")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_w8tqw")
|
texture = ExtResource("2_w8tqw")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_w8tqw")
|
texture = ExtResource("2_w8tqw")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_w8tqw")
|
texture = ExtResource("2_w8tqw")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_w8tqw")
|
texture = ExtResource("2_w8tqw")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_w8tqw")
|
texture = ExtResource("2_w8tqw")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_w8tqw")
|
texture = ExtResource("2_w8tqw")
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
[node name="Bobby" instance=ExtResource("1_neifu")]
|
[node name="Bobby" instance=ExtResource("1_neifu")]
|
||||||
|
|
||||||
[node name="LegL" parent="Rig" index="0"]
|
[node name="LegL" parent="Root/Rig" index="0"]
|
||||||
texture = ExtResource("2_fcti4")
|
texture = ExtResource("2_fcti4")
|
||||||
|
|
||||||
[node name="LegR" parent="Rig" index="1"]
|
[node name="LegR" parent="Root/Rig" index="1"]
|
||||||
texture = ExtResource("2_fcti4")
|
texture = ExtResource("2_fcti4")
|
||||||
|
|
||||||
[node name="Body" parent="Rig" index="2"]
|
[node name="Body" parent="Root/Rig" index="2"]
|
||||||
texture = ExtResource("2_fcti4")
|
texture = ExtResource("2_fcti4")
|
||||||
|
|
||||||
[node name="Hat" parent="Rig/Body" index="0"]
|
[node name="Hat" parent="Root/Rig/Body" index="0"]
|
||||||
texture = ExtResource("2_fcti4")
|
texture = ExtResource("2_fcti4")
|
||||||
|
|
||||||
[node name="HandL" parent="Rig/Body" index="1"]
|
[node name="HandL" parent="Root/Rig/Body" index="1"]
|
||||||
texture = ExtResource("2_fcti4")
|
texture = ExtResource("2_fcti4")
|
||||||
|
|
||||||
[node name="HandR" parent="Rig/Body" index="2"]
|
[node name="HandR" parent="Root/Rig/Body" index="2"]
|
||||||
texture = ExtResource("2_fcti4")
|
texture = ExtResource("2_fcti4")
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
## Base agent script.
|
||||||
|
|
||||||
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||||
|
@onready var bt_player: BTPlayer = $BTPlayer
|
||||||
|
@onready var health: Health = $Health
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
health.damaged.connect(_damaged)
|
||||||
|
health.death.connect(_die)
|
||||||
|
|
||||||
|
|
||||||
|
func _damaged(_amount: float) -> void:
|
||||||
|
animation_player.play(&"hit")
|
||||||
|
|
||||||
|
|
||||||
|
func _die() -> void:
|
||||||
|
animation_player.play(&"death")
|
||||||
|
bt_player.active = false
|
|
@ -0,0 +1,29 @@
|
||||||
|
class_name Health
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
## Tracks health and emits signal when damaged or dead.
|
||||||
|
|
||||||
|
signal death
|
||||||
|
signal damaged(amount: float)
|
||||||
|
|
||||||
|
@export var max_health: float = 10.0
|
||||||
|
|
||||||
|
var _current: float
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
_current = max_health
|
||||||
|
|
||||||
|
|
||||||
|
func take_damage(amount: float) -> void:
|
||||||
|
_current -= amount
|
||||||
|
_current = max(_current, 0.0)
|
||||||
|
|
||||||
|
if _current <= 0.0:
|
||||||
|
death.emit()
|
||||||
|
else:
|
||||||
|
damaged.emit(amount)
|
||||||
|
|
||||||
|
|
||||||
|
func get_current() -> float:
|
||||||
|
return _current
|
|
@ -0,0 +1,14 @@
|
||||||
|
class_name Hitbox
|
||||||
|
extends Area2D
|
||||||
|
|
||||||
|
## Area that deals damage.
|
||||||
|
|
||||||
|
@export var damage: float = 1.0
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
area_entered.connect(_on_area_entered)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_area_entered(area: Area2D) -> void:
|
||||||
|
var hurtbox := area as Hurtbox
|
||||||
|
hurtbox.take_damage(damage, self)
|
|
@ -0,0 +1,12 @@
|
||||||
|
class_name Hurtbox
|
||||||
|
extends Area2D
|
||||||
|
|
||||||
|
## Area that registers damage.
|
||||||
|
|
||||||
|
@export var health: Health
|
||||||
|
|
||||||
|
func take_damage(amount: float, source: Area2D) -> void:
|
||||||
|
if source.owner == owner:
|
||||||
|
# Don't damage yourself.
|
||||||
|
return
|
||||||
|
health.take_damage(amount)
|
Loading…
Reference in New Issue