Animation fix and some more tests
This commit is contained in:
@ -40,7 +40,8 @@ func target_reached() -> void:
|
||||
if name.contains("Arrow"): #special effects here!
|
||||
if randf() < 0.1:
|
||||
target.get_parent().set_speed(target.get_parent().get_speed() / 2)
|
||||
pass
|
||||
target.get_parent().adjust_speed_of_animation()
|
||||
pass
|
||||
if name.contains("Magic"):
|
||||
if randf() < 0.5:
|
||||
target.get_parent().set_progress(max(target.get_parent().get_progress() - 60, 0))
|
||||
|
@ -6,6 +6,21 @@
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lj5pp"]
|
||||
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"]
|
||||
resource_name = "rotation"
|
||||
length = 0.5
|
||||
@ -27,21 +42,6 @@ tracks/0/keys = {
|
||||
"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"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_0itbo"),
|
||||
|
@ -105,7 +105,7 @@ animations = [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("21_m5o2x")
|
||||
}],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": &"hurt",
|
||||
"speed": 20.0
|
||||
}, {
|
||||
@ -201,9 +201,8 @@ collision_layer = 3
|
||||
position = Vector2(10, 0)
|
||||
scale = Vector2(0.25, 0.25)
|
||||
sprite_frames = SubResource("SpriteFrames_brd2m")
|
||||
animation = &"hurt"
|
||||
animation = &"walk"
|
||||
autoplay = "walk"
|
||||
frame_progress = 0.66798
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
scale = Vector2(2, 2)
|
||||
|
@ -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()
|
||||
|
@ -108,7 +108,7 @@ animations = [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("21_to6c5")
|
||||
}],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": &"hurt",
|
||||
"speed": 20.0
|
||||
}, {
|
||||
@ -206,10 +206,8 @@ shape = SubResource("CircleShape2D_ra45u")
|
||||
position = Vector2(10, 0)
|
||||
scale = Vector2(0.2, 0.186)
|
||||
sprite_frames = SubResource("SpriteFrames_gxpsl")
|
||||
animation = &"hurt"
|
||||
animation = &"walk"
|
||||
autoplay = "walk"
|
||||
frame = 11
|
||||
frame_progress = 0.9629
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
||||
|
||||
|
@ -105,7 +105,7 @@ animations = [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("21_xh1xf")
|
||||
}],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": &"hurt",
|
||||
"speed": 20.0
|
||||
}, {
|
||||
@ -201,9 +201,8 @@ collision_layer = 3
|
||||
position = Vector2(10, 0)
|
||||
scale = Vector2(0.18, 0.18)
|
||||
sprite_frames = SubResource("SpriteFrames_h86ts")
|
||||
animation = &"hurt"
|
||||
animation = &"walk"
|
||||
autoplay = "walk"
|
||||
frame_progress = 0.748545
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
||||
|
||||
|
Reference in New Issue
Block a user