-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.lua
More file actions
49 lines (47 loc) · 1.31 KB
/
player.lua
File metadata and controls
49 lines (47 loc) · 1.31 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
require("specialTile")
function updatePlayer(self, key, map, index)
map[self.x][self.y] = self.under
if (key=="up" or key=="e") then
if map[self.x - 1 * self.dir][self.y] <= 4 then
self.x = self.x - 1 * self.dir
end
end
if (key=="left" or key=="a") then
if map[self.x][self.y - 1* self.dir] <= 4 then
self.y = self.y - 1 * self.dir
end
end
if (key=="down" or key=="w") then
if map[self.x + 1* self.dir][self.y] <= 4 then
self.x = self.x + 1 * self.dir
end
end
if (key=="right" or key=="c") then
if map[self.x][self.y + 1* self.dir] <= 4 then
self.y = self.y + 1 * self.dir
end
end
self.under = map[self.x][self.y]
map[self.x][self.y] = 11
if (self.under == 3) then
self.dir = self.dir * -1
elseif (self.under == 2) then
local otherTp = findOtherTp(map)
if (otherTp ~= 0) then
map[self.x][self.y] = self.under
self.x = otherTp[1]
self.y = otherTp[2]
self.under = map[self.x][self.y]
map[self.x][self.y] = 11
end
end
end
function createPlayer()
player = {}
player.x = 2
player.y = 2
player.dir = 1
player.under = 1
player.lvl = 1
return player
end