add health component and FollowTarget Enemy Controller and minor changes

This commit is contained in:
2026-05-20 19:31:29 +01:00
parent bceb6c6df8
commit 962bc016a3
9 changed files with 56 additions and 5 deletions
+5 -1
View File
@@ -4,6 +4,9 @@ class_name CharacterController extends Node
@export_category("Movement Setting")
@export var body: CharacterBody2D
@export var move_res:MovementResouce = MovementResouce.new()
@export_group("Flags")
## Will allow body to move an slide on it's own without parent callling
@export var handle_movement:bool = false
# @export var SPEED = 500.0
# @export var JUMP_VELOCITY = -900.0
# @export var gravity = 1900
@@ -112,7 +115,8 @@ func _physics_process(delta: float) -> void:
# jump_loaded = false
# has_released_jump = false
# body.velocity.y = JUMP_VELOCITY
# move_and_slide()
if handle_movement:
body.move_and_slide()
# func jump():
# jump_loaded = true
@@ -0,0 +1,17 @@
class_name FollowTargetEnemyController extends SimpleEnemycontroller
@export var target:Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
super._ready()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if target:
direction = sign(target.global_position.x - body.global_position.x )
else:
direction = 0
super._process(delta)
@@ -0,0 +1 @@
uid://12f5ubnmfl0v
@@ -4,6 +4,7 @@ class_name SimpleEnemycontroller extends Node
@export var body: CharacterBody2D
@export var move_res:MovementResouce = MovementResouce.new()
@export var direction:float = 0
@export var handle_movement:bool = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@@ -19,3 +20,6 @@ func _process(delta: float) -> void:
body.velocity.x = move_toward(body.velocity.x, 0, move_res.speed)
if not body.is_on_floor():
body.velocity.y += move_res.gravity * delta
if handle_movement:
body.move_and_slide()
+25
View File
@@ -0,0 +1,25 @@
class_name HealthComponent extends Node
@export var max_health:float = 100
var _health = 100
signal health_changed(current_health:float)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
_health = max_health
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
func add_health(amount:float):
_health = max(_health + amount, max_health)
health_changed.emit(_health)
func subtract_health(amount:float):
_health = max(_health - amount, 0)
health_changed.emit(_health)
func get_health() -> float:
return _health
+1
View File
@@ -0,0 +1 @@
uid://o21d85vy2cfs
+1 -2
View File
@@ -1,11 +1,10 @@
class_name HitBox extends Area2D
@export var damage:float = 10
@export_flags("player","enemy") var affect:int = 0
@export_flags("player","enemy") var damage_type:int = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
print(affect)
pass # Replace with function body.
+2 -2
View File
@@ -1,7 +1,7 @@
class_name HurtBox extends Area2D
signal damage_recieved(damage:float)
@export_flags("player","enemy") var type
@export_flags("player","enemy") var respond_from
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@@ -13,6 +13,6 @@ func _process(delta: float) -> void:
pass
func on_damage_receieved(hitbox:HitBox):
if hitbox.affect & type:
if hitbox.damage_type & respond_from:
damage_recieved.emit(hitbox.damage)
#if type