35 lines
742 B
GDScript
35 lines
742 B
GDScript
extends KinematicBody2D
|
|
|
|
const UP = Vector2(0, -1)
|
|
const GRAVITY = 20
|
|
const SPEED = 200
|
|
const JUMP_HEIGHT = -550
|
|
|
|
var motion = Vector2()
|
|
|
|
func _physics_process(delta):
|
|
motion.y += GRAVITY
|
|
if Input.is_action_pressed("ui_right"):
|
|
$Sprite.flip_h = false
|
|
motion.x = SPEED
|
|
elif Input.is_action_pressed("right"):
|
|
$Sprite.flip_h = false
|
|
motion.x = SPEED
|
|
elif Input.is_action_pressed("ui_left"):
|
|
$Sprite.flip_h = true
|
|
motion.x = -SPEED
|
|
elif Input.is_action_pressed("left"):
|
|
$Sprite.flip_h = true
|
|
motion.x = -SPEED
|
|
else:
|
|
motion.x = 0
|
|
if is_on_floor():
|
|
if Input.is_action_pressed("ui_up"):
|
|
motion.y = JUMP_HEIGHT
|
|
elif Input.is_action_pressed("up"):
|
|
motion.y = JUMP_HEIGHT
|
|
|
|
|
|
motion = move_and_slide(motion, UP)
|
|
pass
|