-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.gd
54 lines (39 loc) · 1.12 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
47
48
49
50
51
52
53
54
extends KinematicBody2D
# Declare member variables here. Examples:
var curHp : int = 10
var maxHp : int = 10
var moveSpeed : int = 250
var damage : int = 1
var gold : int = 0
var curLevel : int = 0
var curXp : int = 0
var xpToNextLevel : int = 50
var xpToLevelIncreaseRate : float = 1.2
var interactDist : int = 70
var vel = Vector2()
var facingDir = Vector2()
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _physics_process (delta):
vel = Vector2()
# inputs
if Input.is_action_pressed("move_up"):
vel.y -= 1
facingDir = Vector2(0, -1)
if Input.is_action_pressed("move_down"):
vel.y += 1
facingDir = Vector2(0, 1)
if Input.is_action_pressed("move_left"):
vel.x -= 1
facingDir = Vector2(-1, 0)
if Input.is_action_pressed("move_right"):
vel.x += 1
facingDir = Vector2(1, 0)
# normalize the velocity to prevent faster diagonal movement
vel = vel.normalized()
# move the player
move_and_slide(vel * moveSpeed, Vector2.ZERO)