share/hedgewars/Data/Missions/Shotgun Training.hwt
changeset 2816 30fc14a79aa0
parent 2815 c1daf1213cbe
child 2949 d137a9da7701
equal deleted inserted replaced
2815:c1daf1213cbe 2816:30fc14a79aa0
    20 -- This variable is set to true if the game is lost (i.e.
    20 -- This variable is set to true if the game is lost (i.e.
    21 -- time runs out).
    21 -- time runs out).
    22 local game_lost = false
    22 local game_lost = false
    23 -- This variable will point to the hog's gear
    23 -- This variable will point to the hog's gear
    24 local player = nil
    24 local player = nil
       
    25 -- This variable will grab the time left at the end of the round
       
    26 local time_goal = 0
    25 
    27 
    26 -- This is a custom function to make it easier to
    28 -- This is a custom function to make it easier to
    27 -- spawn more targets with just one line of code
    29 -- spawn more targets with just one line of code
    28 -- You may define as many custom functions as you
    30 -- You may define as many custom functions as you
    29 -- like.
    31 -- like.
   105 		game_lost = true
   107 		game_lost = true
   106 		-- ... and show a short message.
   108 		-- ... and show a short message.
   107 		ShowMission("Shotgun Training", "Aiming Practice", "Oh no! Time's up! Just try again.", -amSkip, 0);
   109 		ShowMission("Shotgun 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?
   110 		-- How about killing our poor hog due to his poor performance?
   109 		SetHealth(player, 0);
   111 		SetHealth(player, 0);
       
   112 		-- Just to be sure set the goal time to 1 ms
       
   113 		time_goal = 1
   110 	end
   114 	end
   111 	-- If the goal is reached or we've lost ...
   115 	-- If the goal is reached or we've lost ...
   112 	if score == score_goal or game_lost then
   116 	if score == score_goal or game_lost then
   113 		-- ... check to see if the time we'd like to
   117 		-- ... check to see if the time we'd like to
   114 		-- wait has passed and then ...
   118 		-- wait has passed and then ...
   116 			-- ... end the game ...
   120 			-- ... end the game ...
   117 			EndGame()
   121 			EndGame()
   118 		else
   122 		else
   119 			-- ... or just lower the timer by 1.
   123 			-- ... or just lower the timer by 1.
   120 			end_timer = end_timer - 1
   124 			end_timer = end_timer - 1
       
   125 			-- Reset the time left to stop the timer
       
   126 			TurnTimeLeft = time_goal
   121 		end
   127 		end
   122 	end
   128 	end
   123 end
   129 end
   124 
   130 
   125 -- This function is called when the game is initialized
   131 -- This function is called when the game is initialized
   150 			if not game_lost then
   156 			if not game_lost then
   151 			-- Otherwise show that the goal was accomplished
   157 			-- Otherwise show that the goal was accomplished
   152 			ShowMission("Shotgun Training", "Aiming Practice", "Congratulations! You've eliminated all targets|within the allowed time frame.", 0, 0);
   158 			ShowMission("Shotgun Training", "Aiming Practice", "Congratulations! You've eliminated all targets|within the allowed time frame.", 0, 0);
   153 			-- Also let the hogs shout "victory!"
   159 			-- Also let the hogs shout "victory!"
   154 			PlaySound(sndVictory)
   160 			PlaySound(sndVictory)
       
   161 			-- Save the time left so we may keep it.
       
   162 			time_goal = TurnTimeLeft
   155 			end
   163 			end
   156 		end
   164 		end
   157 	end
   165 	end
   158 end
   166 end