From 8164b47301ec822dc285e6a20f8be086486ad0ea Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Mon, 20 Apr 2020 21:09:13 +0200 Subject: [PATCH] Fixed StateBug --- src/Boss/SlimeBoss/SlimeBoss.tscn | 97 ++++++++++----------- src/Boss/SlimeBoss/SlimeBossStateMachine.gd | 60 ++----------- src/Overlap/StateMachine/SequenceState.gd | 1 - src/Player/Player.tscn | 2 +- src/World.tscn | 2 +- 5 files changed, 57 insertions(+), 105 deletions(-) diff --git a/src/Boss/SlimeBoss/SlimeBoss.tscn b/src/Boss/SlimeBoss/SlimeBoss.tscn index 18ce780..a7624fb 100644 --- a/src/Boss/SlimeBoss/SlimeBoss.tscn +++ b/src/Boss/SlimeBoss/SlimeBoss.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=37 format=2] +[gd_scene load_steps=35 format=2] [ext_resource path="res://Overlap/HurtHit_Box/Hurtbox.tscn" type="PackedScene" id=1] [ext_resource path="res://Overlap/HurtHit_Box/Hitbox.tscn" type="PackedScene" id=2] @@ -13,7 +13,6 @@ [ext_resource path="res://Boss/SlimeBoss/Animations/move_up.png" type="Texture" id=11] [ext_resource path="res://Boss/SlimeBoss/States/Roam/MoveToRandomPosition.gd" type="Script" id=12] [ext_resource path="res://Overlap/Kind.tscn" type="PackedScene" id=13] -[ext_resource path="res://Boss/SlimeBoss/HeroCloseZone.gd" type="Script" id=14] [ext_resource path="res://Overlap/StateMachine/SequenceState.gd" type="Script" id=15] [ext_resource path="res://Boss/SlimeBoss/States/Charge/Prepare.gd" type="Script" id=16] [ext_resource path="res://Boss/SlimeBoss/States/Charge/Sprint.gd" type="Script" id=17] @@ -22,23 +21,23 @@ [ext_resource path="res://Boss/SlimeBoss/States/Stomp.gd" type="Script" id=20] [ext_resource path="res://Effects/Stomp/StompEffect.tscn" type="PackedScene" id=21] -[sub_resource type="CircleShape2D" id=1] -radius = 60.0 +[sub_resource type="CapsuleShape2D" id=15] +radius = 30.0 +height = 50.0 -[sub_resource type="CircleShape2D" id=17] -radius = 16.0312 +[sub_resource type="CapsuleShape2D" id=16] +radius = 13.0 +height = 30.0 -[sub_resource type="CircleShape2D" id=16] -radius = 24.0208 +[sub_resource type="CapsuleShape2D" id=17] +radius = 15.0 +height = 35.0 -[sub_resource type="CircleShape2D" id=4] -radius = 150.0 - -[sub_resource type="CapsuleShape2D" id=5] +[sub_resource type="CapsuleShape2D" id=4] radius = 8.0 height = 32.0 -[sub_resource type="Animation" id=6] +[sub_resource type="Animation" id=5] length = 0.45 step = 0.025 tracks/0/type = "value" @@ -114,7 +113,7 @@ tracks/5/keys = { "values": [ 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1 ] } -[sub_resource type="Animation" id=7] +[sub_resource type="Animation" id=6] length = 0.45 step = 0.025 tracks/0/type = "value" @@ -190,7 +189,7 @@ tracks/5/keys = { "values": [ 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1 ] } -[sub_resource type="Animation" id=8] +[sub_resource type="Animation" id=7] length = 0.45 step = 0.025 tracks/0/type = "value" @@ -266,7 +265,7 @@ tracks/5/keys = { "values": [ 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1 ] } -[sub_resource type="Animation" id=9] +[sub_resource type="Animation" id=8] length = 0.45 step = 0.025 tracks/0/type = "value" @@ -342,7 +341,7 @@ tracks/5/keys = { "values": [ 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1 ] } -[sub_resource type="Animation" id=10] +[sub_resource type="Animation" id=9] length = 1.9 step = 0.025 tracks/0/type = "value" @@ -418,7 +417,7 @@ tracks/5/keys = { "values": [ 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ] } -[sub_resource type="Animation" id=11] +[sub_resource type="Animation" id=10] length = 1.9 step = 0.025 tracks/0/type = "value" @@ -494,7 +493,7 @@ tracks/5/keys = { "values": [ 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ] } -[sub_resource type="Animation" id=12] +[sub_resource type="Animation" id=11] length = 2.66666 step = 0.0111111 tracks/0/type = "value" @@ -570,7 +569,7 @@ tracks/5/keys = { "values": [ false ] } -[sub_resource type="Animation" id=13] +[sub_resource type="Animation" id=12] length = 1.28333 step = 0.0166667 tracks/0/type = "value" @@ -646,7 +645,7 @@ tracks/5/keys = { "values": [ true ] } -[sub_resource type="Animation" id=14] +[sub_resource type="Animation" id=13] length = 1.28333 step = 0.0166667 tracks/0/type = "value" @@ -722,7 +721,7 @@ tracks/5/keys = { "values": [ false ] } -[sub_resource type="Animation" id=15] +[sub_resource type="Animation" id=14] length = 1.28333 step = 0.0166667 tracks/0/type = "value" @@ -815,7 +814,7 @@ position = Vector2( 0, -8 ) emitting = false [node name="StompEffect" parent="Effects" instance=ExtResource( 21 )] -visible = false +frame = 29 [node name="Stats" parent="." instance=ExtResource( 3 )] max_health = 3 @@ -867,44 +866,40 @@ script = ExtResource( 19 ) script = ExtResource( 20 ) [node name="Sprite" type="Sprite" parent="."] -position = Vector2( 5, -28 ) -texture = ExtResource( 6 ) -flip_h = true -vframes = 7 -hframes = 11 +position = Vector2( 0, -28 ) +texture = ExtResource( 5 ) +vframes = 10 +hframes = 24 [node name="StompHitbox" parent="." instance=ExtResource( 2 )] [node name="CollisionShape2D" parent="StompHitbox" index="0"] -shape = SubResource( 1 ) +position = Vector2( 0, 10 ) +rotation = 1.5708 +shape = SubResource( 15 ) disabled = true [node name="Hitbox" parent="." instance=ExtResource( 2 )] collision_layer = 4 [node name="CollisionShape2D" parent="Hitbox" index="0"] -position = Vector2( 0, -15 ) -shape = SubResource( 17 ) +position = Vector2( 0, -5 ) +rotation = 1.5708 +shape = SubResource( 16 ) [node name="Hurtbox" parent="." instance=ExtResource( 1 )] collision_layer = 4 collision_mask = 0 [node name="CollisionShape2D" parent="Hurtbox" index="0"] -position = Vector2( 0, -15 ) -shape = SubResource( 16 ) - -[node name="HeroCloseZone" type="Area2D" parent="."] -collision_layer = 0 -script = ExtResource( 14 ) - -[node name="CollisionShape2D" type="CollisionShape2D" parent="HeroCloseZone"] -shape = SubResource( 4 ) +position = Vector2( 0, -5 ) +rotation = 1.5708 +shape = SubResource( 17 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2( -1.52588e-05, 0 ) rotation = 1.5708 -shape = SubResource( 5 ) +shape = SubResource( 4 ) [node name="DebugLabel" type="Label" parent="."] visible = false @@ -919,16 +914,16 @@ __meta__ = { [node name="AnimationPlayer" type="AnimationPlayer" parent="."] autoplay = "MoveRight" -anims/ChargeDown = SubResource( 6 ) -anims/ChargeLeft = SubResource( 7 ) -anims/ChargeRight = SubResource( 8 ) -anims/ChargeUp = SubResource( 9 ) -anims/Charging = SubResource( 10 ) -anims/FightStart = SubResource( 11 ) -anims/MoveDown = SubResource( 12 ) -anims/MoveLeft = SubResource( 13 ) -anims/MoveRight = SubResource( 14 ) -anims/MoveUp = SubResource( 15 ) +anims/ChargeDown = SubResource( 5 ) +anims/ChargeLeft = SubResource( 6 ) +anims/ChargeRight = SubResource( 7 ) +anims/ChargeUp = SubResource( 8 ) +anims/Charging = SubResource( 9 ) +anims/FightStart = SubResource( 10 ) +anims/MoveDown = SubResource( 11 ) +anims/MoveLeft = SubResource( 12 ) +anims/MoveRight = SubResource( 13 ) +anims/MoveUp = SubResource( 14 ) [connection signal="animation_finished" from="Effects/StompEffect" to="States/Stomp" method="_on_StompEffect_animation_finished"] [connection signal="health_changed" from="Stats" to="." method="_on_Stats_health_changed"] [connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"] diff --git a/src/Boss/SlimeBoss/SlimeBossStateMachine.gd b/src/Boss/SlimeBoss/SlimeBossStateMachine.gd index 8c01e7a..f520e32 100644 --- a/src/Boss/SlimeBoss/SlimeBossStateMachine.gd +++ b/src/Boss/SlimeBoss/SlimeBossStateMachine.gd @@ -51,27 +51,28 @@ func _on_Stats_no_health(): go_to_next_state($States/Die) func _on_Stats_health_changed(new_health): - assert(new_health > -1) - assert(new_health < $Stats.max_health) - if _phase == PHASES.PHASE_ONE and new_health == 2: _change_phase(PHASES.PHASE_TWO) - if _phase == PHASES.PHASE_TWO and new_health == 1: + elif _phase == PHASES.PHASE_TWO and new_health == 1: _change_phase(PHASES.PHASE_THREE) + elif _phase == PHASES.PHASE_THREE and new_health < 1: + queue_free() func go_to_next_state(state_override=null): if state_active: state_active.exit() - if state_override != null: state_active = state_override else: state_active = _decide_on_next_state() + emit_signal("state_changed", state_active.name) + state_active.enter() func _change_phase(new_phase): + set_invincible(true) var phase_name = "" match new_phase: PHASES.PHASE_ONE: @@ -96,7 +97,6 @@ func _decide_on_next_state(): set_invincible(true) return $States/FightStart if state_active == $States/FightStart: - set_invincible(false) return $States/ChargeSequence if _phase == PHASES.PHASE_ONE: @@ -129,6 +129,7 @@ func _decide_on_next_state(): if state_active == $States/Stomp: sequence_cycles += 1 return $States/ChargeSequence + return $States/ChargeSequence else: angry_phases_done = 2 sequence_cycles = 0 @@ -153,6 +154,7 @@ func _decide_on_next_state(): if state_active == $States/Stomp: sequence_cycles += 1 return $States/ChargeSequence + return $States/ChargeSequence else: angry_phases_done = 3 sequence_cycles = 0 @@ -173,51 +175,7 @@ func _decide_on_next_state(): # queue_free() # return $States/Dead # -# # PHASE ONE -# if _phase == PHASES.PHASE_ONE: -# if state_active == $States/RoamSequence: -# sequence_cycles += 1 -# if sequence_cycles < 2: -# return $States/RoamSequence -# else: -# sequence_cycles = 0 -# return $States/Stomp -# if state_active == $States/Stomp: -# return $States/RoamSequence -# -# # PHASE TWO -# elif _phase == PHASES.PHASE_TWO: -# if state_active == $States/RoamSequence: -# return $States/Stomp -# if state_active == $States/Stomp: -# if sequence_cycles < 2: -# sequence_cycles += 1 -# return $States/Stomp -# else: -# sequence_cycles = 0 -# return $States/ChargeSequence -# if state_active == $States/ChargeSequence: -# return $States/RoamSequence -# -# -# # PHASE THREE -# elif _phase == PHASES.PHASE_THREE: -# if state_active == $States/RoamSequence: -# return $States/Stomp -# if state_active == $States/Stomp: -# if sequence_cycles < 2: -# sequence_cycles += 1 -# return $States/Stomp -# else: -# sequence_cycles = 0 -# return $States/ChargeSequence -# if state_active == $States/ChargeSequence: -# if sequence_cycles < 2: -# sequence_cycles += 1 -# return $States/ChargeSequence -# else: -# sequence_cycles = 0 -# return $States/Stomp + func set_invincible(value): diff --git a/src/Overlap/StateMachine/SequenceState.gd b/src/Overlap/StateMachine/SequenceState.gd index e9e68e7..37cb924 100644 --- a/src/Overlap/StateMachine/SequenceState.gd +++ b/src/Overlap/StateMachine/SequenceState.gd @@ -31,7 +31,6 @@ func _on_state_active_finished(): func go_to_next_state_in_sequence(): state_active.exit() - var new_state_index = (state_active.get_index() + 1) % get_child_count() if new_state_index == 0: emit_signal('finished') diff --git a/src/Player/Player.tscn b/src/Player/Player.tscn index be52078..44c99d4 100644 --- a/src/Player/Player.tscn +++ b/src/Player/Player.tscn @@ -736,7 +736,7 @@ __meta__ = { } [node name="Stats" parent="." instance=ExtResource( 5 )] -max_health = 5 +max_health = 999999 [node name="AnimationStates" type="Node" parent="."] script = ExtResource( 15 ) diff --git a/src/World.tscn b/src/World.tscn index 8603521..ad9ba6b 100644 --- a/src/World.tscn +++ b/src/World.tscn @@ -23,7 +23,7 @@ region_enabled = true region_rect = Rect2( 0, 0, 1280, 720 ) [node name="Background" parent="." instance=ExtResource( 7 )] -frame = 14 +frame = 12 [node name="FloorTileMap" type="TileMap" parent="."] visible = false