Debug Textbox that shows current State

This commit is contained in:
Jakob Feldmann 2021-03-19 17:21:30 +01:00
parent 67f2466f8c
commit edc8a4d16f
5 changed files with 76 additions and 48 deletions

View File

@ -2,6 +2,7 @@ extends Actor
export var stomp_impulse := 1000.0 export var stomp_impulse := 1000.0
# TODO Move events to StateMachine # TODO Move events to StateMachine
func _on_EnemyDetector_area_entered(area: Area2D) -> void: func _on_EnemyDetector_area_entered(area: Area2D) -> void:
_velocity = calculate_stomp_velocity(_velocity, stomp_impulse) _velocity = calculate_stomp_velocity(_velocity, stomp_impulse)
@ -35,10 +36,7 @@ func apply_gravity(delta, velocity:Vector2):
func calculate_move_velocity( func calculate_move_velocity(
linear_velocity: Vector2, linear_velocity: Vector2, speed: Vector2, direction: Vector2, is_jump_interrupted: bool
speed: Vector2,
direction: Vector2,
is_jump_interrupted: bool
) -> Vector2: ) -> Vector2:
var out := linear_velocity var out := linear_velocity
out.x = speed.x * direction.x out.x = speed.x * direction.x
@ -59,4 +57,3 @@ func calculate_stomp_velocity(linear_velocity: Vector2, impulse: float) -> Vecto
func die() -> void: func die() -> void:
queue_free() queue_free()
PlayerData.deaths += 1 PlayerData.deaths += 1

View File

@ -16,12 +16,13 @@ extents = Vector2( 30.9321, 24.5597 )
collision_mask = 8 collision_mask = 8
script = ExtResource( 5 ) script = ExtResource( 5 )
[node name="player" type="Sprite" parent="."] [node name="Player" type="Sprite" parent="."]
position = Vector2( 1.79366e-43, 5.72205e-06 ) position = Vector2( 0, -32 )
scale = Vector2( 0.64, 0.64 ) scale = Vector2( 0.64, 0.64 )
texture = ExtResource( 1 ) texture = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, -32.2102 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="RayCaster" type="Node2D" parent="CollisionShape2D"] [node name="RayCaster" type="Node2D" parent="CollisionShape2D"]
@ -49,9 +50,22 @@ collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyDetector"] [node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyDetector"]
modulate = Color( 0.2, 0, 0.494118, 1 ) modulate = Color( 0.2, 0, 0.494118, 1 )
position = Vector2( 0, -32.2102 )
shape = SubResource( 2 ) shape = SubResource( 2 )
[node name="StateMachine" type="Node" parent="."] [node name="StateMachine" type="Node" parent="."]
script = ExtResource( 2 ) script = ExtResource( 2 )
[node name="StateLable" type="Label" parent="."]
margin_left = -31.0
margin_top = -80.0
margin_right = 31.0
margin_bottom = -64.0
text = "Coochie"
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="area_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_area_entered"] [connection signal="area_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_area_entered"]
[connection signal="body_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_body_entered"] [connection signal="body_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_body_entered"]

View File

@ -1,5 +1,6 @@
extends StateMachine extends StateMachine
# Adds the intial states # Adds the intial states
func _ready(): func _ready():
add_state("idle") add_state("idle")
@ -7,18 +8,34 @@ func _ready():
add_state("jump") add_state("jump")
add_state("fall") add_state("fall")
print_debug(states) print_debug(states)
set_state(states.idle); set_state(states.idle)
# Calls the parent behaviours according to state # Calls the parent behaviours according to state
func _state_logic(delta): func _state_logic(delta):
parent.get_node("CollisionShape2D/RayCaster")._raycast(Vector2.DOWN, parent.get_node("CollisionShape2D").get_shape(), parent.collision_mask) # RayCasts for visual debugging
# TODO Global context switch for debug/build mode
# \ is for new line in multiline statements
parent.get_node("CollisionShape2D/RayCaster")._raycast(
Vector2.DOWN,
parent.get_node("CollisionShape2D").get_shape(),
parent.collision_mask
)
match self.state:
"idle":
parent.apply_movement(delta)
"run":
parent.apply_movement(delta)
"jump":
parent.apply_movement(delta)
"fall":
parent.apply_movement(delta) parent.apply_movement(delta)
# Determines which state should be active at the moment # Determines which state should be active at the moment
func _get_transition(delta): func _get_transition(delta):
parent.get_node("StateLable").text = self.state
return null return null