First trap initialized!
This commit is contained in:
@ -12,10 +12,10 @@ var last_position: Vector2 = Vector2.ZERO # To store the previous position
|
||||
|
||||
func _ready() -> void:
|
||||
last_position = get_parent().position
|
||||
|
||||
get_node("CharacterBody2D/Area2D").connect("body_entered", Callable(self, "Collision_Handler"))
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").connect("animation_finished", Callable(self, "AnimatedSprite2D_animation_finished"))
|
||||
set_character_data()
|
||||
adjust_health_bar()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
move_character(delta)
|
||||
@ -69,12 +69,55 @@ func set_character_data():
|
||||
|
||||
func adjust_health_bar() -> void:
|
||||
var health_bar = get_node("ProgressBar")
|
||||
|
||||
# Create new StyleBox resources for each instance
|
||||
var fill_style = StyleBoxFlat.new()
|
||||
fill_style.corner_radius_top_left = 20
|
||||
fill_style.corner_radius_top_right = 20
|
||||
fill_style.corner_radius_bottom_left = 20
|
||||
fill_style.corner_radius_bottom_right = 20
|
||||
|
||||
var bg_style = StyleBoxFlat.new()
|
||||
bg_style.corner_radius_top_left = 20
|
||||
bg_style.corner_radius_top_right = 20
|
||||
bg_style.corner_radius_bottom_left = 20
|
||||
bg_style.corner_radius_bottom_right = 20
|
||||
|
||||
if current_shield > 0:
|
||||
health_bar.get("theme_override_styles/fill").bg_color = Color(0,0,1)
|
||||
health_bar.get("theme_override_styles/background").bg_color = Color(0,1,0)
|
||||
health_bar.value = shield / current_shield * 100
|
||||
fill_style.bg_color = Color(0, 0, 1) # Blue for shield
|
||||
bg_style.bg_color = Color(0, 1, 0) # Green background
|
||||
health_bar.value = int((current_shield / float(shield)) * 100) # Use current_shield and shield
|
||||
else:
|
||||
health_bar.get("theme_override_styles/fill").bg_color = Color(0,1,0)
|
||||
health_bar.get("theme_override_styles/background").bg_color = Color(1,0,0)
|
||||
health_bar.value = health / current_health * 100
|
||||
pass
|
||||
fill_style.bg_color = Color(0, 1, 0) # Green for health
|
||||
bg_style.bg_color = Color(1, 0, 0) # Red background
|
||||
health_bar.value = int((current_health / float(health)) * 100)
|
||||
|
||||
# Apply the styles
|
||||
health_bar.add_theme_stylebox_override("fill", fill_style)
|
||||
health_bar.add_theme_stylebox_override("background", bg_style)
|
||||
|
||||
func enemy_hurt(amount) -> void:
|
||||
if current_shield > 0:
|
||||
if shield > amount:
|
||||
current_shield -= amount
|
||||
else:
|
||||
amount -= current_shield
|
||||
current_shield = 0
|
||||
current_health -= amount
|
||||
else:
|
||||
current_health -= amount
|
||||
|
||||
if current_health <= 0:
|
||||
get_parent().queue_free()
|
||||
else:
|
||||
adjust_health_bar()
|
||||
|
||||
func AnimatedSprite2D_animation_finished() -> void:
|
||||
var animated_sprite = get_node("CharacterBody2D/AnimatedSprite2D")
|
||||
if animated_sprite.animation == "hurt":
|
||||
animated_sprite.play("walk")
|
||||
|
||||
func Collision_Handler(body: Node2D):
|
||||
if body.get_parent().name.contains("StickTrap"):
|
||||
enemy_hurt(25)
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hurt")
|
||||
|
Reference in New Issue
Block a user