Created
April 6, 2012 14:00
-
-
Save rnestler/2320010 to your computer and use it in GitHub Desktop.
Hedgewars training level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Hedgewars Ballgun Training | |
loadfile(GetDataPath() .. "Scripts/Locale.lua")() | |
local end_timer = 5000 -- 5000 ms = 5 s | |
local game_finished = false | |
local targets = 3 | |
local ammo = 3 | |
local mission_name = "Ballgun Training" | |
function spawnTarget(round) | |
SetGearPosition( | |
AddGear(0, 0, gtTarget, 0, 0, 0, 0), | |
1800, | |
1500 | |
) | |
SetGearPosition( | |
AddGear(0, 0, gtTarget, 0, 0, 0, 0), | |
1900, | |
1500 | |
) | |
SetGearPosition( | |
AddGear(0, 0, gtTarget, 0, 0, 0, 0), | |
2000, | |
1500 | |
) | |
end | |
function onGameInit() | |
-- At first we have to overwrite/set some global variables | |
-- that define the map, the game has to load, as well as | |
-- other things such as the game rules to use, etc. | |
-- Things we don't modify here will use their default values. | |
-- The base number for the random number generator | |
Seed = 1 | |
-- Game settings and rules | |
GameFlags = gfOneClanMode | |
-- The time the player has to move each round (in ms) | |
TurnTime = 60000 | |
CaseFreq = 0 | |
MinesNum = 0 | |
Explosives = 0 | |
-- The delay between each round | |
Delay = 0 | |
-- The map to be played | |
Map = "Ropes" | |
-- The theme to be used | |
Theme = "City" | |
-- Create the player team | |
AddTeam(loc("Team Ball"), 14483456, "Simple", "Island", "Default") | |
-- And add a hog to it | |
player = AddHog(loc("Hunter"), 0, 1, "NoHat") | |
SetGearPosition(player, 2000, 100) | |
end | |
function onGameStart() | |
-- Spawn the first target. | |
spawnTarget(1) | |
-- Show some nice mission goals. | |
-- Parameters are: caption, sub caption, description, | |
-- extra text, icon and time to show. | |
-- A negative icon parameter (-n) represents the n-th weapon icon | |
-- A positive icon paramter (n) represents the (n+1)-th mission icon | |
-- A timeframe of 0 is replaced with the default time to show. | |
ShowMission(loc(mission_name), loc("Aiming Practice"), string.format(loc("Eliminate all targets with as least shots as possible.|You have only %i shots for this mission."),ammo), -amBallgun, 0) | |
end | |
function onNewTurn() | |
ParseCommand("setweap " .. string.char(amBallgun)) | |
end | |
function onGameTick() | |
if game_finished == true then | |
if end_timer == 0 then | |
EndGame() | |
else | |
end_timer = end_timer - 1 | |
TurnTimeLeft = time_goal | |
end | |
end | |
end | |
function onAttack() | |
ammo = ammo - 1 | |
if ammo <= 0 then | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("Oh no! You run out of ammo! Just try again."), -amSkip, 0) | |
game_finished = true | |
end | |
end | |
function onAmmoStoreInit() | |
-- add three shots of bubble gun ammo | |
SetAmmo(amBallgun, ammo, 0, 0, 1) | |
end | |
function onGearAdd(gear) | |
end | |
function onGearDelete(gear) | |
if GetGearType(gear) == gtTarget then | |
targets = targets - 1 | |
if targets <= 0 then | |
game_finished = true | |
if ammo == 2 then | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets with just one shot!"), 0, 0) | |
elseif ammo == 1 then | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("Nice Job! You've eliminated all targets with two shots!"), 4, 0) | |
else | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("That was thight! You've eliminated all targets with your last shot!"), 2, 0) | |
end | |
PlaySound(sndVictory) | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Hedgewars Ballgun Training | |
loadfile(GetDataPath() .. "Scripts/Locale.lua")() | |
loadfile(GetDataPath() .. "Scripts/Generic_Training.lua")() | |
local end_timer = 5000 -- 5000 ms = 5 s | |
local game_finished = false | |
local targets = 3 | |
local ammo = 3 | |
local mission_name = "Ballgun Training" | |
training_mission = { | |
Weapon = amBallgun, | |
TurnTime= 60000, | |
Map = "Ropes", | |
Theme = "City", | |
Team = { name = loc("Team Ball"), color = 14483456, grave = "Simple", fort = "Island", voicepack = "Default", flag = "Default" }, | |
player = { name = loc("Hunter"), botlevel = 0, health=1, hat = "NoHat" }, | |
Rounds = { | |
-- round 1 | |
{ | |
StartPosition = { x=2000, y=100}, | |
Targets = { | |
{x=1800, y=1500}, | |
{x=1900, y=1500}, | |
{x=2000, y=1500} | |
}, | |
} | |
} | |
} | |
function onAttack() | |
ammo = ammo - 1 | |
if ammo <= 0 then | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("Oh no! You run out of ammo! Just try again."), -amSkip, 0) | |
game_finished = true | |
end | |
end | |
function onGameInit() | |
-- At first we have to overwrite/set some global variables | |
-- that define the map, the game has to load, as well as | |
-- other things such as the game rules to use, etc. | |
-- Things we don't modify here will use their default values. | |
-- The base number for the random number generator | |
Seed = 1 | |
-- Game settings and rules | |
GameFlags = gfOneClanMode | |
-- The time the player has to move each round (in ms) | |
TurnTime = 60000 | |
CaseFreq = 0 | |
MinesNum = 0 | |
Explosives = 0 | |
-- The delay between each round | |
Delay = 0 | |
-- The map to be played | |
Map = "Ropes" | |
-- The theme to be used | |
Theme = "City" | |
-- Create the player team | |
AddTeam(loc("Team Ball"), 14483456, "Simple", "Island", "Default") | |
-- And add a hog to it | |
player = AddHog(loc("Hunter"), 0, 1, "NoHat") | |
SetGearPosition(player, 2000, 100) | |
end | |
function onGameStart() | |
-- Spawn the first target. | |
spawnTarget(1) | |
-- Show some nice mission goals. | |
-- Parameters are: caption, sub caption, description, | |
-- extra text, icon and time to show. | |
-- A negative icon parameter (-n) represents the n-th weapon icon | |
-- A positive icon paramter (n) represents the (n+1)-th mission icon | |
-- A timeframe of 0 is replaced with the default time to show. | |
ShowMission(loc(mission_name), loc("Aiming Practice"), string.format(loc("Eliminate all targets with as least shots as possible.|You have only %i shots for this mission."),ammo), -training_mission.Weapon, 0) | |
end | |
function onNewTurn() | |
ParseCommand("setweap " .. string.char(training_mission.Weapon)) | |
end | |
function onAmmoStoreInit() | |
-- add three shots of bubble gun ammo | |
SetAmmo(training_mission.Weapon, ammo, 0, 0, 1) | |
end | |
function onGearAdd(gear) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- these are helper function to ease the implementation of trainings | |
function spawnTarget(round) | |
targets = 0 | |
for i,target in ipairs(training_mission.Rounds[round].Targets) do | |
SetGearPosition( | |
AddGear(0, 0, gtTarget, 0, 0, 0, 0), | |
target.x, | |
target.y | |
) | |
targets = targets+1 | |
end | |
end | |
function onGameTick() | |
if game_finished == true then | |
if end_timer == 0 then | |
EndGame() | |
else | |
end_timer = end_timer - 1 | |
TurnTimeLeft = time_goal | |
end | |
end | |
end | |
function onAttack() | |
ammo = ammo - 1 | |
if ammo <= 0 then | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("Oh no! You run out of ammo! Just try again."), -amSkip, 0) | |
game_finished = true | |
end | |
end | |
function onGearDelete(gear) | |
if GetGearType(gear) == gtTarget then | |
targets = targets - 1 | |
if targets <= 0 then | |
round = round+1 | |
-- spawn next round if it exists | |
if training_mission.Rounds[round] then | |
spawnTarget(round) | |
else | |
game_finished = true | |
if ammo == 2 then | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets with just one shot!"), 0, 0) | |
elseif ammo == 1 then | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("Nice Job! You've eliminated all targets with two shots!"), 4, 0) | |
else | |
ShowMission(loc(mission_name), loc("Aiming Practice"), loc("That was thight! You've eliminated all targets with your last shot!"), 2, 0) | |
end | |
PlaySound(sndVictory) | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment