-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.lua
66 lines (58 loc) · 1.45 KB
/
player.lua
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
55
56
57
58
59
60
61
62
63
64
65
66
require('nodes')
player = {
x = 0,
y = 0,
dead = false,
blind = false,
checkpoint = {
x = 0,
y = 0
},
coinsCollected = 0
}
local function getMovement(key)
if key == "up" or key == "w" then
return {
x = player.x,
y = player.y - 1
}
elseif key == "down" or key == "s" then
return {
x = player.x,
y = player.y + 1
}
elseif key == "left" or key == "a" then
return {
x = player.x - 1,
y = player.y
}
elseif key == "right" or key == "d" then
return {
x = player.x + 1,
y = player.y
}
else
return false
end
end
player.handleKey = function(key)
local movement = getMovement(key)
if movement and nodes.isWalkable(movement.x, movement.y) and player.blind then
player.x = movement.x
player.y = movement.y
if (nodes.isDeadly(movement.x, movement.y)) then
player.dead = true
end
if (candles[movement.x] or {})[movement.y] then
player.checkpoint.x = movement.x
player.checkpoint.y = movement.y
end
if (coins[movement.x] or {})[movement.y] then
player.coinsCollected = player.coinsCollected + 1
coins[movement.x][movement.y] = false
end
end
if key == "space" then
player.blind = not player.blind
end
end