Debug Textbox that shows current State
This commit is contained in:
parent
67f2466f8c
commit
edc8a4d16f
@ -1,9 +1,9 @@
|
||||
extends KinematicBody2D
|
||||
class_name Actor
|
||||
|
||||
const FLOOR_NORMAL: = Vector2.UP
|
||||
const FLOOR_NORMAL := Vector2.UP
|
||||
|
||||
export var speed: = Vector2(300, 1000)
|
||||
export var gravity: = 9800.0
|
||||
export var speed := Vector2(300, 1000)
|
||||
export var gravity := 9800.0
|
||||
|
||||
var _velocity: = Vector2.ZERO
|
||||
var _velocity := Vector2.ZERO
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
extends Actor
|
||||
|
||||
export var stomp_impulse: = 1000.0
|
||||
export var stomp_impulse := 1000.0
|
||||
|
||||
|
||||
# TODO Move events to StateMachine
|
||||
func _on_EnemyDetector_area_entered(area: Area2D) -> void:
|
||||
@ -12,8 +13,8 @@ func _on_EnemyDetector_body_entered(body: Node) -> void:
|
||||
|
||||
|
||||
func apply_movement(delta: float) -> void:
|
||||
var is_jump_interrupted: = Input.is_action_just_released("jump") and _velocity.y < 0.0
|
||||
var direction: = get_direction()
|
||||
var is_jump_interrupted := Input.is_action_just_released("jump") and _velocity.y < 0.0
|
||||
var direction := get_direction()
|
||||
_velocity = calculate_move_velocity(_velocity, speed, direction, is_jump_interrupted)
|
||||
_velocity = move_and_slide(_velocity, FLOOR_NORMAL)
|
||||
|
||||
@ -29,18 +30,15 @@ func handle_move_input():
|
||||
return null
|
||||
|
||||
|
||||
func apply_gravity(delta, velocity:Vector2):
|
||||
func apply_gravity(delta, velocity: Vector2):
|
||||
velocity.y += gravity * delta
|
||||
return velocity
|
||||
|
||||
|
||||
func calculate_move_velocity(
|
||||
linear_velocity: Vector2,
|
||||
speed: Vector2,
|
||||
direction: Vector2,
|
||||
is_jump_interrupted: bool
|
||||
) -> Vector2:
|
||||
var out: = linear_velocity
|
||||
linear_velocity: Vector2, speed: Vector2, direction: Vector2, is_jump_interrupted: bool
|
||||
) -> Vector2:
|
||||
var out := linear_velocity
|
||||
out.x = speed.x * direction.x
|
||||
out = apply_gravity(get_physics_process_delta_time(), out)
|
||||
if direction.y == -1:
|
||||
@ -51,7 +49,7 @@ func calculate_move_velocity(
|
||||
|
||||
|
||||
func calculate_stomp_velocity(linear_velocity: Vector2, impulse: float) -> Vector2:
|
||||
var out: = linear_velocity
|
||||
var out := linear_velocity
|
||||
out.y = -impulse
|
||||
return out
|
||||
|
||||
@ -59,4 +57,3 @@ func calculate_stomp_velocity(linear_velocity: Vector2, impulse: float) -> Vecto
|
||||
func die() -> void:
|
||||
queue_free()
|
||||
PlayerData.deaths += 1
|
||||
|
||||
|
||||
@ -16,12 +16,13 @@ extents = Vector2( 30.9321, 24.5597 )
|
||||
collision_mask = 8
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="player" type="Sprite" parent="."]
|
||||
position = Vector2( 1.79366e-43, 5.72205e-06 )
|
||||
[node name="Player" type="Sprite" parent="."]
|
||||
position = Vector2( 0, -32 )
|
||||
scale = Vector2( 0.64, 0.64 )
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2( 0, -32.2102 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="RayCaster" type="Node2D" parent="CollisionShape2D"]
|
||||
@ -49,9 +50,22 @@ collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyDetector"]
|
||||
modulate = Color( 0.2, 0, 0.494118, 1 )
|
||||
position = Vector2( 0, -32.2102 )
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[node name="StateMachine" type="Node" parent="."]
|
||||
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="body_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_body_entered"]
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
extends StateMachine
|
||||
|
||||
|
||||
# Adds the intial states
|
||||
func _ready():
|
||||
add_state("idle")
|
||||
@ -7,18 +8,34 @@ func _ready():
|
||||
add_state("jump")
|
||||
add_state("fall")
|
||||
print_debug(states)
|
||||
set_state(states.idle);
|
||||
set_state(states.idle)
|
||||
|
||||
|
||||
# Calls the parent behaviours according to state
|
||||
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)
|
||||
|
||||
|
||||
# Determines which state should be active at the moment
|
||||
func _get_transition(delta):
|
||||
|
||||
parent.get_node("StateLable").text = self.state
|
||||
return null
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user