|
1 ObjectList = {} |
|
2 PointsBuffer = '' -- A string to accumulate points in |
|
3 |
|
4 -- Overall padding for roping freedom |
|
5 Padding = 430 |
|
6 |
|
7 function AddPoint(x, y, width, erase) |
|
8 PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff)) |
|
9 if width then |
|
10 width = bor(width,0x80) |
|
11 if erase then |
|
12 width = bor(width,0x40) |
|
13 end |
|
14 PointsBuffer = PointsBuffer .. string.char(width) |
|
15 else |
|
16 PointsBuffer = PointsBuffer .. string.char(0) |
|
17 end |
|
18 if #PointsBuffer > 245 then |
|
19 ParseCommand('draw '..PointsBuffer) |
|
20 PointsBuffer = '' |
|
21 end |
|
22 end |
|
23 function FlushPoints() |
|
24 if #PointsBuffer > 0 then |
|
25 ParseCommand('draw '..PointsBuffer) |
|
26 PointsBuffer = '' |
|
27 end |
|
28 end |
|
29 |
|
30 -- This could probably use less points and more precision |
|
31 -- 700x700 for object space |
|
32 function DrawStar(x, y, d, f) |
|
33 -- default scale is 700x700 or so |
|
34 s = 700 |
|
35 if not(d == 1) then s = div(s,d) end |
|
36 if NoOverlap(x,y,s,s) then |
|
37 AddCollision(x,y,s,s) |
|
38 if not(d == 1) then |
|
39 i = 6-d |
|
40 j = math.min(div(5,d),1) |
|
41 -- centre |
|
42 AddPoint(x,y,div(20,d)) |
|
43 -- arms |
|
44 AddPoint(x-div(325,d),y-f*div(108,d),2) |
|
45 AddPoint(x+div(325,d),y-f*div(108,d)) |
|
46 AddPoint(x-div(205,d),y+f*div(270,d)) |
|
47 AddPoint(x,y-f*div(345,d)) |
|
48 AddPoint(x+div(205,d),y+f*div(270,d)) |
|
49 AddPoint(x-div(325,d),y-f*div(108,d)) |
|
50 if d < 4 then |
|
51 -- fill in arm 1 |
|
52 AddPoint(x-div(275,d),y-f*div(92,d),i) |
|
53 AddPoint(x-div(50,d),y-f*div(92,d)) |
|
54 AddPoint(x-div(105,d),y+f*div(25,d)) |
|
55 AddPoint(x-div(250,d),y-f*div(80,d)) |
|
56 AddPoint(x-div(115,d),y-f*div(70,d)) |
|
57 AddPoint(x-div(130,d),y-f*div(25,d)) |
|
58 AddPoint(x-div(175,d),y-f*div(60,d)) |
|
59 -- fill in arm 2 |
|
60 AddPoint(x+div(275,d),y-f*div(92,d),i) |
|
61 AddPoint(x+div(50,d),y-f*div(92,d)) |
|
62 AddPoint(x+div(105,d),y+f*div(25,d)) |
|
63 AddPoint(x+div(250,d),y-f*div(80,d)) |
|
64 AddPoint(x+div(115,d),y-f*div(70,d)) |
|
65 AddPoint(x+div(130,d),y-f*div(25,d)) |
|
66 AddPoint(x+div(175,d),y-f*div(60,d)) |
|
67 -- fill in arm 3 |
|
68 AddPoint(x-div(175,d),y+f*div(230,d),i) |
|
69 AddPoint(x-div(110,d),y+f*div(60,d)) |
|
70 AddPoint(x,y+f*div(120,d)) |
|
71 AddPoint(x-div(155,d),y+f*div(215,d)) |
|
72 AddPoint(x-div(105,d),y+f*div(95,d)) |
|
73 AddPoint(x-div(60,d),y+f*div(130,d)) |
|
74 AddPoint(x-div(85,d),y+f*div(155,d),j) |
|
75 -- fill in arm 4 |
|
76 AddPoint(x,y-f*div(300,d),3) |
|
77 AddPoint(x+div(50,d),y-f*div(125,d)) |
|
78 AddPoint(x-div(50,d),y-f*div(125,d)) |
|
79 AddPoint(x,y-f*div(270,d)) |
|
80 AddPoint(x-div(40,d),y-f*div(160,d)) |
|
81 AddPoint(x+div(40,d),y-f*div(160,d)) |
|
82 AddPoint(x,y-f*div(195,d),j) |
|
83 -- fill in arm 5 |
|
84 AddPoint(x+div(175,d),y+f*div(230,d),i) |
|
85 AddPoint(x+div(110,d),y+f*div(60,d)) |
|
86 AddPoint(x,y+f*div(120,d)) |
|
87 AddPoint(x+div(155,d),y+f*div(215,d)) |
|
88 AddPoint(x+div(105,d),y+f*div(95,d)) |
|
89 AddPoint(x+div(60,d),y+f*div(130,d)) |
|
90 AddPoint(x+div(85,d),y+f*div(155,d),j) |
|
91 end |
|
92 else |
|
93 -- centre |
|
94 AddPoint(x,y,20) |
|
95 -- arms |
|
96 AddPoint(x-325,y-f*108,1) |
|
97 AddPoint(x+325,y-f*108) |
|
98 AddPoint(x-205,y+f*270) |
|
99 AddPoint(x,y-f*345) |
|
100 AddPoint(x+205,y+f*270) |
|
101 AddPoint(x-325,y-f*108) |
|
102 -- fill in arm 1 |
|
103 AddPoint(x-275,y-f*92,4) |
|
104 AddPoint(x-50,y-f*92) |
|
105 AddPoint(x-105,y+f*25) |
|
106 AddPoint(x-250,y-f*80) |
|
107 AddPoint(x-115,y-f*70) |
|
108 AddPoint(x-130,y-f*25) |
|
109 AddPoint(x-175,y-f*60) |
|
110 -- fill in arm 2 |
|
111 AddPoint(x+275,y-f*92,4) |
|
112 AddPoint(x+50,y-f*92) |
|
113 AddPoint(x+105,y+f*25) |
|
114 AddPoint(x+250,y-f*80) |
|
115 AddPoint(x+115,y-f*70) |
|
116 AddPoint(x+130,y-f*25) |
|
117 AddPoint(x+175,y-f*60) |
|
118 -- fill in arm 3 |
|
119 AddPoint(x-175,y+f*230,4) |
|
120 AddPoint(x-110,y+f*60) |
|
121 AddPoint(x-10,y+f*120) |
|
122 AddPoint(x-155,y+f*215) |
|
123 AddPoint(x-105,y+f*95) |
|
124 AddPoint(x-60,y+f*130) |
|
125 AddPoint(x-85,y+f*155,5) |
|
126 -- fill in arm 4 |
|
127 AddPoint(x,y-f*300,3) |
|
128 AddPoint(x+50,y-f*125) |
|
129 AddPoint(x-50,y-f*125) |
|
130 AddPoint(x,y-f*270) |
|
131 AddPoint(x-40,y-f*160) |
|
132 AddPoint(x+40,y-f*160) |
|
133 AddPoint(x,y-f*195,5) |
|
134 -- fill in arm 5 |
|
135 AddPoint(x+175,y+f*230,4) |
|
136 AddPoint(x+110,y+f*60) |
|
137 AddPoint(x+10,y+f*120) |
|
138 AddPoint(x+155,y+f*215) |
|
139 AddPoint(x+105,y+f*95) |
|
140 AddPoint(x+60,y+f*130) |
|
141 AddPoint(x+85,y+f*155,5) |
|
142 end |
|
143 return true |
|
144 else |
|
145 return false |
|
146 end |
|
147 end |
|
148 |
|
149 -- well. this was easy |
|
150 function DrawCircle(x, y, w) |
|
151 if NoOverlap(x,y,w*10+6,w*10+6) then |
|
152 AddCollision(x,y,w*10+6,w*10+6) |
|
153 AddPoint(x,y,w) |
|
154 return true |
|
155 else |
|
156 return false |
|
157 end |
|
158 end |
|
159 |
|
160 function DrawCrescent(x, y, w, s) |
|
161 b = div(w*(GetRandom(4)+1)*10+6,6) |
|
162 |
|
163 if NoOverlap(x,y,w*10+6,w*10+6) then |
|
164 AddCollision(x,y,w*10+6,w*10+6) |
|
165 AddPoint(x,y,w) |
|
166 if s then -- side |
|
167 if GetRandom(1) == 0 then |
|
168 b = b*-1 |
|
169 end |
|
170 AddPoint(x-b,y,w,true) |
|
171 else -- top |
|
172 AddPoint(x,y-b,w,true) |
|
173 end |
|
174 return true |
|
175 else |
|
176 return false |
|
177 end |
|
178 end |
|
179 |
|
180 function DrawCones(x,w,h,c) |
|
181 y = 2048-h |
|
182 hw = div(w,2) |
|
183 if NoOverlap(x+div(w*c,2),y+div(h,2),w*c,h) then |
|
184 AddCollision(x+div(w*c,2),y+div(h,2),w*c,h) |
|
185 x = x + hw |
|
186 for i = 1,c do -- I'm guessing outlining is slightly more efficient than fanning at 16px brush |
|
187 AddPoint(x,y,1) |
|
188 AddPoint(x-hw+8,2048) |
|
189 AddPoint(x+hw-8,2048) |
|
190 AddPoint(x,y) |
|
191 for j = x-hw+25,x+hw,34 do |
|
192 AddPoint(x,y+30,3) |
|
193 AddPoint(j,2048) |
|
194 end |
|
195 if GetRandom(2)==0 then |
|
196 AddPoint(x,y-20,8) |
|
197 end |
|
198 x = x + w |
|
199 end |
|
200 else |
|
201 return false |
|
202 end |
|
203 |
|
204 end |
|
205 |
|
206 function DrawPlateau(x,y,l,t,b) |
|
207 if NoOverlapXY(x-28,y-28,x+l+28,y+l+28) then |
|
208 AddPoint(x,y,5) |
|
209 AddPoint(x+l,y) |
|
210 |
|
211 to = GetRandom(6) |
|
212 if not(to==0) then |
|
213 if GetRandom(2)==0 then |
|
214 to = div(l,to) |
|
215 else |
|
216 to = l-div(l,to) |
|
217 end |
|
218 end |
|
219 if t>0 and NoOverlapXY(x+to-28,y-t-28,x+to+28,y+28) then |
|
220 AddPoint(x+to,y-t,5) |
|
221 AddPoint(x+to,y) |
|
222 if GetRandom(2)==0 then |
|
223 AddPoint(x+to,y-t+75,20) |
|
224 else -- square off |
|
225 AddPoint(x+to-20,y-t,1) |
|
226 AddPoint(x+to-20,y-t-20) |
|
227 AddPoint(x+to+20,y-t-20) |
|
228 AddPoint(x+to+20,y-t) |
|
229 end |
|
230 tSucc = true |
|
231 end |
|
232 |
|
233 if to > 120 and GetRandom(2)==0 then -- left bumper |
|
234 AddPoint(x+15,y-20,9) |
|
235 else -- square off |
|
236 --AddPoint(x-50,y,2) |
|
237 AddPoint(x,y+20,1) |
|
238 AddPoint(x-20,y+20) |
|
239 AddPoint(x-20,y-20) |
|
240 AddPoint(x,y-20) |
|
241 end |
|
242 if to < (l-120) and GetRandom(2)==0 then -- right bumper |
|
243 AddPoint(x+l-15,y-20,9) |
|
244 else -- square off |
|
245 --AddPoint(x+l+50,y,2) |
|
246 AddPoint(x+l,y+20,1) |
|
247 AddPoint(x+l+20,y+20) |
|
248 AddPoint(x+l+20,y-20) |
|
249 AddPoint(x+l,y-20) |
|
250 end |
|
251 bo = GetRandom(6) |
|
252 if not(bo == 0) then |
|
253 if GetRandom(2)==0 then |
|
254 bo = div(l,bo) |
|
255 else |
|
256 bo = l-div(l,bo) |
|
257 end |
|
258 end |
|
259 -- still consider a success even if we can't place this one. Might need to return more than true/false |
|
260 if b>0 and NoOverlapXY(x+bo-28,y-28,x+bo+28,y+b+28) then |
|
261 AddPoint(x+bo,y,5) |
|
262 AddPoint(x+bo,y+b) |
|
263 if GetRandom(2)==0 then |
|
264 AddPoint(x+bo,y+b-75,20) |
|
265 else -- square off |
|
266 AddPoint(x+bo-20,y+b,1) |
|
267 AddPoint(x+bo-20,y+b+20) |
|
268 AddPoint(x+bo+20,y+b+20) |
|
269 AddPoint(x+bo+20,y+b) |
|
270 end |
|
271 bSucc = true |
|
272 end |
|
273 if bSucc then AddCollisionXY(x+bo-28,y-28,x+bo+28,y+b+28) end |
|
274 if tSucc then AddCollisionXY(x+to-28,y-t-28,x+to+28,y+28) end |
|
275 AddCollisionXY(x-28,y-28,x+l+28,y+28) |
|
276 return true |
|
277 else |
|
278 return false |
|
279 end |
|
280 end |
|
281 |
|
282 function AddCollision(x,y,w,h) |
|
283 table.insert(ObjectList,{x-div(w+Padding,2), |
|
284 y-div(h+Padding,2), |
|
285 x+div(w+Padding,2), |
|
286 y+div(h+Padding,2)}) |
|
287 end |
|
288 |
|
289 function AddCollisionXY(x,y,x2,y2) |
|
290 table.insert(ObjectList,{x-div(Padding,2), |
|
291 y-div(Padding,2), |
|
292 x2+div(Padding,2), |
|
293 y2+div(Padding,2)}) |
|
294 end |
|
295 |
|
296 -- bounding box check |
|
297 function NoOverlap(x,y,w,h) |
|
298 w = w |
|
299 h = h |
|
300 x = x-div(w,2) |
|
301 y = y-div(h,2) |
|
302 x2 = x+w |
|
303 y2 = y+h |
|
304 return NoOverlapXY(x,y,x2,y2) |
|
305 end |
|
306 function NoOverlapXY(x,y,x2,y2) |
|
307 i=1 |
|
308 l=table.getn(ObjectList) |
|
309 while i<=l do |
|
310 ox = ObjectList[i][1] |
|
311 oy = ObjectList[i][2] |
|
312 ox2 = ObjectList[i][3] |
|
313 oy2 = ObjectList[i][4] |
|
314 -- WriteLnToConsole(ox..' '..oy..' '..ox2..' '..oy2..' - '..x..' '..y..' '..x2..' '..y2) |
|
315 --if (math.abs(ox + ox2 -x - x2) <= (ox2 - ox + x2 - x)) and (math.abs(oy + oy2 - y - y2) <= (oy - oy2 + y - y2)) then |
|
316 if x < ox2 and ox < x2 and y < oy2 and oy < y2 then |
|
317 return false |
|
318 end |
|
319 i=i+1 |
|
320 end |
|
321 return true |
|
322 end |
|
323 |
|
324 function dbg() |
|
325 i=1 |
|
326 l=table.getn(ObjectList) |
|
327 while i<=l do |
|
328 ox = ObjectList[i][1] |
|
329 oy = ObjectList[i][2] |
|
330 ox2 = ObjectList[i][3] |
|
331 oy2 = ObjectList[i][4] |
|
332 AddPoint(ox,oy,1) |
|
333 AddPoint(ox2,oy) |
|
334 AddPoint(ox2,oy2) |
|
335 AddPoint(ox,oy2) |
|
336 AddPoint(ox,oy) |
|
337 AddPoint(ox2,oy2) |
|
338 i=i+1 |
|
339 end |
|
340 end |
|
341 |
|
342 function onGameInit() |
|
343 MapGen = 2 |
|
344 TemplateFilter = 0 |
|
345 TotGen = 0 |
|
346 Tries = 0 |
|
347 if GetRandom(2) == 0 then |
|
348 AddPoint(-50,2030,10) |
|
349 AddPoint(4150,2030) |
|
350 for i = 0,GetRandom(3) do |
|
351 x = GetRandom(4096) |
|
352 AddPoint(x,2200,GetRandom(50),true) |
|
353 AddPoint(x,1900) |
|
354 end |
|
355 end |
|
356 |
|
357 |
|
358 if GetRandom(2) == 0 then |
|
359 l = GetRandom(3)+1 |
|
360 w = GetRandom(200)+200 |
|
361 h = GetRandom(350)+200 |
|
362 x = GetRandom(4096-w*l) |
|
363 DrawCones(x,w,h,l) |
|
364 --if DrawCones(x,w,h,l) then TotGen = TotGen+1 |
|
365 end |
|
366 if GetRandom(2) == 0 then |
|
367 for i = 1,GetRandom(5)+1 do |
|
368 w = GetRandom(35)+15 |
|
369 x = GetRandom(4096-w*12)+w |
|
370 if GetRandom(2)==0 then |
|
371 y = 2048-GetRandom(w*10+6) |
|
372 else |
|
373 y = 2048 |
|
374 end |
|
375 -- if AddPoint(x,y,w) then TotGetn = TotGen+1 |
|
376 DrawCircle(x,y,w) |
|
377 end |
|
378 end |
|
379 if GetRandom(2)==0 then |
|
380 x = GetRandom(3300)+350 |
|
381 y = GetRandom(1300)+350 |
|
382 if DrawStar(x,y, 1, 1+GetRandom(2)*-2) then |
|
383 TotGen = TotGen+1 |
|
384 end |
|
385 end |
|
386 |
|
387 while (TotGen < 6) and (Tries < 100) do |
|
388 l = GetRandom(1000-Tries*10)+300 |
|
389 x = GetRandom(3900-l)+100 |
|
390 y = GetRandom(1900)+100 |
|
391 if GetRandom(2)==0 then b = GetRandom(800)+300 |
|
392 else b = 0 end |
|
393 if GetRandom(2)==0 then t = GetRandom(800)+300 |
|
394 else t = 0 end |
|
395 if y-t < 50 then t = y - 50 end |
|
396 if t < 200 then t = 0 end |
|
397 if DrawPlateau(x,y,l,t,b) then |
|
398 TotGen = TotGen+1 |
|
399 end |
|
400 Tries = Tries + 1 |
|
401 end |
|
402 Tries = 0 |
|
403 while (TotGen < 17) and (Tries < 1000) do |
|
404 if Tries < 500 and GetRandom(2)==0 then |
|
405 x = GetRandom(3300)+350 |
|
406 y = GetRandom(1300)+350 |
|
407 if DrawStar(x,y, 1, 1+GetRandom(2)*-2) then |
|
408 TotGen = TotGen+1 |
|
409 end |
|
410 else |
|
411 if Tries > 500 then d = GetRandom(2)+3 |
|
412 else d = GetRandom(3)+2 end |
|
413 x = GetRandom(4000-div(700,d))+div(700,d*2) |
|
414 y = GetRandom(1300-div(700,d))+div(700,d*2) |
|
415 if DrawStar(x,y, d, 1+GetRandom(2)*-2) then |
|
416 TotGen = TotGen+1 |
|
417 end |
|
418 end |
|
419 w = GetRandom(35-div(Tries,29))+15 |
|
420 x = GetRandom(4050-w*20)+w*10 |
|
421 y = GetRandom(2000-w*20)+w*10 |
|
422 if DrawCircle(x,y,w) then |
|
423 TotGen = TotGen+1 |
|
424 end |
|
425 w = GetRandom(35-div(Tries,29))+5 |
|
426 x = GetRandom(4050-w*20)+w*10 |
|
427 y = GetRandom(2000-w*20)+w*10 |
|
428 if DrawCrescent(x,y,w,GetRandom(2)==0) then |
|
429 TotGen = TotGen+1 |
|
430 end |
|
431 Tries = Tries + 1 |
|
432 end |
|
433 -- Padding = div(Padding,2) |
|
434 -- Tries = 0 |
|
435 -- while (TotGen < 21) and (Tries < 10000) do |
|
436 -- r = GetRandom(20-div(Tries,223))+5 |
|
437 -- x = GetRandom(4050-r*20)+r*10 |
|
438 -- y = GetRandom(2000-r*20)+r*10 |
|
439 -- if DrawCircle(x,y,r) then |
|
440 -- TotGen = TotGen+1 |
|
441 -- end |
|
442 -- Tries = Tries + 1 |
|
443 -- end |
|
444 --dbg() |
|
445 FlushPoints() |
|
446 end |