Different enemies with different properties
This commit is contained in:
@ -1,35 +1,62 @@
|
||||
extends Node2D
|
||||
|
||||
@export var speed = 100
|
||||
var speed = 0
|
||||
var health = 0
|
||||
var shield = 0
|
||||
|
||||
var current_health = 0
|
||||
var current_shield = 0
|
||||
|
||||
var last_position: Vector2 = Vector2.ZERO # To store the previous position
|
||||
|
||||
func _ready() -> void:
|
||||
last_position = get_parent().position # Set the initial position when the mob starts
|
||||
last_position = get_parent().position
|
||||
set_character_data()
|
||||
adjust_health_bar()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
move_character(delta)
|
||||
|
||||
|
||||
func move_character(delta: float) -> void:
|
||||
var path_follow = get_parent()
|
||||
|
||||
# Update the progress along the path
|
||||
# Update the progress and prevent rotation
|
||||
path_follow.set_progress(path_follow.get_progress() + speed * delta)
|
||||
|
||||
# Prevent rotation (lock rotation to 0)
|
||||
path_follow.rotation = 0
|
||||
|
||||
# Get the current position on the path (mob's position)
|
||||
#turn the character to to the way its headed
|
||||
var current_position = path_follow.position
|
||||
|
||||
# Flip the character if moving left (when moving to the left, the x position decreases)
|
||||
if current_position.x < last_position.x:
|
||||
# Flip the character horizontally by inverting its scale on the x-axis
|
||||
path_follow.scale.x = -abs(path_follow.scale.x)
|
||||
else:
|
||||
# Ensure the character is not flipped when moving right
|
||||
path_follow.scale.x = abs(path_follow.scale.x)
|
||||
|
||||
# Update the last_position for the next frame
|
||||
last_position = current_position
|
||||
|
||||
# If the mob reaches the end of the path, queue it for deletion
|
||||
#if reached the end of the path remove both the path, and the character
|
||||
if path_follow.get_progress_ratio() >= 0.999:
|
||||
get_parent().queue_free()
|
||||
|
||||
|
||||
func set_character_data():
|
||||
match self.name:
|
||||
"Forkman":
|
||||
speed = 100
|
||||
health = 100
|
||||
shield = 100
|
||||
"Swordman":
|
||||
speed = 120
|
||||
health = 100
|
||||
shield = 100
|
||||
|
||||
current_health = health
|
||||
current_shield = shield
|
||||
|
||||
|
||||
func adjust_health_bar() -> void:
|
||||
var health_bar = get_node("ProgressBar")
|
||||
health_bar.value = health / current_health * 100
|
||||
pass
|
||||
|
Reference in New Issue
Block a user