-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.gd
More file actions
49 lines (36 loc) · 1.01 KB
/
Copy pathPlayer.gd
File metadata and controls
49 lines (36 loc) · 1.01 KB
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
48
49
extends KinematicBody2D
# - Properties
var score :int = 0
var speed: int = 400
var jumpForce : int = 600
var gravity : int = 800
var vel : Vector2 = Vector2()
onready var sprite : Sprite = get_node("Sprite")
onready var footStepsAudio = $"AudioEffect/FootStepsAudioPlayer"
func _physics_process(delta):
vel.x = 0
# - Movement inputs
if Input.is_action_pressed("move_left"):
footStepsAudio.play()
vel.x -= speed
elif Input.is_action_pressed("move_right"):
footStepsAudio.play()
vel.x += speed
elif Input.is_action_just_released("move_left"):
footStepsAudio.stop()
elif Input.is_action_just_released("move_right"):
footStepsAudio.stop()
# - Applying velocity
vel = move_and_slide(vel,Vector2.UP)
# - Gravity
vel.y +=gravity*delta
# Jump input
if Input.is_action_just_pressed("jump") and is_on_floor():
vel.y -= jumpForce
if Input.is_action_just_released("jump"):
footStepsAudio.stop()
# - Sprite direction
if vel.x < 0:
sprite.flip_h = true
elif vel.x > 0:
sprite.flip_h = false