|
1 |
|
2 -- taken from http://code.google.com/p/hedgewars/wiki/LuaDrawing |
|
3 PointsBuffer = '' -- A string to accumulate points in |
|
4 function AddPoint(x, y, width, erase) |
|
5 PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff)) |
|
6 if width then |
|
7 width = bor(width,0x80) |
|
8 if erase then |
|
9 width = bor(width,0x40) |
|
10 end |
|
11 PointsBuffer = PointsBuffer .. string.char(width) |
|
12 else |
|
13 PointsBuffer = PointsBuffer .. string.char(0) |
|
14 end |
|
15 if #PointsBuffer > 245 then |
|
16 ParseCommand('draw '..PointsBuffer) |
|
17 PointsBuffer = '' |
|
18 end |
|
19 end |
|
20 function FlushPoints() |
|
21 if #PointsBuffer > 0 then |
|
22 ParseCommand('draw '..PointsBuffer) |
|
23 PointsBuffer = '' |
|
24 end |
|
25 end |
|
26 |
|
27 |
|
28 local ta_pointsize = 63 |
|
29 local ta_radius = (ta_pointsize * 10 + 6) / 2 |
|
30 |
|
31 local sqrttwo = math.sqrt(2) |
|
32 |
|
33 -- creates round test area |
|
34 function AddTestArea(testarea) |
|
35 step = 100 |
|
36 xstep = step * testarea["xdir"] |
|
37 ystep = step * testarea["ydir"] |
|
38 x = testarea["x"] |
|
39 y = testarea["y"] |
|
40 if xstep * ystep ~= 0 then |
|
41 xstep = math.floor(xstep / sqrttwo) |
|
42 ystep = math.floor(ystep / sqrttwo) |
|
43 end |
|
44 AddPoint(x, y, ta_pointsize); |
|
45 AddPoint(x + xstep, y + ystep, ta_pointsize, true); |
|
46 end |
|
47 |
|
48 -- vertical test areas |
|
49 local taa_v1 = {x= 350, y= 400, xdir= 0, ydir= 1} |
|
50 local taa_v2 = {x= 350, y=1500, xdir= 0, ydir=-1} |
|
51 -- horizontal test areas |
|
52 local taa_h1 = {x=1150, y= 400, xdir= 1, ydir= 0} |
|
53 local taa_h2 = {x=1200, y=1100, xdir=-1, ydir= 0} |
|
54 -- diagonal test areas |
|
55 local taa_d1 = {x=2200, y= 400, xdir= 1, ydir= 1} |
|
56 local taa_d2 = {x=2000, y=1500, xdir= 1, ydir=-1} |
|
57 local taa_d3 = {x=3300, y= 400, xdir=-1, ydir= 1} |
|
58 local taa_d4 = {x=3300, y=1500, xdir=-1, ydir=-1} |
|
59 |
|
60 -- fail counter |
|
61 local nfailed = 0 |
|
62 local nspawned = 0 |
|
63 local ndied = 0 |
|
64 |
|
65 function onGameInit() |
|
66 -- At first we have to overwrite/set some global variables |
|
67 -- that define the map, the game has to load, as well as |
|
68 -- other things such as the game rules to use, etc. |
|
69 -- Things we don't modify here will use their default values. |
|
70 |
|
71 -- The base number for the random number generator |
|
72 Seed = 1 |
|
73 -- The map to be played |
|
74 MapGen = 2 |
|
75 -- The theme to be used |
|
76 Theme = "Bamboo" |
|
77 -- Game settings and rules |
|
78 EnableGameFlags(gfOneClanMode, gfDisableWind, gfDisableLandObjects, gfDisableGirders, gfSolidLand) |
|
79 CaseFreq = 0 |
|
80 MinesNum = 0 |
|
81 Explosives = 0 |
|
82 |
|
83 -- No damage please |
|
84 DamagePercent = 1 |
|
85 |
|
86 -- Draw Map |
|
87 AddPoint(10,30,0) -- hog spawn platform |
|
88 -- test areas |
|
89 AddTestArea(taa_v1) |
|
90 AddTestArea(taa_v2) |
|
91 AddTestArea(taa_h1) |
|
92 AddTestArea(taa_h2) |
|
93 AddTestArea(taa_d1) |
|
94 AddTestArea(taa_d2) |
|
95 AddTestArea(taa_d3) |
|
96 AddTestArea(taa_d4) |
|
97 |
|
98 FlushPoints() |
|
99 |
|
100 -- Create the player team |
|
101 AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default") |
|
102 -- And add a hog to it |
|
103 player = AddHog("Hunter", 0, 1, "NoHat") |
|
104 -- place it on how spawn platform |
|
105 SetGearPosition(player, 10, 10) |
|
106 end |
|
107 |
|
108 -- xdir/ydir is direction in which to fire the drills |
|
109 function SpawnDrillRocketArray(testarea) |
|
110 xdir = testarea["xdir"] |
|
111 ydir = testarea["ydir"] |
|
112 centerx = testarea["x"] |
|
113 centery = testarea["y"] |
|
114 distance = 23 |
|
115 d = distance |
|
116 radius = ta_radius |
|
117 speed = 900000; |
|
118 local xmin, xmax, ymin, ymax |
|
119 if (xdir ~= 0) and (ydir ~= 0) then |
|
120 d = d / sqrttwo |
|
121 radius = radius / sqrttwo |
|
122 speed = math.floor(speed / sqrttwo) |
|
123 end |
|
124 centerx = centerx - (xdir * (radius + 20)) |
|
125 centery = centery - (ydir * (radius + 20)) |
|
126 radius = radius - 6 |
|
127 xn = ydir |
|
128 yn = -xdir |
|
129 startx = centerx - (radius * xn) |
|
130 starty = centery - (radius * yn) |
|
131 endx = centerx + (radius * xn) |
|
132 endy = centery + (radius * yn) |
|
133 |
|
134 -- spawn loop |
|
135 x = startx |
|
136 y = starty |
|
137 xd = d * xn |
|
138 yd = d * yn |
|
139 if (xd < 0) and (startx < endx) then x = endx end |
|
140 if (yd < 0) and (starty < endy) then y = endy end |
|
141 nsteps = math.floor(math.max(math.abs(startx - endx),math.abs(starty - endy)) / d) |
|
142 for i = 1, nsteps, 1 do |
|
143 AddGear(math.floor(x), math.floor(y), gtDrill, gsttmpFlag * (i % 2), speed * xdir, speed * ydir, 0) |
|
144 nspawned = nspawned + 1 |
|
145 x = x + xd |
|
146 y = y + yd |
|
147 end |
|
148 end |
|
149 |
|
150 function onGearDelete(gear) |
|
151 if GetGearType(gear) == gtDrill then |
|
152 -- the way to check state will change in API at some point |
|
153 if band(GetState(gear), gsttmpFlag) == 0 then |
|
154 -- regular drill rocket |
|
155 if (GetTimer(gear) < 2000) or (GetTimer(gear) > 3000) then |
|
156 nfailed = nfailed + 1 |
|
157 end |
|
158 else |
|
159 -- airstrike drill rocket |
|
160 if GetTimer(gear) > 0 then |
|
161 nfailed = nfailed + 1 |
|
162 end |
|
163 end |
|
164 ndied = ndied + 1 |
|
165 if ndied == nspawned then |
|
166 WriteLnToConsole('TESTRESULT: ' .. nfailed .. ' of ' .. nspawned .. ' drill rockets did not explode as expected') |
|
167 if (nfailed > 0) then |
|
168 EndLuaTest(TEST_FAILED) |
|
169 else |
|
170 EndLuaTest(TEST_SUCCESSFUL) |
|
171 end |
|
172 end |
|
173 end |
|
174 end |
|
175 |
|
176 function onGameStart() |
|
177 SetGravity(1) |
|
178 |
|
179 SpawnDrillRocketArray(taa_h1) |
|
180 SpawnDrillRocketArray(taa_h2) |
|
181 SpawnDrillRocketArray(taa_v1) |
|
182 SpawnDrillRocketArray(taa_v2) |
|
183 SpawnDrillRocketArray(taa_d1) |
|
184 SpawnDrillRocketArray(taa_d2) |
|
185 SpawnDrillRocketArray(taa_d3) |
|
186 SpawnDrillRocketArray(taa_d4) |
|
187 end |
|
188 |