mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-13 15:34:53 +00:00
✨ Health and AreaDamage components, death and respawn logic
This commit is contained in:
parent
3d21d9a5aa
commit
ce1cdda7a1
13 changed files with 121 additions and 22 deletions
4
components/area_damage_component.gd
Normal file
4
components/area_damage_component.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extends Area3D
|
||||
class_name AreaDamageComponent
|
||||
|
||||
@export var damage : int = 100
|
||||
13
components/area_damage_component.tscn
Normal file
13
components/area_damage_component.tscn
Normal 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")
|
||||
20
components/health_component.gd
Normal file
20
components/health_component.gd
Normal 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)
|
||||
12
components/health_component.tscn
Normal file
12
components/health_component.tscn
Normal 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")
|
||||
Loading…
Add table
Add a link
Reference in a new issue