vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 function wowon_geo_ball_in (b)
2 -- a = flugwinkel ball
3 -- xb = x pos ball
4 -- yb = y pos ball
5 -- r = radius ball
6 -- d = r/(wurzel2) -- diagonalenfaktor
7  
8 -- xf = x pos feld (immer links unten)
9 -- yf = y pos feld
10 -- b = breite feld
11 -- h = höhe feld
12 -- t = berechnungstoleranz / feldrahmen
13  
14 -- return (punkt auf dem kreis, der kolosion hat) (aufprall winkel) (feldnummer)
15 -- retrun nil, wenn gar nix der fall ist
16  
17 local a = wowon.game.ball[b].w
18 local xb = wowon.game.ball[b].x
19 local yb = wowon.game.ball[b].y
20 local r = wowon.game.ball[b].r
21 local d = r/(math.sqrt(2))
22  
23  
24  
25 for i = 1, table.getn(wowon.game.felder) do
26  
27 local f = wowon.game.felder[i]
28 local xf = wowon.game.feld[f].x
29 local yf = wowon.game.feld[f].y
30 local b = wowon.game.feld[f].b
31 local h = wowon.game.feld[f].h
32 local t = nil
33 if (b>h) then
34 t = h/2
35 else
36 t = b/2
37 end
38  
39 -- nach rechts oben (f2)
40 if (a>0) and (a<90) then
41 -- für p1
42 if (yf<yb+r and yf+t>yb+r) and (xf<xb and xf+b>xb) then
43 return 1, 2, f
44 -- für p3
45 elseif (yf<yb and yf+h>yb) and (xf<xb+r and xf+t>xb+r) then
46 return 3, 2, f
47 -- für p2
48 elseif (yf<yb+d and yf+t>yb+d) and (xf<xb+d and xf+t>xb+d) then
49 return 2, 2, f
50 -- für p8
51 elseif (yf<yb+d and yf+t>yb+d) and (xf+b>xb-d and xf+b-t<xb-d) then
52 return 8, 2, f
53 -- für p4
54 elseif (xf<xb+d and xf+t>xb+d) and (yf+h>yb-d and yf+h-t<yb-d) then
55 return 4, 2, f
56 else
57 end
58  
59 -- nach links oben (f6)
60 elseif (a>270 and a<360) then
61 -- für p1
62 if (yf<yb+r and yf+t>yb+r) and (xf<xb and xf+b>xb) then
63 return 1, 6, f
64 -- für p7
65 elseif (yf<yb and yf+h>yb) and (xf+b>xb-r and xf+b-t<xb-r) then
66 return 7, 6, f
67 -- für p8
68 elseif (yf<yb+d and yf+t>yb+d) and (xf+b>xb-d and xf+b-t<xb-d) then
69 return 8, 6, f
70 -- für p2
71 elseif (yf<yb+d and yf+t>yb+d) and (xf<xb+d and xf+t>xb+d) then
72 return 2, 6, f
73 -- für p6
74 elseif (yf+h>yb-d and yf+h-t<yb-d) and (xf+b>xb-d and xf+b-t<xb-d) then
75 return 6, 6
76 else
77 end
78  
79  
80 -- nach links unten (f5)
81 elseif (a>180 and a<270) then
82 -- für p5
83 if (yf+h>yb-r and yf+h-t<yb-r) and (xf<xb and xf+b>xb) then
84 return 5, 5, f
85 -- für p7
86 elseif (yf<yb and yf+h>yb) and (xf+b>xb-r and xf+b-t<xb-r) then
87 return 7, 5, f
88 -- für p6
89 elseif (yf+h>yb-d and yf+h-t<yb-d) and (xf+b>xb-d and xf+b-t<xb-d) then
90 return 6, 5, f
91 -- für p8
92 elseif (yf<yb+d and yf+t>yb+d) and (xf+b>xb-d and xf+b-t<xb-d) then
93 return 8, 5, f
94 -- für p4
95 elseif (xf<xb+d and xf+t>xb+d) and (yf+h>yb-d and yf+h-t<yb-d) then
96 return 4, 5, f
97 else
98 end
99  
100 -- nach rechts unten (f3)
101 elseif (a>90 and a<180) then
102 -- für p5
103 if (yf+h>yb-r and yf+h-t<yb-r) and (xf<xb and xf+b>xb) then
104 return 5, 3, f
105 -- für p3
106 elseif (yf<yb and yf+h>yb) and (xf<xb+r and xf+t>xb+r) then
107 return 3, 3 , f
108 -- für p4
109 elseif (xf<xb+d and xf+t>xb+d) and (yf+h>yb-d and yf+h-t<yb-d) then
110 return 4, 3, f
111 -- für p2
112 elseif (yf<yb+d and yf+t>yb+d) and (xf<xb+d and xf+t>xb+d) then
113 return 2, 3, f
114 -- für p6
115 elseif (yf+h>yb-d and yf+h-t<yb-d) and (xf+b>xb-d and xf+b-t<xb-d) then
116 return 6, 3, f
117 else
118 end
119  
120 -- nach oben (f1)
121 elseif (a==0 or a==360) then
122 -- für p1
123 if (yf<yb+r and yf+t>yb+r) and (xf<xb and xf+b>xb) then
124 return 1, 1, f
125 -- für p2
126 elseif (yf<yb+d and yf+t>yb+d) and (xf<xb+d and xf+t>xb+d) then
127 return 2, 1, f
128 -- für p8
129 elseif (yf<yb+d and yf+t>yb+d) and (xf+b>xb-d and xf+b-t<xb-d) then
130 return 8, 2, f
131 else
132 end
133  
134 -- nach unten (f4)
135 elseif (a==180) then
136  
137 -- für p5
138 if (yf+h>yb-r and yf+h-t<yb-r) and (xf<xb and xf+b>xb) then
139 return 5, 4, f
140 -- für p4
141 elseif (xf<xb+d and xf+t>xb+d) and (yf+h>yb-d and yf+h-t<yb-d) then
142 return 4, 4, f
143 -- für p6
144 elseif (yf+h>yb-d and yf+h-t<yb-d) and (xf+b>xb-d and xf+b-t<xb-d) then
145 return 6, 4, f
146 else
147 end
148  
149 else
150 end
151  
152 end
153 return nil
154 end
155  
156  
157  
158 -- überprüft ob ball auserhalb des sf ist
159 -- return nil - wenn im sf
160 -- return 1 - wenn oben drausen
161 -- retrun 5 - wenn unten drausen
162 -- retrun 7 - wenn links drausen
163 -- retrun 3 - wenn rechts drausen
164 -- return "b" - wenn ball den balken berührt
165 -- zweite stelle = aufprallwinkel
166 function wowon_geo_ball_out (b)
167 -- b = ballnummer
168  
169 -- a = flugwinkel ball
170 local a = wowon.game.ball[b].w
171 -- x = x pos ball
172 local x = wowon.game.ball[b].x
173 -- y = y pos ball
174 local y = wowon.game.ball[b].y
175 -- r = radius ball
176 local r = wowon.game.ball[b].r
177  
178 -- h = höhe des sf
179 local h = wowon.game.feld.y
180 -- b = breite des sf
181 local b = wowon.game.feld.x
182 -- o = offset
183 local o = wowon.game.feld.o
184  
185 -- bb = breite balken
186 local bb = wowon.game.balken.b
187 -- xb = x pos balken
188 local xb = wowon.game.balken.x
189 -- hb = höhe des balken
190 local hb = wowon.game.balken.h
191  
192 if (y+r>h) then
193 if (a>0 and a<90) then
194 return 1, 2
195 elseif (a>270 and a<360) then
196 return 1, 6
197 else
198 return 1, 1
199 end
200 elseif (x-r<0) then
201 if (a>270 and a<360) then
202 return 7, 6
203 else
204 return 7, 5
205 end
206 elseif (x+r>b) then
207 if (a>0 and a<90) then
208 return 3, 2
209 else
210 return 3, 3
211 end
212 elseif (y-r<o) and (x>xb-bb/2) and (x<xb+bb/2) and (y-r>o-hb) then
213 return "b"
214 elseif (y-r<0) then
215 return 5
216 else
217 return nil
218 end
219  
220 end
221  
222  
223 -- setzt den winkeln nach / einfallswinkel = ausfallswinkel
224 function wowon_geo_winkel (b, p, w)
225 -- b = ballnummer
226 -- p = aufprallpunkt
227 -- w = aufprallwinkel
228  
229 --wowon_debug("b="..b.." p="..p.." w="..w)
230  
231 local a = wowon.game.ball[b].w
232  
233 if (p == 1) then
234 if (w == 1) then
235 a = 180
236 elseif (w == 2) then
237 a = 180-a
238 elseif (w == 6) then
239 a = 540-a
240 else
241 end
242 elseif (p == 3) then
243 if (w == 2) then
244 a = 360-a
245 elseif (w == 3) then
246 a = 360-a
247 else
248 end
249 elseif (p == 7) then
250 if (w == 6) then
251 a = 360-a
252 elseif (w == 5) then
253 a = 360-a
254 else
255 end
256 elseif (p == 5) then
257 if (w == 5) then
258 a = 540-a
259 elseif (w == 3) then
260 a = 180-a
261 elseif (w == 4) then
262 a = 0
263 else
264 end
265  
266 -- sonderfälle (eckwinkel)
267 elseif (p == 2) then
268 a = 225
269 elseif (p == 8) then
270 a = 135
271 elseif (p == 6) then
272 a = 45
273 elseif (p == 4) then
274 a = 315
275 else
276 end
277  
278 wowon.game.ball[b].w = a
279  
280 end
281  
282 -- setzt den winkeln nach / einfallswinkel = zufallwinkel
283 function wowon_geo_randomwinkel (b, p, w)
284 -- b = ballnummer
285 -- p = aufprallpunkt
286 -- w = aufprallwinkel
287  
288 --wowon_debug("b="..b.." p="..p.." w="..w)
289  
290 local a = wowon.game.ball[b].w
291  
292 --sperrtoleranz des winkel
293 local x = 15
294  
295 if (p == 1) then
296 --if (w == 1) or (w == 2) or (w == 6) then
297 a = math.random(90+x,270-x)
298 -- verhindern eines zu senkrechten winkels
299 if (a < 190) and (a > 170) then
300 if (a < 190) and (a > 180) then
301 a = a+x
302 else
303 a = a-x
304 end
305 end
306 --end
307 elseif (p == 3) then
308 --if (w == 2) or (w == 3) then
309 a = math.random(180+x, 360-x)
310 -- verhindern eines zu waggrechten winkels
311 if (a < 280) and (a > 260) then
312 if (a < 280) and (a > 270) then
313 a = a+x
314 else
315 a = a-x
316 end
317 end
318 --end
319 elseif (p == 7) then
320 --if (w == 6) or (w == 5) then
321 a = math.random(0+x,180-x)
322 -- verhindern eines zu waggrechten winkels
323 if (a < 100) and (a > 80) then
324 if (a < 100) and (a > 90) then
325 a = a+x
326 else
327 a = a-x
328 end
329 end
330 --end
331 elseif (p == 5) then
332 --if (w == 5) or (w == 3) or (w == 4) then
333 a = math.random(0+x,180-x)
334 -- verhindern eines zu senkrechten winkels
335 if (a < 100) and (a > 80) then
336 if (a < 100) and (a > 90) then
337 a = a+x
338 else
339 a = a-x
340 end
341 end
342 if (a > 90) then
343 a = a-90
344 else
345 a = 360-4
346 end
347 --end
348  
349 -- sonderfälle (eckwinkel)
350 elseif (p == 2) then
351 a = math.random(180+x,270-x)
352 elseif (p == 8) then
353 a = math.random(90+x,180-x)
354 elseif (p == 6) then
355 a = math.random(0+x,90-x)
356 elseif (p == 4) then
357 a = math.random(270+x,360-x)
358 else
359 end
360  
361 wowon.game.ball[b].w = a
362  
363 end
364  
365 -- setzt den neuen winkel des balles nach aufprall auf den balken
366 function wowon_geo_winkel_balken (b)
367  
368 -- bx = x pos ball
369 local bx = wowon.game.ball[b].x
370 -- bb = balkenbreite
371 local bb = wowon.game.balken.b
372 -- bbx = balken pos x
373 local bbx = wowon.game.balken.x
374  
375 -- wenn abprallwinkel zwischen 0 und 90 sein wird
376 if (bx > bbx) then
377 local x = bx-bbx
378 -- prozentualer anteil der länge
379 x = x*100/(bb/2)
380 -- neuer winkel
381 x = 60*(x/100)
382 -- winkel setzen
383 wowon.game.ball[b].w = x
384 --wowon_debug ("b="..b.." w="..x)
385 -- wenn abprallwinkel zwischen 270 und 0 sein wird
386 elseif (bbx > bx) then
387 local x = bbx-bx
388 -- prozentualer anteil der länge
389 x = x*100/(bb/2)
390 -- neuer winkel
391 x = 60*(x/100)
392 -- winkel abziehen
393 x = 360-x
394 -- winkel setzen
395 wowon.game.ball[b].w = x
396 --wowon_debug ("b="..b.." w="..x)
397 else
398 wowon.game.ball[b].w = 0
399 end
400  
401 end