Health and AreaDamage components, death and respawn logic

This commit is contained in:
Squinternator 2024-04-08 22:31:16 +00:00
parent 3d21d9a5aa
commit ce1cdda7a1
13 changed files with 121 additions and 22 deletions

View file

@ -0,0 +1,4 @@
extends Area3D
class_name AreaDamageComponent
@export var damage : int = 100

View file

@ -0,0 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://ds1hekx1dq1bg"]
[ext_resource type="Script" path="res://components/area_damage_component.gd" id="1_hn2e3"]
[sub_resource type="SphereShape3D" id="SphereShape3D_080vi"]
radius = 5.0
[node name="AreaDamage" type="Area3D"]
collision_layer = 4
script = ExtResource("1_hn2e3")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_080vi")

View file

@ -0,0 +1,20 @@
extends Area3D
class_name HealthComponent
@export var max_health : int = 100
@export var health : int
signal health_zeroed
func _ready():
health = max_health
area_entered.connect(_on_area_entered)
func damage(amount : int):
health -= amount
if health <= 0:
health_zeroed.emit()
func _on_area_entered(area):
if area is AreaDamageComponent:
damage(area.damage)

View file

@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://bof3mg7wgxrmn"]
[ext_resource type="Script" path="res://components/health_component.gd" id="1_00xis"]
[ext_resource type="Shape3D" uid="uid://dkwljsgaflf31" path="res://characters/player/collision_shape.res" id="2_sgbmt"]
[node name="HealthComponent" type="Area3D"]
collision_layer = 0
collision_mask = 4
script = ExtResource("1_00xis")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = ExtResource("2_sgbmt")