DuckRun/scenes/Duck/Duck.gd

57 lines
1.2 KiB
GDScript3
Raw Permalink Normal View History

2024-10-01 15:56:30 +02:00
extends CharacterBody2D
const JUMP_VELOCITY = -230.0
signal gameover
@onready var alive = true
2024-10-03 21:12:20 +02:00
var state = "main-menu"
2024-10-01 15:56:30 +02:00
func _ready() -> void:
%Skin.change_to(0)
2024-10-01 15:56:30 +02:00
func die():
print("die")
gameover.emit()
alive = false
func start():
global_position = Vector2(21,91)
velocity = Vector2(0,0)
2024-10-01 15:56:30 +02:00
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 global_position.x < 20 or global_position.y > 100:
2024-10-01 15:56:30 +02:00
if alive:
die()
2024-10-03 21:12:20 +02:00
if $"/root/Global".gamerunning:
state = "game"
if state == "main-menu" :
2024-10-01 15:56:30 +02:00
$AnimationPlayer.play("idle")
2024-10-03 21:12:20 +02:00
elif state == "game":
if not is_on_floor():
$AnimationPlayer.play("fly")
elif not alive:
$AnimationPlayer.play("die")
else:
$AnimationPlayer.play("walk")
2024-10-01 15:56:30 +02:00
2024-10-03 21:12:20 +02:00
func _color_slider_changed(value) -> void:
$EnteConstantSprite/EnteColormask.modulate.h = $"../../Gui/Settings/ColorSlider".value*0.01
2024-10-03 21:12:20 +02:00
func _on_ente_sprite_frame_changed() -> void:
$EnteConstantSprite/EnteColormask.frame = $EnteConstantSprite.frame
$EnteConstantSprite/Skin.frame = $EnteConstantSprite.frame