-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.gd
46 lines (36 loc) · 1.01 KB
/
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 = 100
const gravity = 10
const jumppower = -250
const ground = Vector2(0, -1)
var velocity = Vector2()
var onground = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _physics_process(delta):
if Input.is_action_pressed("ui_right"):
if is_on_floor() == true:
$AnimatedSprite.play("right")
velocity.x = speed
if sign($Position2D.position.x) == -1:
$Position2D.position.x *= -1
elif Input.is_action_pressed("ui_left"):
if is_on_floor() == true:
$AnimatedSprite.play("left")
velocity.x = -speed
if sign($Position2D.position.x) == 1:
$Position2D.position.x *= -1
else:
velocity.x = 0
if onground == true:
$AnimatedSprite.play("idle")
if Input.is_action_pressed("ui_up") and onground == true:
velocity.y = jumppower
onground = false
velocity.y += gravity
velocity = move_and_slide(velocity, ground)
if is_on_floor():
onground = true
else:
onground = false