2786
|
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 |
|
|
12 |
-- This variable will hold the number of destroyed targets.
|
2814
|
13 |
local score = 0
|
2786
|
14 |
-- This variable represents the number of targets to destroy.
|
2814
|
15 |
local score_goal = 5
|
2786
|
16 |
-- This variable controls how many milliseconds/ticks we'd
|
|
17 |
-- like to wait before we end the round once all targets
|
|
18 |
-- have been destroyed.
|
2814
|
19 |
local end_timer = 5000 -- 5000 ms = 5 s
|
|
20 |
-- This variable is set to true if the game is lost (i.e.
|
|
21 |
-- time runs out).
|
|
22 |
local game_lost = false
|
|
23 |
-- This variable will point to the hog's gear
|
|
24 |
local player = nil
|
2786
|
25 |
|
|
26 |
-- This is a custom function to make it easier to
|
|
27 |
-- spawn more targets with just one line of code
|
|
28 |
-- You may define as many custom functions as you
|
|
29 |
-- like.
|
|
30 |
function spawnTarget()
|
|
31 |
-- add a new target gear
|
|
32 |
gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
|
|
33 |
|
|
34 |
-- move it to a random position within 0 and
|
|
35 |
-- LAND_WIDTH - the width of the map
|
|
36 |
FindPlace(gear, true, 0, LAND_WIDTH)
|
|
37 |
|
|
38 |
-- move the target to a higher vertical position
|
|
39 |
-- to ensure it's not somewhere down below
|
|
40 |
x, y = GetGearPosition(gear)
|
|
41 |
SetGearPosition(gear, x, 500)
|
|
42 |
end
|
|
43 |
|
|
44 |
-- This function is called before the game loads its
|
|
45 |
-- resources.
|
|
46 |
-- It's one of the predefined function names that will
|
|
47 |
-- be called by the game. They give you entry points
|
|
48 |
-- where you're able to call your own code using either
|
|
49 |
-- provided instructions or custom functions.
|
|
50 |
function onGameInit()
|
|
51 |
-- At first we have to overwrite/set some global variables
|
|
52 |
-- that define the map, the game has to load, as well as
|
|
53 |
-- other things such as the game rules to use, etc.
|
|
54 |
-- Things we don't modify here will use their default values.
|
|
55 |
|
|
56 |
-- The base number for the random number generator
|
2790
|
57 |
Seed = 0
|
2786
|
58 |
-- Game settings and rules
|
|
59 |
GameFlags = gfMultiWeapon + gfOneClanMode + gfSolidLand
|
|
60 |
-- The time the player has to move each round (in ms)
|
2815
|
61 |
TurnTime = 60000
|
2786
|
62 |
-- The frequency of crate drops
|
|
63 |
CaseFreq = 0
|
|
64 |
-- The number of land objects being placed
|
|
65 |
LandAdds = 0
|
|
66 |
-- The delay between each round
|
|
67 |
Delay = 0
|
|
68 |
-- The map to be played
|
|
69 |
Map = "Bamboo"
|
|
70 |
-- The theme to be used
|
|
71 |
Theme = "Bamboo"
|
|
72 |
|
|
73 |
-- Create the player team
|
|
74 |
AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default")
|
|
75 |
-- And add a hog to it
|
2814
|
76 |
player = AddHog("Hunter", 0, 1, "NoHat")
|
|
77 |
SetGearPosition(player, 1960, 1160);
|
2786
|
78 |
end
|
|
79 |
|
|
80 |
-- This function is called when the round starts
|
|
81 |
-- it spawns the first target that has to be destroyed.
|
|
82 |
-- In addition it shows the scenario goal(s).
|
|
83 |
function onGameStart()
|
|
84 |
-- Spawn the first target.
|
|
85 |
spawnTarget()
|
|
86 |
|
|
87 |
-- Show some nice mission goals.
|
|
88 |
-- Parameters are: caption, sub caption, description,
|
|
89 |
-- extra text, icon and time to show.
|
|
90 |
-- A negative icon parameter (-n) represents the n-th weapon icon
|
|
91 |
-- A positive icon paramter (n) represents the (n+1)-th mission icon
|
|
92 |
-- A timeframe of 0 is replaced with the default time to show.
|
|
93 |
ShowMission("Bazooka Training", "Aiming Practice", "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.", -amBazooka, 0);
|
|
94 |
end
|
|
95 |
|
|
96 |
-- This function is called every game tick.
|
|
97 |
-- Note that there are 1000 ticks within one second.
|
|
98 |
-- You shouldn't try to calculate too complicated
|
|
99 |
-- code here as this might slow down your game.
|
|
100 |
function onGameTick()
|
2814
|
101 |
-- If time's up, set the game to be lost.
|
|
102 |
-- We actually check the time to be "1 ms" as it
|
|
103 |
-- will be at "0 ms" right at the start of the game.
|
2815
|
104 |
if TurnTimeLeft == 1 and score < score_goal then
|
2814
|
105 |
game_lost = true
|
|
106 |
-- ... and show a short message.
|
|
107 |
ShowMission("Bazooka Training", "Aiming Practice", "Oh no! Time's up! Just try again.", -amSkip, 0);
|
|
108 |
-- How about killing our poor hog due to his poor performance?
|
|
109 |
SetHealth(player, 0);
|
|
110 |
end
|
|
111 |
-- If the goal is reached or we've lost ...
|
|
112 |
if score == score_goal or game_lost then
|
2786
|
113 |
-- ... check to see if the time we'd like to
|
|
114 |
-- wait has passed and then ...
|
|
115 |
if end_timer == 0 then
|
|
116 |
-- ... end the game ...
|
|
117 |
EndGame()
|
|
118 |
else
|
|
119 |
-- ... or just lower the timer by 1.
|
|
120 |
end_timer = end_timer - 1
|
|
121 |
end
|
|
122 |
end
|
|
123 |
end
|
|
124 |
|
|
125 |
-- This function is called when the game is initialized
|
|
126 |
-- to request the available ammo and probabilities
|
|
127 |
function onAmmoStoreInit()
|
|
128 |
-- add an unlimited supply of bazooka ammo
|
|
129 |
SetAmmo(amBazooka, 9, 0)
|
|
130 |
end
|
|
131 |
|
|
132 |
-- This function is called when a new gear is added.
|
|
133 |
-- We don't need it for this training, so we can
|
|
134 |
-- keep it empty.
|
|
135 |
function onGearAdd(gear)
|
|
136 |
end
|
|
137 |
|
|
138 |
-- This function is called before a gear is destroyed.
|
|
139 |
-- We use it to count the number of targets destroyed.
|
|
140 |
function onGearDelete(gear)
|
|
141 |
-- We're only interested in target gears.
|
|
142 |
if GetGearType(gear) == gtTarget then
|
|
143 |
-- Add one point to our score/counter
|
|
144 |
score = score + 1
|
|
145 |
-- If we haven't reached the goal ...
|
|
146 |
if score < score_goal then
|
|
147 |
-- ... spawn another target.
|
|
148 |
spawnTarget()
|
|
149 |
else
|
2814
|
150 |
if not game_lost then
|
2786
|
151 |
-- Otherwise show that the goal was accomplished
|
|
152 |
ShowMission("Bazooka Training", "Aiming Practice", "Congratulations! You've eliminated all targets|within the allowed time frame.", 0, 0);
|
|
153 |
-- Also let the hogs shout "victory!"
|
|
154 |
PlaySound(sndVictory)
|
2814
|
155 |
end
|
2786
|
156 |
end
|
|
157 |
end
|
|
158 |
end |