share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua
changeset 12727 23fb2179945f
parent 12346 fb22caa19600
child 12728 745d5c9a3abc
equal deleted inserted replaced
12726:54300512e742 12727:23fb2179945f
    18 -- This variable will hold the number of destroyed targets.
    18 -- This variable will hold the number of destroyed targets.
    19 local score = 0
    19 local score = 0
    20 -- This variable will hold the number of shots from the sniper rifle
    20 -- This variable will hold the number of shots from the sniper rifle
    21 local shots = 0
    21 local shots = 0
    22 -- This variable represents the number of targets to destroy.
    22 -- This variable represents the number of targets to destroy.
    23 local score_goal = 31
    23 local score_goal = 27
    24 -- This variable controls how many milliseconds/ticks we'd
    24 -- This variable controls how many milliseconds/ticks we'd
    25 -- like to wait before we end the round once all targets
    25 -- like to wait before we end the round once all targets
    26 -- have been destroyed.
    26 -- have been destroyed.
    27 local end_timer = 1000 -- 1000 ms = 1 s
    27 local end_timer = 1000 -- 1000 ms = 1 s
    28 -- This variable is set to true if the game is lost (i.e.
    28 -- This variable is set to true if the game is lost (i.e.
    29 -- time runs out).
    29 -- time runs out).
    30 local game_lost = false
    30 local game_lost = false
    31 -- This variable will point to the hog's gear
    31 -- This variable will point to the hog's gear
    32 local player = nil
    32 local player = nil
       
    33 -- Current target gear
       
    34 local target = nil
    33 -- This variable will grab the time left at the end of the round
    35 -- This variable will grab the time left at the end of the round
    34 local time_goal = 0
    36 local time_goal = 0
    35 
    37 
    36 local target = nil
    38 -- Like score, but targets before a blow-up sequence count double.
       
    39 -- Used to calculate final target score
       
    40 local score_bonus = 0
    37 
    41 
    38 local last_hit_time = 0
    42 local last_hit_time = 0
    39 
    43 
    40 local cinematic = false
    44 local cinematic = false
       
    45 
       
    46 -- Number of dynamite gears currently in game
       
    47 local dynamiteCounter = 0
       
    48 
       
    49 -- Position for delayed targets
       
    50 local delayedTargetTargetX, delayedTargetY
    41 
    51 
    42 -- This is a custom function to make it easier to
    52 -- This is a custom function to make it easier to
    43 -- spawn more targets with just one line of code
    53 -- spawn more targets with just one line of code
    44 -- You may define as many custom functions as you
    54 -- You may define as many custom functions as you
    45 -- like.
    55 -- like.
       
    56 
       
    57 -- Spawns a target at (x, y)
    46 function spawnTarget(x, y)
    58 function spawnTarget(x, y)
    47 	-- add a new target gear
    59 	-- add a new target gear
    48 	target = AddGear(x, y, gtTarget, 0, 0, 0, 0)
    60 	target = AddGear(x, y, gtTarget, 0, 0, 0, 0)
    49 	-- have the camera move to the target so the player knows where it is
    61 	-- have the camera move to the target so the player knows where it is
    50 	FollowGear(target)
    62 	FollowGear(target)
    51 end
    63 end
    52 
    64 
       
    65 -- Remembers position to spawn a target at (x, y) after a dynamite explosion
       
    66 function spawnTargetDelayed(x, y)
       
    67 	delayedTargetX = x
       
    68 	delayedTargetY = y
       
    69 end
       
    70 
       
    71 -- Cut sequence to blow up land with dynamite
    53 function blowUp(x, y)
    72 function blowUp(x, y)
    54     if cinematic == false then
    73 	if cinematic == false then
    55         cinematic = true
    74 		cinematic = true
    56         SetCinematicMode(true)
    75 		SetCinematicMode(true)
    57     end
    76 	end
    58 	-- adds some TNT
    77 	AddGear(x, y, gtDynamite, 0, 0, 0, 0)
    59 	gear = AddGear(x, y, gtDynamite, 0, 0, 0, 0)
       
    60 end
    78 end
    61 
    79 
    62 function onNewTurn()
    80 function onNewTurn()
    63 	SetWeapon(amSniperRifle)
    81 	SetWeapon(amSniperRifle)
    64 end
    82 end
   180 -- We use it to count the number of shots, which we
   198 -- We use it to count the number of shots, which we
   181 -- in turn use to calculate the final score and stats
   199 -- in turn use to calculate the final score and stats
   182 function onGearAdd(gear)
   200 function onGearAdd(gear)
   183 	if GetGearType(gear) == gtSniperRifleShot then
   201 	if GetGearType(gear) == gtSniperRifleShot then
   184 		shots = shots + 1
   202 		shots = shots + 1
       
   203 	elseif GetGearType(gear) == gtDynamite then
       
   204 		dynamiteCounter = dynamiteCounter + 1
   185 	end
   205 	end
   186 end
   206 end
   187 
   207 
   188 -- This function is called before a gear is destroyed.
   208 -- This function is called before a gear is destroyed.
   189 -- We use it to count the number of targets destroyed.
   209 -- We use it to count the number of targets destroyed.
   193 	if gt == gtCase then
   213 	if gt == gtCase then
   194 		game_lost = true
   214 		game_lost = true
   195 		return
   215 		return
   196 	end
   216 	end
   197 
   217 
   198 	if (gt == gtDynamite) and cinematic then
   218 	if (gt == gtDynamite) then
   199 		cinematic = false
   219 		-- Dynamite blow-up, used to continue the game.
   200 		SetCinematicMode(false)
   220 		dynamiteCounter = dynamiteCounter - 1
       
   221 
       
   222 		-- Wait for all dynamites to be destroyed before we continue.
       
   223 		-- Most cut scenes spawn multiple dynamites.
       
   224 		if dynamiteCounter == 0 then
       
   225 			if cinematic then
       
   226 				cinematic = false
       
   227 				SetCinematicMode(false)
       
   228 			end
       
   229 			-- Add bonus score for the previuos target
       
   230 			score_bonus = score_bonus + 1
       
   231 			-- Now *actually* spawn the delayed target
       
   232 			spawnTarget(delayedTargetX, delayedTargetY)
       
   233 		end
   201 		return
   234 		return
   202 	end
   235 	end
   203 
   236 
   204 	if gt == gtTarget then
   237 	if gt == gtTarget then
       
   238 		target = nil
   205 		-- remember when the target was hit for adjusting the camera
   239 		-- remember when the target was hit for adjusting the camera
   206 		last_hit_time = TurnTimeLeft
   240 		last_hit_time = TurnTimeLeft
   207 		-- Add one point to our score/counter
   241 		-- Add one point to our score/counter
   208 		score = score + 1
   242 		score = score + 1
       
   243 		score_bonus = score_bonus + 1
   209 		-- If we haven't reached the goal ...
   244 		-- If we haven't reached the goal ...
   210 		if score < score_goal then
   245 		if score < score_goal then
   211 			-- ... spawn another target.
   246 			-- ... spawn another target.
   212 			if score == 1 then
   247 			if score == 1 then
   213 				spawnTarget(1520,1350)
   248 				spawnTarget(1520,1350)
   214 			elseif score == 2 then
   249 			elseif score == 2 then
   215 				spawnTarget(1730,1040)
   250 				spawnTarget(1730,1040)
   216 			elseif score == 3 then
   251 			elseif score == 3 then
   217 				spawnTarget(2080,780)
   252 				spawnTarget(2080,780)
   218 			elseif score == 4 then
   253 			elseif score == 4 then
       
   254 				-- Short cut scene, blows up up lots up land and prepares
       
   255 				-- next target position.
   219 				AddCaption(loc("Good so far!") .. " " .. loc("Keep it up!"));
   256 				AddCaption(loc("Good so far!") .. " " .. loc("Keep it up!"));
   220 				blowUp(1730,1226)
   257 				blowUp(1730,1226)
   221 				blowUp(1440,1595)
   258 				blowUp(1440,1595)
   222 				blowUp(1527,1575)
   259 				blowUp(1527,1575)
   223 				blowUp(1614,1595)
   260 				blowUp(1614,1595)
   225 				blowUp(1527,1675)
   262 				blowUp(1527,1675)
   226 				blowUp(1634,1675)
   263 				blowUp(1634,1675)
   227 				blowUp(1440,1755)
   264 				blowUp(1440,1755)
   228 				blowUp(1527,1775)
   265 				blowUp(1527,1775)
   229 				blowUp(1614,1755)
   266 				blowUp(1614,1755)
   230 				spawnTarget(1527,1667)
   267 				-- Target appears *after* the cutscene.
       
   268 				spawnTargetDelayed(1527,1667)
   231 			elseif score == 5 then
   269 			elseif score == 5 then
   232 				spawnTarget(1527,1667)
   270 				spawnTarget(2175,1300)
   233 			elseif score == 6 then
   271 			elseif score == 6 then
   234 				spawnTarget(2175,1300)
   272 				spawnTarget(2250,940)
   235 			elseif score == 7 then
   273 			elseif score == 7 then
   236 				spawnTarget(2250,940)
   274 				spawnTarget(2665,1540)
   237 			elseif score == 8 then
   275 			elseif score == 8 then
   238 				spawnTarget(2665,1540)
   276 				spawnTarget(3040,1160)
   239 			elseif score == 9 then
   277 			elseif score == 9 then
   240 				spawnTarget(3040,1160)
   278 				spawnTarget(2930,1500)
   241 			elseif score == 10 then
   279 			elseif score == 10 then
   242 				spawnTarget(2930,1500)
       
   243 			elseif score == 11 then
       
   244 				AddCaption(loc("This one's tricky."));
   280 				AddCaption(loc("This one's tricky."));
   245 				spawnTarget(700,720)
   281 				spawnTarget(700,720)
   246 			elseif score == 12 then
   282 			elseif score == 11 then
   247 				AddCaption(loc("Well done."));
   283 				AddCaption(loc("Well done."));
   248 				blowUp(914,1222)
   284 				blowUp(914,1222)
   249 				blowUp(1050,1222)
   285 				blowUp(1050,1222)
   250 				blowUp(1160,1008)
   286 				blowUp(1160,1008)
   251 				blowUp(1160,1093)
   287 				blowUp(1160,1093)
   255 				blowUp(640,911)
   291 				blowUp(640,911)
   256 				blowUp(780,911)
   292 				blowUp(780,911)
   257 				blowUp(920,911)
   293 				blowUp(920,911)
   258 				blowUp(1060,913)
   294 				blowUp(1060,913)
   259 				blowUp(1198,913)
   295 				blowUp(1198,913)
   260 				spawnTarget(1200,730)
   296 				spawnTargetDelayed(1200,830)
       
   297 			elseif score == 12 then
       
   298 				spawnTarget(1430,450)
   261 			elseif score == 13 then
   299 			elseif score == 13 then
   262 				spawnTarget(1200,830)
   300 				spawnTarget(796,240)
   263 			elseif score == 14 then
   301 			elseif score == 14 then
   264 				spawnTarget(1430,450)
   302 				spawnTarget(300,10)
   265 			elseif score == 15 then
   303 			elseif score == 15 then
   266 				spawnTarget(796,240)
   304 				spawnTarget(2080,820)
   267 			elseif score == 16 then
   305 			elseif score == 16 then
   268 				spawnTarget(300,10)
       
   269 			elseif score == 17 then
       
   270 				spawnTarget(2080,820)
       
   271 			elseif score == 18 then
       
   272 				AddCaption(loc("Demolition is fun!"));
   306 				AddCaption(loc("Demolition is fun!"));
   273 				blowUp(2110,920)
   307 				blowUp(2110,920)
   274 				blowUp(2210,920)
   308 				blowUp(2210,920)
   275 				blowUp(2200,305)
   309 				blowUp(2200,305)
   276 				blowUp(2300,305)
   310 				blowUp(2300,305)
   281 				blowUp(2300,800)
   315 				blowUp(2300,800)
   282 				blowUp(2300,900)
   316 				blowUp(2300,900)
   283 				blowUp(2401,305)
   317 				blowUp(2401,305)
   284 				blowUp(2532,305)
   318 				blowUp(2532,305)
   285 				blowUp(2663,305)
   319 				blowUp(2663,305)
   286 				spawnTarget(2300,760)
   320 				spawnTargetDelayed(2300,760)
       
   321 			elseif score == 17 then
       
   322 				spawnTarget(2738,190)
       
   323 			elseif score == 18 then
       
   324 				spawnTarget(2590,-100)
   287 			elseif score == 19 then
   325 			elseif score == 19 then
   288 				spawnTarget(2300,760)
       
   289 			elseif score == 20 then
       
   290 				spawnTarget(2738,190)
       
   291 			elseif score == 21 then
       
   292 				spawnTarget(2590,-100)
       
   293 			elseif score == 22 then
       
   294 				AddCaption(loc("Will this ever end?"));
   326 				AddCaption(loc("Will this ever end?"));
   295 				blowUp(2790,305)
   327 				blowUp(2790,305)
   296 				blowUp(2930,305)
   328 				blowUp(2930,305)
   297 				blowUp(3060,305)
   329 				blowUp(3060,305)
   298 				blowUp(3190,305)
   330 				blowUp(3190,305)
   304 				blowUp(2805,760)
   336 				blowUp(2805,760)
   305 				blowUp(2805,890)
   337 				blowUp(2805,890)
   306 				blowUp(3258,370)
   338 				blowUp(3258,370)
   307 				blowUp(3258,475)
   339 				blowUp(3258,475)
   308 				blowUp(3264,575)
   340 				blowUp(3264,575)
   309 				spawnTarget(3230,240)
   341 				spawnTargetDelayed(3230,290)
       
   342 			elseif score == 20 then
       
   343 				spawnTarget(3670,250)
       
   344 			elseif score == 21 then
       
   345 				spawnTarget(2620,-100)
       
   346 			elseif score == 22 then
       
   347 				spawnTarget(2870,300)
   310 			elseif score == 23 then
   348 			elseif score == 23 then
   311 				spawnTarget(3230,290)
   349 				spawnTarget(3850,900)
   312 			elseif score == 24 then
   350 			elseif score == 24 then
   313 				spawnTarget(3670,250)
   351 				spawnTarget(3780,300)
   314 			elseif score == 25 then
   352 			elseif score == 25 then
   315 				spawnTarget(2620,-100)
   353 				spawnTarget(3670,0)
   316 			elseif score == 26 then
   354 			elseif score == 26 then
   317 				spawnTarget(2870,300)
       
   318 			elseif score == 27 then
       
   319 				spawnTarget(3850,900)
       
   320 			elseif score == 28 then
       
   321 				spawnTarget(3780,300)
       
   322 			elseif score == 29 then
       
   323 				spawnTarget(3670,0)
       
   324 			elseif score == 30 then
       
   325 				AddCaption(loc("Last Target!"));
   355 				AddCaption(loc("Last Target!"));
   326 				spawnTarget(3480,1200)
   356 				spawnTarget(3480,1200)
   327 			end
   357 			end
   328 		else
   358 		else
   329 			if not game_lost then
   359 			if not game_lost then
   340 
   370 
   341 -- This function calculates the final score of the player and provides some texts and
   371 -- This function calculates the final score of the player and provides some texts and
   342 -- data for the final stats screen
   372 -- data for the final stats screen
   343 function generateStats()
   373 function generateStats()
   344 	local accuracy = (score/shots)*100
   374 	local accuracy = (score/shots)*100
   345 	local end_score_targets = (score * 200)
   375 	local end_score_targets = (score_bonus * 200)
   346 	local end_score_overall
   376 	local end_score_overall
   347 	if not game_lost then
   377 	if not game_lost then
   348 		local end_score_time = math.ceil(time_goal/5)
   378 		local end_score_time = math.ceil(time_goal/5)
   349 		local end_score_accuracy = math.ceil(accuracy * 100)
   379 		local end_score_accuracy = math.ceil(accuracy * 100)
   350 		end_score_overall = end_score_time + end_score_targets + end_score_accuracy
   380 		end_score_overall = end_score_time + end_score_targets + end_score_accuracy
   362 		end_score_overall = end_score_targets
   392 		end_score_overall = end_score_targets
   363 	end
   393 	end
   364 	SendStat(siPointType, loc("points"))
   394 	SendStat(siPointType, loc("points"))
   365 	SendStat(siPlayerKills, tostring(end_score_overall), loc("Sniperz"))
   395 	SendStat(siPlayerKills, tostring(end_score_overall), loc("Sniperz"))
   366 end
   396 end
       
   397