Animation fix and some more tests
This commit is contained in:
@ -40,6 +40,7 @@ func target_reached() -> void:
|
|||||||
if name.contains("Arrow"): #special effects here!
|
if name.contains("Arrow"): #special effects here!
|
||||||
if randf() < 0.1:
|
if randf() < 0.1:
|
||||||
target.get_parent().set_speed(target.get_parent().get_speed() / 2)
|
target.get_parent().set_speed(target.get_parent().get_speed() / 2)
|
||||||
|
target.get_parent().adjust_speed_of_animation()
|
||||||
pass
|
pass
|
||||||
if name.contains("Magic"):
|
if name.contains("Magic"):
|
||||||
if randf() < 0.5:
|
if randf() < 0.5:
|
||||||
|
@ -6,6 +6,21 @@
|
|||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lj5pp"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lj5pp"]
|
||||||
size = Vector2(18, 16)
|
size = Vector2(18, 16)
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_0itbo"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Sprite2D:rotation")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [0.0]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_lj5pp"]
|
[sub_resource type="Animation" id="Animation_lj5pp"]
|
||||||
resource_name = "rotation"
|
resource_name = "rotation"
|
||||||
length = 0.5
|
length = 0.5
|
||||||
@ -27,21 +42,6 @@ tracks/0/keys = {
|
|||||||
"values": [0.0, 6.28319]
|
"values": [0.0, 6.28319]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_0itbo"]
|
|
||||||
length = 0.001
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("Sprite2D:rotation")
|
|
||||||
tracks/0/interp = 1
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [0.0]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_55qby"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_55qby"]
|
||||||
_data = {
|
_data = {
|
||||||
&"RESET": SubResource("Animation_0itbo"),
|
&"RESET": SubResource("Animation_0itbo"),
|
||||||
|
@ -105,7 +105,7 @@ animations = [{
|
|||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": ExtResource("21_m5o2x")
|
"texture": ExtResource("21_m5o2x")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"hurt",
|
"name": &"hurt",
|
||||||
"speed": 20.0
|
"speed": 20.0
|
||||||
}, {
|
}, {
|
||||||
@ -201,9 +201,8 @@ collision_layer = 3
|
|||||||
position = Vector2(10, 0)
|
position = Vector2(10, 0)
|
||||||
scale = Vector2(0.25, 0.25)
|
scale = Vector2(0.25, 0.25)
|
||||||
sprite_frames = SubResource("SpriteFrames_brd2m")
|
sprite_frames = SubResource("SpriteFrames_brd2m")
|
||||||
animation = &"hurt"
|
animation = &"walk"
|
||||||
autoplay = "walk"
|
autoplay = "walk"
|
||||||
frame_progress = 0.66798
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||||
scale = Vector2(2, 2)
|
scale = Vector2(2, 2)
|
||||||
|
@ -14,8 +14,8 @@ static var NAMES = ["Forkman", "Cobold", "Ork"]
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
last_position = get_parent().position
|
last_position = get_parent().position
|
||||||
get_node("CharacterBody2D/Area2D").connect("body_entered", Callable(self, "Collision_Handler"))
|
get_node("CharacterBody2D/Area2D").body_entered.connect(Collision_Handler)
|
||||||
get_node("CharacterBody2D/AnimatedSprite2D").connect("animation_finished", Callable(self, "AnimatedSprite2D_animation_finished"))
|
get_node("CharacterBody2D/AnimatedSprite2D").animation_finished.connect(AnimatedSprite2D_animation_finished)
|
||||||
set_character_data()
|
set_character_data()
|
||||||
adjust_health_bar()
|
adjust_health_bar()
|
||||||
|
|
||||||
@ -67,11 +67,14 @@ func set_character_data():
|
|||||||
shield = 0
|
shield = 0
|
||||||
damage = 1
|
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_health = health
|
||||||
current_shield = shield
|
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:
|
func adjust_health_bar() -> void:
|
||||||
var health_bar = get_node("ProgressBar")
|
var health_bar = get_node("ProgressBar")
|
||||||
|
|
||||||
@ -102,6 +105,7 @@ func adjust_health_bar() -> void:
|
|||||||
health_bar.add_theme_stylebox_override("background", bg_style)
|
health_bar.add_theme_stylebox_override("background", bg_style)
|
||||||
|
|
||||||
func enemy_hurt(amount) -> void:
|
func enemy_hurt(amount) -> void:
|
||||||
|
get_node("CharacterBody2D/AnimatedSprite2D").play("hurt")
|
||||||
if current_shield > 0:
|
if current_shield > 0:
|
||||||
if current_shield > amount:
|
if current_shield > amount:
|
||||||
current_shield -= amount
|
current_shield -= amount
|
||||||
@ -118,16 +122,16 @@ func enemy_hurt(amount) -> void:
|
|||||||
adjust_health_bar()
|
adjust_health_bar()
|
||||||
|
|
||||||
func AnimatedSprite2D_animation_finished() -> void:
|
func AnimatedSprite2D_animation_finished() -> void:
|
||||||
var animated_sprite = get_node("CharacterBody2D/AnimatedSprite2D")
|
print("Switching to walk animation. Current Speed Scale:",
|
||||||
if animated_sprite.animation == "hurt":
|
get_node("CharacterBody2D/AnimatedSprite2D").speed_scale)
|
||||||
animated_sprite.play("walk")
|
get_node("CharacterBody2D/AnimatedSprite2D").play("walk")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func Collision_Handler(body: Node2D):
|
func Collision_Handler(body: Node2D):
|
||||||
if body.get_parent().name.contains("StickTrap"):
|
if body.get_parent().name.contains("StickTrap"):
|
||||||
if not body.get_parent().get_if_moving_state():
|
if not body.get_parent().get_if_moving_state():
|
||||||
enemy_hurt(25)
|
enemy_hurt(25)
|
||||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hurt")
|
|
||||||
if body.get_parent().name.contains("Mine"):
|
if body.get_parent().name.contains("Mine"):
|
||||||
if not body.get_parent().get_if_moving_state():
|
if not body.get_parent().get_if_moving_state():
|
||||||
var surrounding_enemies = body.get_node("Area2D").get_overlapping_bodies()
|
var surrounding_enemies = body.get_node("Area2D").get_overlapping_bodies()
|
||||||
|
@ -108,7 +108,7 @@ animations = [{
|
|||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": ExtResource("21_to6c5")
|
"texture": ExtResource("21_to6c5")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"hurt",
|
"name": &"hurt",
|
||||||
"speed": 20.0
|
"speed": 20.0
|
||||||
}, {
|
}, {
|
||||||
@ -206,10 +206,8 @@ shape = SubResource("CircleShape2D_ra45u")
|
|||||||
position = Vector2(10, 0)
|
position = Vector2(10, 0)
|
||||||
scale = Vector2(0.2, 0.186)
|
scale = Vector2(0.2, 0.186)
|
||||||
sprite_frames = SubResource("SpriteFrames_gxpsl")
|
sprite_frames = SubResource("SpriteFrames_gxpsl")
|
||||||
animation = &"hurt"
|
animation = &"walk"
|
||||||
autoplay = "walk"
|
autoplay = "walk"
|
||||||
frame = 11
|
|
||||||
frame_progress = 0.9629
|
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ animations = [{
|
|||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": ExtResource("21_xh1xf")
|
"texture": ExtResource("21_xh1xf")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"hurt",
|
"name": &"hurt",
|
||||||
"speed": 20.0
|
"speed": 20.0
|
||||||
}, {
|
}, {
|
||||||
@ -201,9 +201,8 @@ collision_layer = 3
|
|||||||
position = Vector2(10, 0)
|
position = Vector2(10, 0)
|
||||||
scale = Vector2(0.18, 0.18)
|
scale = Vector2(0.18, 0.18)
|
||||||
sprite_frames = SubResource("SpriteFrames_h86ts")
|
sprite_frames = SubResource("SpriteFrames_h86ts")
|
||||||
animation = &"hurt"
|
animation = &"walk"
|
||||||
autoplay = "walk"
|
autoplay = "walk"
|
||||||
frame_progress = 0.748545
|
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
||||||
|
|
||||||
|
@ -1,66 +1,82 @@
|
|||||||
extends GutTest
|
extends GutTest
|
||||||
|
|
||||||
var EnemyScene = load("res://Game/Mobs/forkman.tscn") # Ellenenség PackedScene útvonala
|
var EnemyScene = load("res://Game/Mobs/forkman.tscn") # Path to enemy PackedScene
|
||||||
var _enemy_instance = null
|
var _enemy_instance = null
|
||||||
var _mock_parent = null
|
var _mock_parent = null
|
||||||
|
|
||||||
func before_each():
|
func before_each():
|
||||||
# Szülő mockolása PathFollow2D helyett
|
# Mock parent instead of PathFollow2D
|
||||||
_mock_parent = PathFollow2D.new()
|
_mock_parent = PathFollow2D.new()
|
||||||
_mock_parent.name = "PathFollow2D_Mock"
|
_mock_parent.name = "PathFollow2D_Mock"
|
||||||
add_child(_mock_parent)
|
add_child(_mock_parent)
|
||||||
|
|
||||||
# Scene példányosítása
|
# Instantiate scene
|
||||||
_enemy_instance = EnemyScene.instantiate()
|
_enemy_instance = EnemyScene.instantiate()
|
||||||
_mock_parent.add_child(_enemy_instance)
|
_mock_parent.add_child(_enemy_instance)
|
||||||
|
|
||||||
# Gyermek node-ok inicializálása
|
# Initialize child nodes
|
||||||
await get_tree().process_frame # Szükséges a _ready() függvény teljes lefutásához
|
await get_tree().process_frame # Required for complete _ready() execution
|
||||||
|
|
||||||
func after_each():
|
func after_each():
|
||||||
_enemy_instance.queue_free()
|
_enemy_instance.queue_free()
|
||||||
_mock_parent.queue_free()
|
_mock_parent.queue_free()
|
||||||
|
|
||||||
|
# Check for children
|
||||||
func test_scene_initialization():
|
func test_scene_initialization():
|
||||||
# Gyermek elemek ellenőrzése
|
|
||||||
var character_body = _enemy_instance.get_node("CharacterBody2D")
|
var character_body = _enemy_instance.get_node("CharacterBody2D")
|
||||||
var health_bar = _enemy_instance.get_node("ProgressBar")
|
var health_bar = _enemy_instance.get_node("ProgressBar")
|
||||||
assert_not_null(character_body, "Hiányzó CharacterBody2D")
|
assert_not_null(character_body, "Missing CharacterBody2D")
|
||||||
assert_not_null(health_bar, "Hiányzó ProgressBar")
|
assert_not_null(health_bar, "Missing ProgressBar")
|
||||||
|
|
||||||
|
|
||||||
|
# Check damage mechanics
|
||||||
func test_shield_damage_reduction():
|
func test_shield_damage_reduction():
|
||||||
# Kezdeti állapot beállítása
|
|
||||||
_enemy_instance.current_shield = 50
|
_enemy_instance.current_shield = 50
|
||||||
_enemy_instance.current_health = 100
|
_enemy_instance.current_health = 100
|
||||||
|
|
||||||
# Sebzés alkalmazása
|
|
||||||
_enemy_instance.enemy_hurt(30)
|
_enemy_instance.enemy_hurt(30)
|
||||||
|
assert_eq(_enemy_instance.current_shield, 20, "Incorrect shield value")
|
||||||
# Ellenőrzések
|
assert_eq(_enemy_instance.current_health, 100, "Health should remain unchanged with this damage amount")
|
||||||
assert_eq(_enemy_instance.current_shield, 20, "Pajzs érték helytelen")
|
|
||||||
assert_eq(_enemy_instance.current_health, 100, "Életerő nem változhat pajzs esetén")
|
|
||||||
|
|
||||||
func test_shield_break_and_health_damage():
|
func test_shield_break_and_health_damage():
|
||||||
# Kezdeti állapot
|
|
||||||
_enemy_instance.current_shield = 20
|
_enemy_instance.current_shield = 20
|
||||||
_enemy_instance.current_health = 100
|
_enemy_instance.current_health = 100
|
||||||
|
|
||||||
# Nagy sebzés
|
|
||||||
_enemy_instance.enemy_hurt(30)
|
_enemy_instance.enemy_hurt(30)
|
||||||
|
assert_eq(_enemy_instance.current_shield, 0, "Shield should be depleted")
|
||||||
# Ellenőrzések
|
assert_eq(_enemy_instance.current_health, 90, "Incorrect health value")
|
||||||
assert_eq(_enemy_instance.current_shield, 0, "Pajzsnak nullának kell lennie")
|
|
||||||
assert_eq(_enemy_instance.current_health, 90, "Életerő csökkenés hibás")
|
|
||||||
|
|
||||||
func test_health_damage_without_shield():
|
func test_health_damage_without_shield():
|
||||||
# Pajzs nélküli állapot
|
|
||||||
_enemy_instance.current_shield = 0
|
_enemy_instance.current_shield = 0
|
||||||
_enemy_instance.current_health = 80
|
_enemy_instance.current_health = 80
|
||||||
|
|
||||||
# Sebzés
|
|
||||||
_enemy_instance.enemy_hurt(25)
|
_enemy_instance.enemy_hurt(25)
|
||||||
|
assert_eq(_enemy_instance.current_shield, 0, "Shield should remain zero")
|
||||||
|
assert_eq(_enemy_instance.current_health, 55, "Incorrect health amount")
|
||||||
|
|
||||||
assert_eq(_enemy_instance.current_shield, 0, "Pajzs mértékének csökkenése változatlan")
|
#Check for animation change
|
||||||
assert_eq(_enemy_instance.current_health, 55, "Életerő csökkenés hibás pajzs nélkül")
|
func test_hurt_animation_plays_on_damage():
|
||||||
|
_enemy_instance.enemy_hurt(10)
|
||||||
|
var anim_sprite = _enemy_instance.get_node("CharacterBody2D/AnimatedSprite2D")
|
||||||
|
assert_eq(anim_sprite.animation, "hurt", "Hurt animation must be playing")
|
||||||
|
|
||||||
|
#Check animation speed change
|
||||||
|
func test_animation_speed_scales_with_speed():
|
||||||
|
# Sebesség beállítások ellenőrzése
|
||||||
|
_enemy_instance.set_character_data()
|
||||||
|
var anim_sprite = _enemy_instance.get_node("CharacterBody2D/AnimatedSprite2D")
|
||||||
|
var expected_speed = snapped(_enemy_instance.speed / 100.0 , 0.1)
|
||||||
|
assert_eq(snapped(anim_sprite.speed_scale, 0.1), expected_speed, "Animation speed should match movement speed")
|
||||||
|
|
||||||
|
#check for cholorchange on healthbar
|
||||||
|
func test_health_bar_color_changes_with_shield():
|
||||||
|
_enemy_instance.current_shield = 50
|
||||||
|
_enemy_instance.adjust_health_bar()
|
||||||
|
var fill_style = _enemy_instance.get_node("ProgressBar").get_theme_stylebox("fill")
|
||||||
|
assert_eq(fill_style.bg_color, Color(0,0,1), "Must be blue in case of shield")
|
||||||
|
|
||||||
|
#Check character flip
|
||||||
|
func test_character_flips_based_on_movement_direction():
|
||||||
|
var initial_scale = _mock_parent.scale.x
|
||||||
|
_mock_parent.position.x += 10
|
||||||
|
_enemy_instance.move_character(0.1)
|
||||||
|
assert_gt(_mock_parent.scale.x, 0, "Positive scaling when moving to the right")
|
||||||
|
_mock_parent.position.x -= 20
|
||||||
|
_enemy_instance.move_character(0.1)
|
||||||
|
assert_lt(_mock_parent.scale.x, 0, "Negative scaling when moving left")
|
||||||
|
Reference in New Issue
Block a user