diff --git a/src/Actors/Enemies/Vacuum.gd b/src/Actors/Enemies/Vacuum.gd index 53709c0..4b14ce7 100644 --- a/src/Actors/Enemies/Vacuum.gd +++ b/src/Actors/Enemies/Vacuum.gd @@ -11,7 +11,7 @@ func _ready() -> void: # TODO Only moves when on screen -func _physics_process(delta: float) -> void: +func execute_movement(delta: float) -> void: velocity.y += _gravity * delta var player_direction := player_on_floor_direction() if(player_direction != 0): diff --git a/src/Actors/Enemies/Vacuum.tscn b/src/Actors/Enemies/Vacuum.tscn index 8c8c2d6..2692100 100644 --- a/src/Actors/Enemies/Vacuum.tscn +++ b/src/Actors/Enemies/Vacuum.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://assets/enemy/VacuumRobot.png" type="Texture" id=1] [ext_resource path="res://src/Actors/Enemies/Vacuum.gd" type="Script" id=2] +[ext_resource path="res://src/StateMachines/VacuumStateMachine.gd" type="Script" id=3] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 14, 7 ) @@ -14,8 +15,9 @@ extents = Vector2( 15, 6.5 ) [node name="Vacuum" type="KinematicBody2D" groups=["harmful"]] collision_layer = 2 -collision_mask = 9 +collision_mask = 11 script = ExtResource( 2 ) +mass = 1.0 speed = 180 acceleration = 100 @@ -70,6 +72,9 @@ collision_mask = 127 position = Vector2( 0, 5.5 ) shape = SubResource( 3 ) +[node name="StateMachine" type="Node" parent="."] +script = ExtResource( 3 ) + [connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"] [connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"] [connection signal="body_entered" from="EnemySkin" to="." method="_on_EnemySkin_body_entered"] diff --git a/src/StateMachines/VacuumStateMachine.gd b/src/StateMachines/VacuumStateMachine.gd new file mode 100644 index 0000000..5508b74 --- /dev/null +++ b/src/StateMachines/VacuumStateMachine.gd @@ -0,0 +1,32 @@ +extends StateMachine + +func _ready() -> void: + add_state("darting") + state = states.darting + set_state(states.darting) + for state in states: + if state_matching_method_exists(state): + continue + else: + printerr("StateMachine -> State: " + state + " has no matching method in parent.") + push_error("StateMachine -> State: " + state + " has no matching method in parent.") + # _animation_logic() + + +# Game logic consequences of state +func _state_logic(delta): + #var state_action_ref = funcref(parent, self.state) + #parent.velocity = state_action_ref.call_func() + parent.execute_movement(delta) + + +func _get_transition(_delta): + return null + + +func _enter_state(_new_state, _previous_state): + pass + + +func _exit_state(_previous_state, _new_state): + pass