1 -- Hedgewars Bazooka Training |
|
2 -- Scripting Example |
|
3 |
|
4 -- Lines such as this one are comments - they are ignored |
|
5 -- by the game, no matter what kind of text is in there. |
|
6 -- It's also possible to place a comment after some real |
|
7 -- instruction as you see below. In short, everything |
|
8 -- following "--" is ignored. |
|
9 |
|
10 --------------------------------------------------------------- |
|
11 -- At first we put all text we'd like to use in some arrays. |
|
12 -- This way we're able to localize the text to be shown without |
|
13 -- modifying other files. |
|
14 -- The language to be used is stored in the global variable |
|
15 -- 'L' that is set by the game (string). |
|
16 -- Text may then be accessed using "arrayname[L]". |
|
17 |
|
18 local caption = { |
|
19 ["en"] = "Bazooka Training", |
|
20 ["de"] = "Bazooka-Training", |
|
21 ["es"] = "Entrenamiento con bazuca", |
|
22 ["pl"] = "Trening bazooki" |
|
23 -- To add other languages, just add lines similar to the |
|
24 -- existing ones - don't forget the trailing ","! |
|
25 } |
|
26 |
|
27 local subcaption = { |
|
28 ["en"] = "Aiming Practice", |
|
29 ["de"] = "Zielübung", |
|
30 ["es"] = "Practica tu puntería", |
|
31 ["pl"] = "Potrenuj celność" |
|
32 } |
|
33 |
|
34 local goal = { |
|
35 ["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.", |
|
36 ["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.", |
|
37 ["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada.", |
|
38 ["pl"] = "Zniszcz wszystkie cele zanim upłynie czas.|W tej misji masz nieskończoną ilość amunicji." |
|
39 } |
|
40 |
|
41 local timeout = { |
|
42 ["en"] = "Oh no! Time's up! Just try again.", |
|
43 ["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.", |
|
44 ["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?", |
|
45 ["pl"] = "Ajajaj! Koniec czasu! Spróbuj jeszcze raz." |
|
46 } |
|
47 |
|
48 local success = { |
|
49 ["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.", |
|
50 ["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.", |
|
51 ["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido.", |
|
52 ["pl"] = "Gratulacje! Zniszczyłeś przed czasem wszystkie cele." |
|
53 } |
|
54 |
|
55 local teamname = { |
|
56 ["en"] = "'Zooka Team", |
|
57 ["de"] = "Die Knalltüten", |
|
58 ["es"] = "Bazuqueros", |
|
59 ["pl"] = "Bazookinierzy", |
|
60 } |
|
61 |
|
62 local hogname = { |
|
63 ["en"] = "Hunter", |
|
64 ["de"] = "Jäger", |
|
65 ["es"] = "Artillero", |
|
66 ["pl"] = "Strzelec" |
|
67 } |
|
68 |
|
69 -- To handle missing texts we define a small wrapper function that |
|
70 -- we'll use to retrieve text. |
|
71 local function loc(text) |
|
72 if text == nil then return "**missing**" |
|
73 elseif text[L] == nil then return text["en"] |
|
74 else return text[L] |
|
75 end |
|
76 end |
|
77 |
|
78 --------------------------------------------------------------- |
|
79 |
|
80 -- This variable will hold the number of destroyed targets. |
|
81 local score = 0 |
|
82 -- This variable represents the number of targets to destroy. |
|
83 local score_goal = 5 |
|
84 -- This variable controls how many milliseconds/ticks we'd |
|
85 -- like to wait before we end the round once all targets |
|
86 -- have been destroyed. |
|
87 local end_timer = 5000 -- 5000 ms = 5 s |
|
88 -- This variable is set to true if the game is lost (i.e. |
|
89 -- time runs out). |
|
90 local game_lost = false |
|
91 -- This variable will point to the hog's gear |
|
92 local player = nil |
|
93 -- This variable will grab the time left at the end of the round |
|
94 local time_goal = 0 |
|
95 |
|
96 -- This is a custom function to make it easier to |
|
97 -- spawn more targets with just one line of code |
|
98 -- You may define as many custom functions as you |
|
99 -- like. |
|
100 function spawnTarget() |
|
101 -- add a new target gear |
|
102 gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0) |
|
103 |
|
104 -- move it to a random position within 0 and |
|
105 -- LAND_WIDTH - the width of the map |
|
106 FindPlace(gear, true, 0, LAND_WIDTH) |
|
107 |
|
108 -- move the target to a higher vertical position |
|
109 -- to ensure it's not somewhere down below |
|
110 x, y = GetGearPosition(gear) |
|
111 SetGearPosition(gear, x, 500) |
|
112 end |
|
113 |
|
114 -- This function is called before the game loads its |
|
115 -- resources. |
|
116 -- It's one of the predefined function names that will |
|
117 -- be called by the game. They give you entry points |
|
118 -- where you're able to call your own code using either |
|
119 -- provided instructions or custom functions. |
|
120 function onGameInit() |
|
121 -- At first we have to overwrite/set some global variables |
|
122 -- that define the map, the game has to load, as well as |
|
123 -- other things such as the game rules to use, etc. |
|
124 -- Things we don't modify here will use their default values. |
|
125 |
|
126 -- The base number for the random number generator |
|
127 Seed = 0 |
|
128 -- Game settings and rules |
|
129 GameFlags = gfMultiWeapon + gfOneClanMode + gfSolidLand |
|
130 -- The time the player has to move each round (in ms) |
|
131 TurnTime = 60000 |
|
132 -- The frequency of crate drops |
|
133 CaseFreq = 0 |
|
134 -- The number of mines being placed |
|
135 LandAdds = 0 |
|
136 -- The number of explosives being placed |
|
137 Explosives = 0 |
|
138 -- The delay between each round |
|
139 Delay = 0 |
|
140 -- The map to be played |
|
141 Map = "Bamboo" |
|
142 -- The theme to be used |
|
143 Theme = "Bamboo" |
|
144 |
|
145 -- Create the player team |
|
146 AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default") |
|
147 -- And add a hog to it |
|
148 player = AddHog(loc(hogname), 0, 1, "NoHat") |
|
149 SetGearPosition(player, 1960, 1160); |
|
150 end |
|
151 |
|
152 -- This function is called when the round starts |
|
153 -- it spawns the first target that has to be destroyed. |
|
154 -- In addition it shows the scenario goal(s). |
|
155 function onGameStart() |
|
156 -- Spawn the first target. |
|
157 spawnTarget() |
|
158 |
|
159 -- Show some nice mission goals. |
|
160 -- Parameters are: caption, sub caption, description, |
|
161 -- extra text, icon and time to show. |
|
162 -- A negative icon parameter (-n) represents the n-th weapon icon |
|
163 -- A positive icon paramter (n) represents the (n+1)-th mission icon |
|
164 -- A timeframe of 0 is replaced with the default time to show. |
|
165 ShowMission(loc(caption), loc(subcaption), loc(goal), -amBazooka, 0); |
|
166 end |
|
167 |
|
168 -- This function is called every game tick. |
|
169 -- Note that there are 1000 ticks within one second. |
|
170 -- You shouldn't try to calculate too complicated |
|
171 -- code here as this might slow down your game. |
|
172 function onGameTick() |
|
173 -- If time's up, set the game to be lost. |
|
174 -- We actually check the time to be "1 ms" as it |
|
175 -- will be at "0 ms" right at the start of the game. |
|
176 if TurnTimeLeft == 1 and score < score_goal then |
|
177 game_lost = true |
|
178 -- ... and show a short message. |
|
179 ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0); |
|
180 -- How about killing our poor hog due to his poor performance? |
|
181 SetHealth(player, 0); |
|
182 -- Just to be sure set the goal time to 1 ms |
|
183 time_goal = 1 |
|
184 end |
|
185 -- If the goal is reached or we've lost ... |
|
186 if score == score_goal or game_lost then |
|
187 -- ... check to see if the time we'd like to |
|
188 -- wait has passed and then ... |
|
189 if end_timer == 0 then |
|
190 -- ... end the game ... |
|
191 EndGame() |
|
192 else |
|
193 -- ... or just lower the timer by 1. |
|
194 end_timer = end_timer - 1 |
|
195 -- Reset the time left to stop the timer |
|
196 TurnTimeLeft = time_goal |
|
197 end |
|
198 end |
|
199 end |
|
200 |
|
201 -- This function is called when the game is initialized |
|
202 -- to request the available ammo and probabilities |
|
203 function onAmmoStoreInit() |
|
204 -- add an unlimited supply of bazooka ammo |
|
205 SetAmmo(amBazooka, 9, 0, 0) |
|
206 end |
|
207 |
|
208 -- This function is called when a new gear is added. |
|
209 -- We don't need it for this training, so we can |
|
210 -- keep it empty. |
|
211 function onGearAdd(gear) |
|
212 end |
|
213 |
|
214 -- This function is called before a gear is destroyed. |
|
215 -- We use it to count the number of targets destroyed. |
|
216 function onGearDelete(gear) |
|
217 -- We're only interested in target gears. |
|
218 if GetGearType(gear) == gtTarget then |
|
219 -- Add one point to our score/counter |
|
220 score = score + 1 |
|
221 -- If we haven't reached the goal ... |
|
222 if score < score_goal then |
|
223 -- ... spawn another target. |
|
224 spawnTarget() |
|
225 else |
|
226 if not game_lost then |
|
227 -- Otherwise show that the goal was accomplished |
|
228 ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0); |
|
229 -- Also let the hogs shout "victory!" |
|
230 PlaySound(sndVictory) |
|
231 -- Save the time left so we may keep it. |
|
232 time_goal = TurnTimeLeft |
|
233 end |
|
234 end |
|
235 end |
|
236 end |
|