42 lines
988 B
GDScript3
42 lines
988 B
GDScript3
![]() |
extends CharacterBody2D
|
||
|
|
||
|
|
||
|
const SPEED: int = 200
|
||
|
const JUMP_VELOCITY: int = -300
|
||
|
|
||
|
|
||
|
func _physics_process(delta: float) -> void:
|
||
|
# Add the gravity.
|
||
|
if not is_on_floor():
|
||
|
velocity += get_gravity() * delta
|
||
|
|
||
|
# Handle jump.
|
||
|
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||
|
velocity.y = JUMP_VELOCITY
|
||
|
$boing.play()
|
||
|
|
||
|
# Get the input direction and handle the movement/deceleration.
|
||
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
||
|
var direction: float = Input.get_axis("ui_left", "ui_right")
|
||
|
velocity.x = direction * SPEED
|
||
|
|
||
|
if $death.playing:
|
||
|
velocity = Vector2(0, 0)
|
||
|
|
||
|
move_and_slide()
|
||
|
|
||
|
for i in get_slide_collision_count():
|
||
|
if get_slide_collision(i).get_collider() == $"../TileMapLayer2" and not $death.playing:
|
||
|
$death.play()
|
||
|
|
||
|
|
||
|
func _on_player_entered(body: Node2D) -> void:
|
||
|
if body == self:
|
||
|
$rice.play()
|
||
|
await $rice.finished
|
||
|
get_tree().quit()
|
||
|
|
||
|
|
||
|
func _on_death_finished() -> void:
|
||
|
get_tree().reload_current_scene()
|