mirror of
https://github.com/creyD/ludum_dare_46.git
synced 2026-06-14 22:32:24 +02:00
Added states to boss state machine
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
extends KinematicBody2D
|
|
||||||
class_name SlimeBoss
|
|
||||||
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
[gd_scene load_steps=18 format=2]
|
[gd_scene load_steps=23 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Overlap/HurtHit_Box/Hurtbox.tscn" type="PackedScene" id=1]
|
[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]
|
[ext_resource path="res://Overlap/HurtHit_Box/Hitbox.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://Overlap/Stats/Stats.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://Overlap/Stats/Stats.tscn" type="PackedScene" id=3]
|
||||||
|
[ext_resource path="res://Boss/SlimeBoss/SlimeBossStateMachine.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://Boss/SlimeBoss/Animations/move_down.png" type="Texture" id=5]
|
[ext_resource path="res://Boss/SlimeBoss/Animations/move_down.png" type="Texture" id=5]
|
||||||
[ext_resource path="res://Boss/SlimeBoss/Animations/move_right.png" type="Texture" id=6]
|
[ext_resource path="res://Boss/SlimeBoss/Animations/move_right.png" type="Texture" id=6]
|
||||||
[ext_resource path="res://Boss/SlimeBoss/States/Motion/Idle.gd" type="Script" id=7]
|
[ext_resource path="res://Boss/SlimeBoss/States/Motion/Idle.gd" type="Script" id=7]
|
||||||
@@ -10,6 +11,9 @@
|
|||||||
[ext_resource path="res://Boss/SlimeBoss/States/Motion/Wander.gd" type="Script" id=9]
|
[ext_resource path="res://Boss/SlimeBoss/States/Motion/Wander.gd" type="Script" id=9]
|
||||||
[ext_resource path="res://Boss/SlimeBoss/States/Motion/SplitUp.gd" type="Script" id=10]
|
[ext_resource path="res://Boss/SlimeBoss/States/Motion/SplitUp.gd" type="Script" id=10]
|
||||||
[ext_resource path="res://Boss/SlimeBoss/Animations/move_up.png" type="Texture" id=11]
|
[ext_resource path="res://Boss/SlimeBoss/Animations/move_up.png" type="Texture" id=11]
|
||||||
|
[ext_resource path="res://Boss/SlimeBoss/States/Motion/JumpTeleport.gd" type="Script" id=12]
|
||||||
|
[ext_resource path="res://Boss/SlimeBoss/States/Motion/Dead.gd" type="Script" id=13]
|
||||||
|
[ext_resource path="res://Boss/SlimeBoss/States/Motion/Pursue.gd" type="Script" id=14]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id=1]
|
[sub_resource type="CapsuleShape2D" id=1]
|
||||||
radius = 18.0
|
radius = 18.0
|
||||||
@@ -19,12 +23,14 @@ height = 18.0
|
|||||||
radius = 18.0
|
radius = 18.0
|
||||||
height = 18.0
|
height = 18.0
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id=3]
|
[sub_resource type="CircleShape2D" id=3]
|
||||||
|
radius = 150.0
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id=4]
|
||||||
radius = 8.0
|
radius = 8.0
|
||||||
height = 15.0
|
height = 15.0
|
||||||
|
|
||||||
[sub_resource type="Animation" id=4]
|
[sub_resource type="Animation" id=5]
|
||||||
resource_name = "MoveDown"
|
|
||||||
length = 2.66666
|
length = 2.66666
|
||||||
loop = true
|
loop = true
|
||||||
step = 0.0111111
|
step = 0.0111111
|
||||||
@@ -102,7 +108,6 @@ tracks/5/keys = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=6]
|
[sub_resource type="Animation" id=6]
|
||||||
resource_name = "MoveLeft"
|
|
||||||
length = 1.28333
|
length = 1.28333
|
||||||
loop = true
|
loop = true
|
||||||
step = 0.0166667
|
step = 0.0166667
|
||||||
@@ -179,8 +184,7 @@ tracks/5/keys = {
|
|||||||
"values": [ true ]
|
"values": [ true ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=5]
|
[sub_resource type="Animation" id=7]
|
||||||
resource_name = "MoveRight"
|
|
||||||
length = 1.28333
|
length = 1.28333
|
||||||
loop = true
|
loop = true
|
||||||
step = 0.0166667
|
step = 0.0166667
|
||||||
@@ -257,8 +261,7 @@ tracks/5/keys = {
|
|||||||
"values": [ false ]
|
"values": [ false ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=7]
|
[sub_resource type="Animation" id=8]
|
||||||
resource_name = "MoveUp"
|
|
||||||
length = 1.28333
|
length = 1.28333
|
||||||
loop = true
|
loop = true
|
||||||
step = 0.0166667
|
step = 0.0166667
|
||||||
@@ -324,9 +327,14 @@ tracks/4/keys = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[node name="SlimeBoss" type="KinematicBody2D"]
|
[node name="SlimeBoss" type="KinematicBody2D"]
|
||||||
|
collision_layer = 4
|
||||||
|
collision_mask = 0
|
||||||
|
script = ExtResource( 4 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_group_": true
|
"_edit_group_": true
|
||||||
}
|
}
|
||||||
|
STATES_COLLECTION = NodePath("States")
|
||||||
|
START_STATE = NodePath("States/Idle")
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite" parent="."]
|
[node name="Sprite" type="Sprite" parent="."]
|
||||||
position = Vector2( 0, -20 )
|
position = Vector2( 0, -20 )
|
||||||
@@ -337,7 +345,7 @@ frame = 227
|
|||||||
|
|
||||||
[node name="Hitbox" parent="." instance=ExtResource( 2 )]
|
[node name="Hitbox" parent="." instance=ExtResource( 2 )]
|
||||||
visible = false
|
visible = false
|
||||||
collision_layer = 0
|
collision_layer = 4
|
||||||
|
|
||||||
[node name="CollisionShape2D" parent="Hitbox" index="0"]
|
[node name="CollisionShape2D" parent="Hitbox" index="0"]
|
||||||
position = Vector2( 0, -15 )
|
position = Vector2( 0, -15 )
|
||||||
@@ -351,10 +359,16 @@ collision_mask = 0
|
|||||||
position = Vector2( 0, -15 )
|
position = Vector2( 0, -15 )
|
||||||
shape = SubResource( 2 )
|
shape = SubResource( 2 )
|
||||||
|
|
||||||
|
[node name="HeroCloseZone" type="Area2D" parent="."]
|
||||||
|
collision_layer = 0
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="HeroCloseZone"]
|
||||||
|
shape = SubResource( 3 )
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2( -1.52588e-05, 0 )
|
position = Vector2( -1.52588e-05, 0 )
|
||||||
rotation = 1.5708
|
rotation = 1.5708
|
||||||
shape = SubResource( 3 )
|
shape = SubResource( 4 )
|
||||||
|
|
||||||
[node name="DebugLabel" type="Label" parent="."]
|
[node name="DebugLabel" type="Label" parent="."]
|
||||||
margin_left = -42.2456
|
margin_left = -42.2456
|
||||||
@@ -382,12 +396,22 @@ script = ExtResource( 10 )
|
|||||||
[node name="Stagger" type="Node" parent="States"]
|
[node name="Stagger" type="Node" parent="States"]
|
||||||
script = ExtResource( 8 )
|
script = ExtResource( 8 )
|
||||||
|
|
||||||
|
[node name="JumpTeleport" type="Node" parent="States"]
|
||||||
|
script = ExtResource( 12 )
|
||||||
|
|
||||||
|
[node name="Dead" type="Node" parent="States"]
|
||||||
|
script = ExtResource( 13 )
|
||||||
|
|
||||||
|
[node name="Pursue" type="Node" parent="States"]
|
||||||
|
script = ExtResource( 14 )
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||||
autoplay = "MoveRight"
|
autoplay = "MoveRight"
|
||||||
anims/MoveDown = SubResource( 4 )
|
anims/MoveDown = SubResource( 5 )
|
||||||
anims/MoveLeft = SubResource( 6 )
|
anims/MoveLeft = SubResource( 6 )
|
||||||
anims/MoveRight = SubResource( 5 )
|
anims/MoveRight = SubResource( 7 )
|
||||||
anims/MoveUp = SubResource( 7 )
|
anims/MoveUp = SubResource( 8 )
|
||||||
|
[connection signal="area_entered" from="HeroCloseZone" to="States/Idle" method="hero_close"]
|
||||||
|
|
||||||
[editable path="Hitbox"]
|
[editable path="Hitbox"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,38 @@
|
|||||||
extends "res://Overlap/StateMachine/StateMachine.gd"
|
extends "res://Overlap/StateMachine/StateMachine.gd"
|
||||||
|
|
||||||
|
onready var hero_close_zone = $HeroCloseZone
|
||||||
|
onready var debug_label = $DebugLabel
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
states_map = {
|
states_map = {
|
||||||
"idle": $Idle,
|
"idle": $States/Idle,
|
||||||
"wander": $Wander,
|
"wander": $States/Wander,
|
||||||
"split_up": $SplitUp,
|
"pursue": $States/Pursue,
|
||||||
"stagger": $Stagger
|
"split_up": $States/SplitUp,
|
||||||
|
"stagger": $States/Stagger,
|
||||||
|
"jump_teleport": $States/JumpTeleport,
|
||||||
|
"dead": $States/Dead
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug_label.text = "IDLE"
|
||||||
|
|
||||||
|
func change_state(state_name):
|
||||||
|
current_state.exit()
|
||||||
|
debug_label.text = state_name.to_upper()
|
||||||
|
|
||||||
|
if state_name == "previous":
|
||||||
|
states_stack.pop_front()
|
||||||
|
elif state_name in ["stagger"]:
|
||||||
|
states_stack.push_front(states_map[state_name])
|
||||||
|
elif state_name == "dead":
|
||||||
|
queue_free()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
var new_state = states_map[state_name]
|
||||||
|
states_stack[0] = new_state
|
||||||
|
|
||||||
|
current_state = states_stack[0]
|
||||||
|
if state_name != "previous":
|
||||||
|
# We don"t want to reinitialize the state if we"re going back to the previous state
|
||||||
|
current_state.enter()
|
||||||
|
emit_signal("state_changed", states_stack)
|
||||||
|
|||||||
4
src/Boss/SlimeBoss/States/Motion/Dead.gd
Normal file
4
src/Boss/SlimeBoss/States/Motion/Dead.gd
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
extends "res://Overlap/StateMachine/State.gd"
|
||||||
|
|
||||||
|
func enter():
|
||||||
|
print("dead state")
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
extends "res://Overlap/StateMachine/MotionState.gd"
|
extends "res://Overlap/StateMachine/State.gd"
|
||||||
|
|
||||||
func enter():
|
func enter():
|
||||||
owner.get_node("AnimationPlayer").play("MoveDown") # TODO: Replace animation
|
owner.get_node("AnimationPlayer").play("MoveDown")
|
||||||
|
|
||||||
func handle_input(event):
|
func hero_close(area):
|
||||||
return .handle_input(event)
|
emit_signal("finished", "pursue")
|
||||||
|
|
||||||
func update(delta):
|
|
||||||
var input_direction = get_input_direction()
|
|
||||||
if input_direction:
|
|
||||||
# emit_signal("finished", "move")
|
|
||||||
pass
|
|
||||||
|
|||||||
4
src/Boss/SlimeBoss/States/Motion/JumpTeleport.gd
Normal file
4
src/Boss/SlimeBoss/States/Motion/JumpTeleport.gd
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
extends "res://Overlap/StateMachine/State.gd"
|
||||||
|
|
||||||
|
func enter():
|
||||||
|
print("jump teleport state")
|
||||||
4
src/Boss/SlimeBoss/States/Motion/Pursue.gd
Normal file
4
src/Boss/SlimeBoss/States/Motion/Pursue.gd
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
extends "res://Overlap/StateMachine/State.gd"
|
||||||
|
|
||||||
|
func enter():
|
||||||
|
print("pursue state")
|
||||||
@@ -1,16 +1,4 @@
|
|||||||
extends Node
|
extends "res://Overlap/StateMachine/State.gd"
|
||||||
|
|
||||||
|
func enter():
|
||||||
# Declare member variables here. Examples:
|
print("split up state")
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
extends Node
|
extends "res://Overlap/StateMachine/State.gd"
|
||||||
|
|
||||||
|
func enter():
|
||||||
# Declare member variables here. Examples:
|
print("stagger state")
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
extends Node
|
extends "res://Overlap/StateMachine/State.gd"
|
||||||
|
|
||||||
|
func enter():
|
||||||
# Declare member variables here. Examples:
|
print("wander state")
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
|
||||||
|
|||||||
Reference in New Issue
Block a user