Animation fix and some more tests
This commit is contained in:
@ -14,8 +14,8 @@ static var NAMES = ["Forkman", "Cobold", "Ork"]
|
||||
|
||||
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"))
|
||||
get_node("CharacterBody2D/Area2D").body_entered.connect(Collision_Handler)
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").animation_finished.connect(AnimatedSprite2D_animation_finished)
|
||||
set_character_data()
|
||||
adjust_health_bar()
|
||||
|
||||
@ -67,11 +67,14 @@ func set_character_data():
|
||||
shield = 0
|
||||
damage = 1
|
||||
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").speed_scale = float(speed) / 100 #adjust animation speed based on the character speed
|
||||
adjust_speed_of_animation() #adjust animation speed based on the character speed
|
||||
current_health = health
|
||||
current_shield = shield
|
||||
|
||||
|
||||
func adjust_speed_of_animation() -> void:
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").speed_scale = snapped(float(speed) / 100, 0.1)
|
||||
|
||||
func adjust_health_bar() -> void:
|
||||
var health_bar = get_node("ProgressBar")
|
||||
|
||||
@ -102,6 +105,7 @@ func adjust_health_bar() -> void:
|
||||
health_bar.add_theme_stylebox_override("background", bg_style)
|
||||
|
||||
func enemy_hurt(amount) -> void:
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hurt")
|
||||
if current_shield > 0:
|
||||
if current_shield > amount:
|
||||
current_shield -= amount
|
||||
@ -118,16 +122,16 @@ func enemy_hurt(amount) -> void:
|
||||
adjust_health_bar()
|
||||
|
||||
func AnimatedSprite2D_animation_finished() -> void:
|
||||
var animated_sprite = get_node("CharacterBody2D/AnimatedSprite2D")
|
||||
if animated_sprite.animation == "hurt":
|
||||
animated_sprite.play("walk")
|
||||
|
||||
print("Switching to walk animation. Current Speed Scale:",
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").speed_scale)
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("walk")
|
||||
|
||||
|
||||
|
||||
func Collision_Handler(body: Node2D):
|
||||
if body.get_parent().name.contains("StickTrap"):
|
||||
if not body.get_parent().get_if_moving_state():
|
||||
enemy_hurt(25)
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hurt")
|
||||
if body.get_parent().name.contains("Mine"):
|
||||
if not body.get_parent().get_if_moving_state():
|
||||
var surrounding_enemies = body.get_node("Area2D").get_overlapping_bodies()
|
||||
|
Reference in New Issue
Block a user