This commit is contained in:
Felix Kaiser
2025-02-17 16:46:19 +01:00
parent 534181eb88
commit 3f62e5e31d
245 changed files with 15711 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
extends Area3D
class_name HealthComponent
@export var max_health : float = 100
@onready var current_health : float = max_health
@export var signal_name : String
signal start_dying
func damage(value: float):
if current_health > 0:
current_health -= value
if signal_name:
HudSignalBus.emit_signal(signal_name, current_health, max_health)
if current_health <= 0:
start_dying.emit()
func _on_area_entered(area: Area3D) -> void:
if area is HealthPickup:
current_health = current_health + area.value
current_health = clamp(current_health, 0, max_health)
HudSignalBus.emit_signal(signal_name, current_health, max_health)
area.queue_free()

View File

@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://d2p86lb72dp61"]
[ext_resource type="Script" path="res://components/healthcomponent.gd" id="1_y6nlw"]
[node name="Healthcomponent" type="Area3D"]
collision_layer = 0
collision_mask = 0
script = ExtResource("1_y6nlw")

15
components/hit_box.gd Normal file
View File

@@ -0,0 +1,15 @@
extends Area3D
@export var health_component : HealthComponent
func _on_body_entered(body: Node3D) -> void:
if body is Projectile:
if is_instance_valid(health_component):
health_component.damage(body.damage)
body.projectile_collision()
func _on_area_entered(area: Area3D) -> void:
if area is ExplosionHurtbox:
if is_instance_valid(health_component):
health_component.damage(area.damage)

25
components/projectile.gd Normal file
View File

@@ -0,0 +1,25 @@
extends CharacterBody3D
class_name Projectile
@export var damage : float = 10
@export var lifetime : float = 1
@export var collsion_scene : PackedScene
signal collided
var timeout_timer : Timer
func _ready() -> void:
timeout_timer = Timer.new()
add_child(timeout_timer)
timeout_timer.timeout.connect(projectile_collision)
timeout_timer.start(lifetime)
func projectile_collision():
timeout_timer.stop()
if collsion_scene:
var new_collision_scene = collsion_scene.instantiate()
get_tree().root.add_child(new_collision_scene)
new_collision_scene.global_transform = global_transform
get_tree().create_timer(lifetime).timeout.connect(queue_free)
collided.emit()

View File

@@ -0,0 +1,12 @@
extends Node3D
@export var speed : float = 100
func _physics_process(delta: float) -> void:
var velocity = speed * -get_parent().transform.basis.z
get_parent().velocity = velocity
if get_parent().move_and_slide():
get_parent().projectile_collision()
queue_free()