27 lines
598 B
GDScript3
27 lines
598 B
GDScript3
|
extends CharacterBody2D
|
||
|
|
||
|
const GRAVITY : int = 1000
|
||
|
const MAX_VELOCITY : int = 600
|
||
|
const FLAP_SPEED : int = -500
|
||
|
|
||
|
# Called when the node enters the scene tree for the first time.
|
||
|
func _ready():
|
||
|
pass # Replace with function body.
|
||
|
|
||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||
|
func _process(delta):
|
||
|
pass
|
||
|
|
||
|
func _input(event):
|
||
|
if event.is_action_pressed("jump"):
|
||
|
flap()
|
||
|
|
||
|
func _physics_process(delta):
|
||
|
velocity.y += GRAVITY * delta
|
||
|
if velocity.y > MAX_VELOCITY:
|
||
|
velocity.y = MAX_VELOCITY
|
||
|
move_and_collide(velocity * delta)
|
||
|
|
||
|
func flap():
|
||
|
velocity.y = FLAP_SPEED
|