debug / stages / basic / basic.tscn
Diagram
Overridden virtual functions
_input
func _input(event: InputEvent) -> void:
if event is InputEventKey:
var key : InputEventKey = event
if key.is_pressed() and key.keycode == KEY_SPACE:
if player.state == Player.State.LOCKED:
player.unlock()
else:
player.lock()
_ready
func _ready() -> void:
playable = true
turn_right()
if not owner: return
if last_owner_name == owner.name:
position = restart_position
else:
restart_position = position
last_owner_name = owner.name
_physics_process
func _physics_process(delta: float) -> void:
var dx := Input.get_axis(&'move_left', &'move_right')
var dy := Input.get_axis(&'move_up', &'move_down')
var direction := Vector2(dx, dy)
var last_state := state
state = compute_state(delta, direction)
match state:
State.CLIMBING:
dx = 0
velocity.y = dy * CLIMBING_SPEED
State.DASHED:
velocity = direction.normalized() * DASH_SPEED
State.DASHING:
velocity *= DASH_ATTENUATION * delta
State.EXHAUSTED:
dx = 0
State.FAILED:
velocity.x = lerp(velocity.x, 0.0, 0.2)
velocity.y = lerp(velocity.y, 0.0, 0.2)
State.FALLING:
if last_state == State.CLIMBING \
and dy < 0:
velocity.y = JUMP_VELOCITY * 0.8
else:
var move_x := dx * SPEED * 0.8
if velocity.x * dx < 0: move_x *= 0.1
velocity.x = lerp(velocity.x, move_x, 0.2)
if velocity.y < JUMP_VELOCITY * 0.85:
velocity.y += GRAVITY * 1.15 * delta
else:
velocity.y += GRAVITY * delta
State.JUMPED:
velocity.y = JUMP_VELOCITY
State.KICKED:
velocity.y = JUMP_VELOCITY * 0.9
velocity.x = get_wall_normal().x * DASH_SPEED * 0.4
State.LOCKED:
dx = 0
velocity = Vector2(0, 0)
_: pass
if not playable: dx = 0
if not (state == State.DASHED \
or state == State.DASHING \
or state == State.FALLING \
or state == State.KICKED
):
if dx: velocity.x = dx * SPEED
else: velocity.x = move_toward(velocity.x, 0, SPEED*0.2)
if state == State.JUMPED:
velocity += jump_boost
jump_boost = Vector2(0, 0)
animate(playable)
move_and_slide()
Instantiators
|
Caution
|
No other scene instantiate this scene. |
Scene Tree
-
Basic Control
-
StageGround0 res://src/stages/0/stage_ground_0.tscn
-
Player res://src/player/player.tscn
-
CameraFrame res://src/stages/frame/camera_frame.tscn
-
Signal Connections
|
Note
|
No signal connections. |
Properties
| Name | Value |
|---|---|
layout_mode |
|
anchors_preset |
|
anchor_right |
|
anchor_bottom |
|
grow_horizontal |
|
grow_vertical |
|
script |
| Name | Value |
|---|---|
tile_map_data |
|
| Name | Value |
|---|---|
unique_name_in_owner |
|
position |
|
| Name | Value |
|---|---|
position |
|
basic.gd
extends Control
@onready var player : Player = %Player
func _input(event: InputEvent) -> void:
if event is InputEventKey:
var key : InputEventKey = event
if key.is_pressed() and key.keycode == KEY_SPACE:
if player.state == Player.State.LOCKED:
player.unlock()
else:
player.lock()