author | nemo |
Sat, 01 Mar 2014 14:52:36 -0500 | |
changeset 10171 | 00f41ff0bf2d |
parent 10028 | 9e742fc72696 |
child 10421 | 87e47843018e |
permissions | -rw-r--r-- |
10026 | 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 |
-- creates round test area |
|
32 |
function AddTestArea(testarea) |
|
33 |
step = 200 |
|
34 |
xstep = step * testarea["xdir"] |
|
35 |
ystep = step * testarea["ydir"] |
|
36 |
x = testarea["x"] |
|
37 |
y = testarea["y"] |
|
38 |
AddPoint(x, y, ta_pointsize); |
|
39 |
AddPoint(x + xstep, y + ystep); |
|
40 |
end |
|
41 |
||
42 |
-- vertical test areas |
|
43 |
local taa_v1 = {x= 350, y= 400, xdir= 0, ydir= 1} |
|
44 |
local taa_v2 = {x= 350, y=1500, xdir= 0, ydir=-1} |
|
45 |
-- horizontal test areas |
|
46 |
local taa_h1 = {x=1150, y= 400, xdir= 1, ydir= 0} |
|
47 |
local taa_h2 = {x=1200, y=1100, xdir=-1, ydir= 0} |
|
48 |
-- diagonal test areas |
|
49 |
local taa_d1 = {x=2200, y= 400, xdir= 1, ydir= 1} |
|
50 |
local taa_d2 = {x=2000, y=1500, xdir= 1, ydir=-1} |
|
51 |
local taa_d3 = {x=3300, y= 400, xdir=-1, ydir= 1} |
|
52 |
local taa_d4 = {x=3300, y=1500, xdir=-1, ydir=-1} |
|
53 |
||
54 |
-- fail counter |
|
55 |
local nfailed = 0 |
|
56 |
local nspawned = 0 |
|
57 |
local ndied = 0 |
|
58 |
||
59 |
function onGameInit() |
|
60 |
-- At first we have to overwrite/set some global variables |
|
61 |
-- that define the map, the game has to load, as well as |
|
62 |
-- other things such as the game rules to use, etc. |
|
63 |
-- Things we don't modify here will use their default values. |
|
64 |
||
65 |
-- The base number for the random number generator |
|
66 |
Seed = 1 |
|
67 |
-- The map to be played |
|
68 |
MapGen = 2 |
|
69 |
-- The theme to be used |
|
70 |
Theme = "Bamboo" |
|
71 |
-- Game settings and rules |
|
72 |
EnableGameFlags(gfOneClanMode, gfDisableWind, gfDisableLandObjects, gfDisableGirders, gfSolidLand) |
|
73 |
CaseFreq = 0 |
|
74 |
MinesNum = 0 |
|
75 |
Explosives = 0 |
|
76 |
||
77 |
-- No damage please |
|
78 |
DamagePercent = 1 |
|
79 |
||
80 |
-- Draw Map |
|
81 |
AddPoint(10,30,0) -- hog spawn platform |
|
82 |
-- test areas |
|
83 |
AddTestArea(taa_v1) |
|
84 |
AddTestArea(taa_v2) |
|
85 |
AddTestArea(taa_h1) |
|
86 |
AddTestArea(taa_h2) |
|
87 |
AddTestArea(taa_d1) |
|
88 |
AddTestArea(taa_d2) |
|
89 |
AddTestArea(taa_d3) |
|
90 |
AddTestArea(taa_d4) |
|
91 |
||
92 |
FlushPoints() |
|
93 |
||
94 |
-- Create the player team |
|
95 |
AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default") |
|
96 |
-- And add a hog to it |
|
97 |
player = AddHog("Hunter", 0, 1, "NoHat") |
|
98 |
-- place it on how spawn platform |
|
99 |
SetGearPosition(player, 10, 10) |
|
100 |
end |
|
101 |
||
102 |
-- xdir/ydir is direction in which to fire the drills |
|
103 |
function SpawnDrillRocketArray(testarea) |
|
104 |
xdir = testarea["xdir"] |
|
105 |
ydir = testarea["ydir"] |
|
106 |
centerx = testarea["x"] |
|
107 |
centery = testarea["y"] |
|
108 |
distance = 23 |
|
109 |
d = distance |
|
110 |
radius = ta_radius |
|
111 |
local xmin, xmax, ymin, ymax |
|
10028
9e742fc72696
add a test based on unC0Rr's suggestion. still a lot of mess and redundancy involved, sry :P
sheepluva
parents:
10026
diff
changeset
|
112 |
speed = 900000; |
9e742fc72696
add a test based on unC0Rr's suggestion. still a lot of mess and redundancy involved, sry :P
sheepluva
parents:
10026
diff
changeset
|
113 |
local xmin, xmax, ymin, ymax |
10026 | 114 |
if (xdir ~= 0) and (ydir ~= 0) then |
115 |
sqrttwo = math.sqrt(2) |
|
116 |
d = d / sqrttwo |
|
117 |
radius = radius / sqrttwo |
|
10028
9e742fc72696
add a test based on unC0Rr's suggestion. still a lot of mess and redundancy involved, sry :P
sheepluva
parents:
10026
diff
changeset
|
118 |
speed = math.floor(speed / sqrttwo) |
10026 | 119 |
end |
120 |
centerx = centerx - (xdir * (radius + 20)) |
|
121 |
centery = centery - (ydir * (radius + 20)) |
|
122 |
radius = radius - 6 |
|
123 |
xn = ydir |
|
124 |
yn = -xdir |
|
125 |
startx = centerx - (radius * xn) |
|
126 |
starty = centery - (radius * yn) |
|
127 |
endx = centerx + (radius * xn) |
|
128 |
endy = centery + (radius * yn) |
|
129 |
||
130 |
-- spawn loop |
|
131 |
x = startx |
|
132 |
y = starty |
|
133 |
xd = d * xn |
|
134 |
yd = d * yn |
|
135 |
if (xd < 0) and (startx < endx) then x = endx end |
|
136 |
if (yd < 0) and (starty < endy) then y = endy end |
|
137 |
nsteps = math.floor(math.max(math.abs(startx - endx),math.abs(starty - endy)) / d) |
|
138 |
for i = 1, nsteps, 1 do |
|
10028
9e742fc72696
add a test based on unC0Rr's suggestion. still a lot of mess and redundancy involved, sry :P
sheepluva
parents:
10026
diff
changeset
|
139 |
AddGear(math.floor(x), math.floor(y), gtDrill, 0, speed * xdir, speed * ydir, 0) |
10026 | 140 |
nspawned = nspawned + 1 |
141 |
x = x + xd |
|
142 |
y = y + yd |
|
143 |
end |
|
144 |
end |
|
145 |
||
146 |
function onGearDelete(gear) |
|
147 |
if GetGearType(gear) == gtDrill then |
|
148 |
if GetTimer(gear) > 0 then |
|
149 |
nfailed = nfailed + 1 |
|
150 |
end |
|
151 |
ndied = ndied + 1 |
|
152 |
if ndied == nspawned then |
|
153 |
WriteLnToConsole('TESTRESULT: ' .. nfailed .. ' of ' .. nspawned .. ' drill rockets exploded prematurely') |
|
154 |
if (nfailed > 0) then |
|
155 |
EndLuaTest(TEST_FAILED) |
|
156 |
else |
|
157 |
EndLuaTest(TEST_SUCCESSFUL) |
|
158 |
end |
|
159 |
end |
|
160 |
end |
|
161 |
end |
|
162 |
||
163 |
function onGameStart() |
|
164 |
SetGravity(1) |
|
165 |
||
166 |
SpawnDrillRocketArray(taa_h1) |
|
167 |
SpawnDrillRocketArray(taa_h2) |
|
168 |
SpawnDrillRocketArray(taa_v1) |
|
169 |
SpawnDrillRocketArray(taa_v2) |
|
170 |
SpawnDrillRocketArray(taa_d1) |
|
171 |
SpawnDrillRocketArray(taa_d2) |
|
172 |
SpawnDrillRocketArray(taa_d3) |
|
173 |
SpawnDrillRocketArray(taa_d4) |
|
174 |
end |
|
175 |