-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.gd
47 lines (36 loc) · 947 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
47
extends KinematicBody2D
var direction = 0
var velocity: = Vector2()
const SPEED = 400
const GRAVITY = 100
const JUMP = 1200
func _ready():
pass
func _process(_delta):
if Input.is_action_pressed("ui_right"):
direction = 1
elif Input.is_action_pressed("ui_left"):
direction = -1
else:
direction = 0
if Input.is_action_just_pressed("ui_select"):
if.is_on_floor():
velocity.y += -JUMP
velocity.y += GRAVITY
velocity.x = direction * SPEED
velocity = move_and_slide(velocity, Vector2.UP)
update_animation()
func update_animation():
if is_on_floor():
if direction == 1:
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("walk")
elif direction == -1:
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("walk")
else:
$AnimatedSprite.play("ıdle")
else:
$AnimatedSprite.play("Jump")
if $AnimatedSprite.flip_h == false and $AnimatedSprite.offset.x < 0:
$AnimatedSprite.offset *= -1