42 lines
855 B
GDScript
42 lines
855 B
GDScript
extends CharacterBody2D
|
|
|
|
|
|
const JUMP_VELOCITY = -230.0
|
|
signal gameover
|
|
|
|
@onready var alive = true
|
|
|
|
func die():
|
|
print("die")
|
|
gameover.emit()
|
|
alive = false
|
|
|
|
func start():
|
|
global_position = Vector2(21,91)
|
|
alive = true
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if not is_on_floor():
|
|
velocity += get_gravity() * delta
|
|
|
|
if Input.is_action_pressed("jump") and is_on_floor() and alive and $"/root/Global".gamerunning:
|
|
velocity.y = JUMP_VELOCITY
|
|
move_and_slide()
|
|
|
|
func _process(_delta: float) -> void:
|
|
if position.x < -20:
|
|
if alive:
|
|
die()
|
|
if not $"/root/Global".gamerunning:
|
|
$AnimationPlayer.play("idle")
|
|
elif not is_on_floor():
|
|
$AnimationPlayer.play("fly")
|
|
elif not alive:
|
|
$AnimationPlayer.play("die")
|
|
else:
|
|
$AnimationPlayer.play("walk")
|
|
|
|
func _collide_with_hindernis(_body: Node2D) -> void:
|
|
print("colide")
|
|
if alive:
|
|
die()
|