-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.lua
157 lines (145 loc) · 4.22 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
-- Blind Tower Defense (temporal name)
-- Copyright 2009 Iwan Gabovitch, Christiaan Janssen, September 2009
--
-- This file is part of Blind Tower Defense
--
-- Blind Tower Defense is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- Blind Tower Defense is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Blind Tower Defense If not, see <http://www.gnu.org/licenses/>.
Map={}
Map.hcells = 20
Map.vcells = 20
Cell = {
width = math.floor(screensize[1]/Map.hcells),
height = math.floor(screensize[2]/Map.vcells)
}
-- force square
Cell.width = Cell.height
function examplemap()
local i,j
-- example: 10x10 map
-- closed: (cannot go through) 0
-- open: (can go through) 1
-- door open: 2
-- door closed: 3
-- door blocked: 4
for i=1,Map.hcells do
Map[i]={}
for j=1,Map.vcells do
Map[i][j]={
u = 0,
d = 0,
l = 0,
r = 0,
corridor = true
}
end
end
--~ Map[5][5].u = 1
--~ Map[5][4].d = 1
--~ Map[6][6].d = 2
--~ Map[6][7].u = 2
--~ Map[7][7].r = 3
--~ Map[8][7].l = 3
--~ Map[8][8].l = 4
--~ Map[8][7].r = 4
end
function drawmap(map)
love.graphics.setLineWidth(2)
local i,j
--~ local dx=screensize[1]/Map.hcells
--~ local dy=screensize[2]/Map.vcells
local dx,dy = Cell.width,Cell.height
--~ dx = dy
for i=1,Map.hcells do
for j=1,Map.vcells do
if not map[i][j].corridor then
love.graphics.setColor(0,48,48)
love.graphics.rectangle( "fill" , (i-1)*dx+1,(j-1)*dy+1,dx-1,dy-1 )
end
if map[i][j].corridor then
-- walls
if map[i][j].u==0 then
love.graphics.setColor(0,160,160)
love.graphics.line((i-1)*dx,(j-1)*dy,i*dx,(j-1)*dy)
end
if map[i][j].l==0 then
love.graphics.setColor(0,160,160)
love.graphics.line((i-1)*dx,(j-1)*dy,(i-1)*dx,j*dy)
end
if map[i][j].d==0 then
love.graphics.setColor(0,160,160)
love.graphics.line((i-1)*dx,j*dy,i*dx,j*dy)
end
if map[i][j].r==0 then
love.graphics.setColor(0,160,160)
love.graphics.line(i*dx,(j-1)*dy,i*dx,j*dy)
end
-- closed doors
if map[i][j].u==3 then
love.graphics.setColor(160,0,160)
love.graphics.line((i-1)*dx,(j-1)*dy,i*dx,(j-1)*dy)
end
if map[i][j].l==3 then
love.graphics.setColor(160,0,160)
love.graphics.line((i-1)*dx,(j-1)*dy,(i-1)*dx,j*dy)
end
if map[i][j].d==3 then
love.graphics.setColor(160,0,160)
love.graphics.line((i-1)*dx,j*dy,i*dx,j*dy)
end
if map[i][j].r==3 then
love.graphics.setColor(160,0,160)
love.graphics.line(i*dx,(j-1)*dy,i*dx,j*dy)
end
-- blocked doors
if map[i][j].u==4 then
love.graphics.setColor(200,0,0)
love.graphics.line((i-1)*dx,(j-1)*dy,i*dx,(j-1)*dy)
end
if map[i][j].l==4 then
love.graphics.setColor(200,0,0)
love.graphics.line((i-1)*dx,(j-1)*dy,(i-1)*dx,j*dy)
end
if map[i][j].d==4 then
love.graphics.setColor(200,0,0)
love.graphics.line((i-1)*dx,j*dy,i*dx,j*dy)
end
if map[i][j].r==4 then
love.graphics.setColor(200,0,0)
love.graphics.line(i*dx,(j-1)*dy,i*dx,j*dy)
end
-- open doors
if map[i][j].u==2 then
love.graphics.setColor(160,0,160)
love.graphics.line((i-1)*dx,(j-1)*dy,(i-3/4)*dx,(j-1)*dy)
love.graphics.line((i-1/4)*dx,(j-1)*dy,i*dx,(j-1)*dy)
end
if map[i][j].l==2 then
love.graphics.setColor(160,0,160)
love.graphics.line((i-1)*dx,(j-1)*dy,(i-1)*dx,(j-3/4)*dy)
love.graphics.line((i-1)*dx,(j-1/4)*dy,(i-1)*dx,j*dy)
end
if map[i][j].d==2 then
love.graphics.setColor(160,0,160)
love.graphics.line((i-1)*dx,j*dy,(i-3/4)*dx,j*dy)
love.graphics.line((i-1/4)*dx,j*dy,i*dx,j*dy)
end
if map[i][j].r==2 then
love.graphics.setColor(160,0,160)
love.graphics.line(i*dx,(j-1)*dy,i*dx,(j-3/4)*dy)
love.graphics.line(i*dx,(j-1/4)*dy,i*dx,j*dy)
end
end
end
end
end