-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.lua
101 lines (97 loc) · 3.31 KB
/
map.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
-- map.lua the class with functions and variables uded with maps
local Map = {}
Map.currentMap = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
{1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1},
{1,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0,0,1,1,1},
{1,0,1,0,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1},
{1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,1,0,0,0,0,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,1},
{1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,1,1,1,0,1,0,1,0,1,1,1,1,1,1,0,1,1,1},
{1,0,0,0,1,0,1,0,1,0,1,1,1,1,1,1,0,1,1,1},
{1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,0,1,1,1},
{0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}}
Map.length = {}
Map.length.x = 20
Map.length.y = 20
-- Basic unit of map
Map.tile = {}
-- Bool for enabling standing on a tile: true = party can stand on tile
Map.tile.isWalkable = true
-- Wall decorations are stuff like buttons, levers, mirrors, etc... each world side has one table, north, east, south, west
Map.tile.n_wall_decor = {}
Map.tile.e_wall_decor = {}
Map.tile.s_wall_decor = {}
Map.tile.w_wall_decor = {}
-- Table containing items of the tile
Map.tile.items = {}
--Function that provides a matrix that is a part of map,
--It takes x,y position on the map, range how big the matrix should be and a direction where it should be progressing
--It takes x,y as center of one side of square and maps all the tiles in from of it in the specified direction
function Map:getMapSquare(x,y,direction,range)
local map_square = {}
for i=1,range do map_square[i] = {} end
--if direction is to north, we always move the beginning to left bottom of matrix
if direction == 0 then
x = x - math.floor(range/2)-1
y = y+1
for i=1,range do
for j=1,range do
if x+j <= 0 or x+j > #Map.currentMap or y-i <= 0 or y-i > #Map.currentMap
then map_square[i][j] = 0
else map_square[i][j] = Map.currentMap[y-i][x+j]
end
end
end
end
--if direction is to east
if direction == 1 then
y = y - math.floor(range/2)-1
x = x-1
for i=1,range do
for j=1,range do
if x+i <= 0 or x+i > #Map.currentMap or y+j <= 0 or y+j > #Map.currentMap
then map_square[i][j] = 0
else map_square[i][j] = Map.currentMap[y+j][x+i]
end
end
end
end
--if direction is to south
if direction == 2 then
x = x + math.floor(range/2)+1
y = y-1
for i=1,range do
for j=1,range do
if y+i <= 0 or y+i > #Map.currentMap or x-j <= 0 or x-j > #Map.currentMap
then map_square[i][j] = 0
else map_square[i][j] = Map.currentMap[y+i][x-j]
end
end
end
end
--if direction is to west
if direction == 3 then
y = y + math.floor(range/2)+1
x = x+1
for i=1,range do
for j=1,range do
if x-i <= 0 or x-i > #Map.currentMap or y-j <= 0 or y-j > #Map.currentMap
then map_square[i][j] = 0
else map_square[i][j] = Map.currentMap[y-j][x-i]
end
end
end
end
return map_square
end
return Map