-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.gd
40 lines (33 loc) · 958 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
extends KinematicBody2D
export var speed = 250 # vitesse du perso
var screen_size # taille de la fenêtre de jeu
func _ready():
screen_size = get_viewport_rect().size
func start(pos):
position = pos
show()
func _process(delta):
var velocity = Vector2()
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
$AnimatedSprite.play()
else:
$AnimatedSprite.stop()
move_and_slide(velocity, Vector2(0, 0))
if velocity.x != 0:
$AnimatedSprite.animation = "walk"
$AnimatedSprite.flip_v = false
$AnimatedSprite.flip_h = velocity.x < 0 # on flip si valeur negative
elif velocity.y != 0:
pass
# $AnimatedSprite.animation = "up"
else:
$AnimatedSprite.set("frame", 0) # position par défaut