-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.gd
46 lines (34 loc) · 880 Bytes
/
player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
extends KinematicBody2D
const SPEED = 240
const GRAVITY = 10
const JUMP_POWER = -480
const FLOOR = Vector2(0,-1)
var velocity = Vector2()
var on_ground = false
func _physics_process(delta):
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = true
else:
velocity.x = 0
if on_ground == true:
$AnimatedSprite.play("idle")
if Input.is_action_pressed("ui_up"):
if on_ground == true:
velocity.y = JUMP_POWER
on_ground = false
velocity.y += GRAVITY
if is_on_floor():
on_ground = true
else:
on_ground = false
if velocity.y < 0:
$AnimatedSprite.play("jump")
else:
$AnimatedSprite.play("idle")
velocity = move_and_slide(velocity,FLOOR)