lepsi ovladani postavy + state debug
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
extends Label
|
||||||
|
|
||||||
|
@onready var statemachine = $"../StateMachine"
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
self.text = str(statemachine.current_state)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://kjmyw7k0wrla
|
||||||
+4
-3
@@ -10,12 +10,13 @@
|
|||||||
position = Vector2(36, 132)
|
position = Vector2(36, 132)
|
||||||
|
|
||||||
[node name="PlayerCamera" type="Camera2D" parent="Player" unique_id=894855924]
|
[node name="PlayerCamera" type="Camera2D" parent="Player" unique_id=894855924]
|
||||||
limit_left = -3
|
limit_left = -15
|
||||||
limit_top = 29
|
limit_top = 29
|
||||||
limit_right = 675
|
limit_right = 663
|
||||||
limit_bottom = 243
|
limit_bottom = 245
|
||||||
|
|
||||||
[node name="Level1" parent="." unique_id=296764534 instance=ExtResource("2_8gbba")]
|
[node name="Level1" parent="." unique_id=296764534 instance=ExtResource("2_8gbba")]
|
||||||
|
position = Vector2(-10, 5)
|
||||||
|
|
||||||
[node name="Parallax" parent="." unique_id=294865399 instance=ExtResource("3_8gbba")]
|
[node name="Parallax" parent="." unique_id=294865399 instance=ExtResource("3_8gbba")]
|
||||||
z_index = -1
|
z_index = -1
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
[node name="Background" type="Parallax2D" parent="." unique_id=1430177573]
|
[node name="Background" type="Parallax2D" parent="." unique_id=1430177573]
|
||||||
scroll_scale = Vector2(0.3, 0)
|
scroll_scale = Vector2(0.3, 0)
|
||||||
repeat_size = Vector2(144, 0)
|
repeat_size = Vector2(144, 0)
|
||||||
|
autoscroll = Vector2(1, 0)
|
||||||
repeat_times = 6
|
repeat_times = 6
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="Background" unique_id=277623484]
|
[node name="Sprite2D" type="Sprite2D" parent="Background" unique_id=277623484]
|
||||||
|
|||||||
+2
-1
@@ -10,7 +10,7 @@ var coyote_timer = 0.0
|
|||||||
var jump_buffer_timer = 0.0
|
var jump_buffer_timer = 0.0
|
||||||
|
|
||||||
@onready var sprite = $Sprite2D
|
@onready var sprite = $Sprite2D
|
||||||
|
@onready var statemachine = $StateMachine
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
@@ -27,3 +27,4 @@ func _physics_process(delta: float) -> void:
|
|||||||
sprite.flip_h = true
|
sprite.flip_h = true
|
||||||
if Input.is_action_pressed("right"):
|
if Input.is_action_pressed("right"):
|
||||||
sprite.flip_h = false
|
sprite.flip_h = false
|
||||||
|
print(statemachine.current_state)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
[ext_resource type="Texture2D" uid="uid://j7wi6lleeuhs" path="res://Assets/herochar sprites(new)/herochar_jump_up_anim_strip_3.png" id="4_tx1dd"]
|
[ext_resource type="Texture2D" uid="uid://j7wi6lleeuhs" path="res://Assets/herochar sprites(new)/herochar_jump_up_anim_strip_3.png" id="4_tx1dd"]
|
||||||
[ext_resource type="Script" uid="uid://cs4hwvx5e2aag" path="res://Scenes/states/jump.gd" id="5_jump"]
|
[ext_resource type="Script" uid="uid://cs4hwvx5e2aag" path="res://Scenes/states/jump.gd" id="5_jump"]
|
||||||
[ext_resource type="Script" uid="uid://bojgwc2h0yevj" path="res://Scenes/states/fall.gd" id="10_tx1dd"]
|
[ext_resource type="Script" uid="uid://bojgwc2h0yevj" path="res://Scenes/states/fall.gd" id="10_tx1dd"]
|
||||||
|
[ext_resource type="Script" uid="uid://kjmyw7k0wrla" path="res://Scenes/label.gd" id="11_gymyn"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qqcod"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_qqcod"]
|
||||||
atlas = ExtResource("2_f1ek2")
|
atlas = ExtResource("2_f1ek2")
|
||||||
@@ -178,3 +179,11 @@ script = ExtResource("5_jump")
|
|||||||
|
|
||||||
[node name="Fall" type="Node" parent="StateMachine" unique_id=1119815676]
|
[node name="Fall" type="Node" parent="StateMachine" unique_id=1119815676]
|
||||||
script = ExtResource("10_tx1dd")
|
script = ExtResource("10_tx1dd")
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="." unique_id=1537806562]
|
||||||
|
offset_left = -19.0
|
||||||
|
offset_top = -31.0
|
||||||
|
offset_right = 21.0
|
||||||
|
offset_bottom = -8.0
|
||||||
|
text = "State"
|
||||||
|
script = ExtResource("11_gymyn")
|
||||||
|
|||||||
@@ -16,3 +16,6 @@ func physics_update(delta: float) -> void:
|
|||||||
|
|
||||||
if player.velocity.y > 0:
|
if player.velocity.y > 0:
|
||||||
state_machine.transition_to("Fall")
|
state_machine.transition_to("Fall")
|
||||||
|
|
||||||
|
func exit() -> void:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -7,15 +7,17 @@ func physics_update(delta: float) -> void:
|
|||||||
|
|
||||||
var direction := Input.get_axis("left", "right")
|
var direction := Input.get_axis("left", "right")
|
||||||
if direction:
|
if direction:
|
||||||
player.velocity.x = move_toward(player.velocity.x, direction * player.SPEED, player.SPEED * 5 * delta)
|
player.velocity.x = move_toward(player.velocity.x, direction * player.SPEED, player.SPEED * 15 * delta)
|
||||||
#player.velocity.x = direction * player.SPEED
|
#player.velocity.x = direction * player.SPEED
|
||||||
else:
|
else:
|
||||||
player.velocity.x = move_toward(player.velocity.x, 0, player.SPEED * 10 * delta) # Decelerate to a stop
|
player.velocity.x = move_toward(player.velocity.x, 0, player.SPEED * 5 * delta) # Decelerate to a stop
|
||||||
player.move_and_slide()
|
player.move_and_slide()
|
||||||
player.sprite.play("run")
|
player.sprite.play("run")
|
||||||
|
|
||||||
if player.jump_buffer_timer > 0:
|
if player.jump_buffer_timer > 0:
|
||||||
if player.is_on_floor() or player.coyote_timer > 0:
|
if player.is_on_floor() or player.coyote_timer > 0:
|
||||||
state_machine.transition_to("Jump")
|
state_machine.transition_to("Jump")
|
||||||
elif direction == 0:
|
elif not player.is_on_floor() and player.velocity.y > 0:
|
||||||
|
state_machine.transition_to("Fall")
|
||||||
|
elif player.velocity.x == 0:
|
||||||
state_machine.transition_to("Idle")
|
state_machine.transition_to("Idle")
|
||||||
|
|||||||
Reference in New Issue
Block a user