-
Notifications
You must be signed in to change notification settings - Fork 5
/
block.lua
141 lines (121 loc) · 3.01 KB
/
block.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
block = class:new()
function block:init(x, y, z, i)
self.x = x
self.y = y
self.z = z
self.tilenum = i
-- 1 2 3 4 top
self.facevisible = {true, true, true, true, true}
self.facecolor = {}
self.facecolor[1] = {255, 0, 0}
self.facecolor[2] = {0, 255, 0}
self.facecolor[3] = {0, 0, 255}
self.facecolor[4] = {255, 255, 0}
self.facecolor[5] = {255, 255, 255}
self.gridcolor = {}
self.gridcolor[1] = {100, 100, 100}
self.gridcolor[2] = {150, 150, 150}
end
function block:updatevisiblefaces()
--side1
if self.z == mapdepth then
self.facevisible[1] = true
elseif map[self.x][self.y][self.z+1].tilenum ~= 1 then
self.facevisible[1] = false
else
self.facevisible[1] = true
end
--side2
if self.x == mapwidth then
self.facevisible[2] = true
elseif map[self.x+1][self.y][self.z].tilenum ~= 1 then
self.facevisible[2] = false
else
self.facevisible[2] = true
end
--side3
if self.z == 1 then
self.facevisible[3] = true
elseif map[self.x][self.y][self.z-1].tilenum ~= 1 then
self.facevisible[3] = false
else
self.facevisible[3] = true
end
--side4
if self.x == 1 then
self.facevisible[4] = true
elseif map[self.x-1][self.y][self.z].tilenum ~= 1 then
self.facevisible[4] = false
else
self.facevisible[4] = true
end
--top
if self.y == mapheight then
self.facevisible[5] = true
elseif map[self.x][self.y+1][self.z].tilenum ~= 1 then
self.facevisible[5] = false
else
self.facevisible[5] = true
end
end
----------------------------------
menublock = class:new()
function menublock:init(x, y, z, i)
self.x = x
self.y = y
self.z = z
self.tilenum = i
-- 1 2 3 4 top
self.facevisible = {true, true, true, true, true}
self.facecolor = {}
self.facecolor[1] = {255, 0, 0}
self.facecolor[2] = {0, 255, 0}
self.facecolor[3] = {0, 0, 255}
self.facecolor[4] = {255, 255, 0}
self.facecolor[5] = {255, 255, 255}
self.gridcolor = {}
self.gridcolor[1] = {100, 100, 100}
self.gridcolor[2] = {150, 150, 150}
end
function menublock:updatevisiblefaces()
--side1
if self.z == menumapdepth then
self.facevisible[1] = true
elseif menumap[self.x][self.y][self.z+1].tilenum ~= 1 then
self.facevisible[1] = false
else
self.facevisible[1] = true
end
--side2
if self.x == menumapwidth then
self.facevisible[2] = true
elseif menumap[self.x+1][self.y][self.z].tilenum ~= 1 then
self.facevisible[2] = false
else
self.facevisible[2] = true
end
--side3
if self.z == 1 then
self.facevisible[3] = true
elseif menumap[self.x][self.y][self.z-1].tilenum ~= 1 then
self.facevisible[3] = false
else
self.facevisible[3] = true
end
--side4
if self.x == 1 then
self.facevisible[4] = true
elseif menumap[self.x-1][self.y][self.z].tilenum ~= 1 then
self.facevisible[4] = false
else
self.facevisible[4] = true
end
--top
if self.y == menumapheight then
self.facevisible[5] = true
elseif menumap[self.x][self.y+1][self.z].tilenum ~= 1 then
self.facevisible[5] = false
else
self.facevisible[5] = true
end
end