author | sheepluva |
Fri, 14 Jan 2011 17:01:29 +0100 | |
changeset 4840 | d607e8c5a743 |
parent 4506 | 37744d5c877e |
child 7771 | ce6d4dd0c780 |
permissions | -rw-r--r-- |
4506
37744d5c877e
Finnished up the lua translations by adding training maps, campaign is ignored for now
Henek
parents:
4503
diff
changeset
|
1 |
-- Hedgewars - Roperace for 2+ Players |
4188 | 2 |
|
4506
37744d5c877e
Finnished up the lua translations by adding training maps, campaign is ignored for now
Henek
parents:
4503
diff
changeset
|
3 |
loadfile(GetDataPath() .. "Scripts/Locale.lua")() |
4188 | 4 |
|
5 |
-- store number of hedgehogs |
|
6 |
local numhhs = 0 |
|
7 |
||
8 |
-- store hedgehog gears |
|
9 |
local hhs = {} |
|
10 |
||
11 |
-- store best time per team |
|
12 |
local clantimes = {} |
|
13 |
||
14 |
-- store best times |
|
15 |
local times = {} |
|
16 |
||
17 |
-- in milisseconds |
|
18 |
local maxtime = 99000 |
|
19 |
||
20 |
-- define start area (left, top, width, height) |
|
21 |
local start_area = {1606, 498, 356, 80} |
|
22 |
||
23 |
-- define goal area (left, top, width, height) |
|
24 |
local goal_area = {2030, 300, 56, 280} |
|
25 |
||
26 |
-- last active hog |
|
27 |
local lasthog = nil |
|
28 |
||
29 |
-- active hog reached the goal? |
|
30 |
local reached = false |
|
31 |
||
32 |
-- hog with best time |
|
33 |
local besthog = nil |
|
34 |
||
35 |
-- hog with worst time (per round) |
|
36 |
local worsthog = nil |
|
37 |
||
38 |
-- best time |
|
39 |
local besttime = maxtime + 1 |
|
40 |
||
41 |
-- worst time (per round) |
|
42 |
local worsttime = 0 |
|
43 |
||
44 |
function onGameInit() |
|
45 |
GameFlags = gfSolidLand + gfInvulnerable |
|
46 |
TurnTime = maxtime |
|
47 |
CaseFreq = 0 |
|
48 |
MinesNum = 0 |
|
49 |
Explosives = 0 |
|
50 |
Delay = 500 |
|
51 |
SuddenDeathTurns = 99999 -- "disable" sudden death |
|
52 |
Theme = 'Olympics' |
|
53 |
end |
|
54 |
||
55 |
function onGameStart() |
|
4503 | 56 |
ShowMission(loc("TrophyRace"), "", loc("Use your rope to get from start to finish as fast as you can!"), -amRope, 0) |
4188 | 57 |
started = true |
58 |
p=1820 |
|
59 |
for i = 0, numhhs - 1 do |
|
60 |
p = p + 50 |
|
61 |
SetGearPosition(hhs[i], p, 0) |
|
62 |
end |
|
63 |
||
64 |
for i=0, ClansCount-1 do |
|
65 |
clantimes[i] = 0 |
|
66 |
end |
|
67 |
end |
|
68 |
||
69 |
function onAmmoStoreInit() |
|
70 |
SetAmmo(amRope, 9, 2, 0) |
|
71 |
end |
|
72 |
||
73 |
function onGameTick() |
|
74 |
if TurnTimeLeft == 1 and CurrentHedgehog ~= nil then |
|
75 |
SetHealth(CurrentHedgehog, 0) |
|
76 |
x, y = GetGearPosition(CurrentHedgehog) |
|
77 |
AddGear(x, y, gtAmmo_Grenade, 0, 0, 0, 0) |
|
78 |
worsttime = 99999 |
|
79 |
worsthog = nil |
|
80 |
elseif TurnTimeLeft == maxtime - 1 and CurrentHedgehog ~= nil then |
|
81 |
if lasthog ~= nil then |
|
82 |
SetGearPosition(lasthog, p , 0) |
|
83 |
end |
|
84 |
reached = false |
|
85 |
SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2) |
|
86 |
elseif CurrentHedgehog ~= nil then |
|
87 |
x, y = GetGearPosition(CurrentHedgehog) |
|
88 |
if not reached and x > goal_area[1] and x < goal_area[1] + goal_area[3] and y > goal_area[2] and y < goal_area[2] + goal_area[4] then -- hog is within goal rectangle |
|
89 |
reached = true |
|
90 |
local ttime = maxtime - TurnTimeLeft |
|
91 |
--give it a sound;) |
|
92 |
if ttime < besttime then |
|
93 |
PlaySound (sndHomerun) |
|
94 |
else |
|
95 |
PlaySound (sndHellish) |
|
96 |
end |
|
97 |
for i = 0, numhhs - 1 do |
|
98 |
if hhs[i] == CurrentHedgehog then |
|
99 |
times[numhhs] = ttime |
|
100 |
end |
|
101 |
end |
|
102 |
||
103 |
local hscore = "| |" |
|
104 |
local clan = GetHogClan(CurrentHedgehog) |
|
105 |
if ttime < clantimes[clan] or clantimes[clan] == 0 then |
|
106 |
clantimes[clan] = ttime |
|
107 |
end |
|
108 |
||
109 |
if ttime < besttime then |
|
110 |
besttime = ttime |
|
111 |
besthog = CurrentHedgehog |
|
4503 | 112 |
hscore = hscore .. loc("NEW fastest lap: ") |
4188 | 113 |
else |
4503 | 114 |
hscore = hscore .. loc("Fastest lap: ") |
4188 | 115 |
end |
116 |
if ttime > worsttime then |
|
117 |
worsttime = ttime |
|
118 |
worsthog = CurrentHedgehog |
|
119 |
end |
|
4503 | 120 |
hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc("Best laps per team: ") |
4188 | 121 |
|
122 |
if clan == ClansCount -1 then |
|
123 |
-- Time for elimination - worst hog is out and the worst hog vars are reset. |
|
124 |
SetHealth(worsthog, 0) |
|
125 |
--Place a grenade to make inactive slowest hog active |
|
126 |
x, y = GetGearPosition(worsthog) |
|
127 |
AddGear(x, y, gtShell, 0, 0, 0, 0) |
|
128 |
worsttime = 0 |
|
129 |
worsthog = nil |
|
130 |
end |
|
131 |
||
132 |
for i=0, ClansCount -1 do |
|
133 |
local tt = "" .. (clantimes[i] / 1000) .. " s" |
|
134 |
if clantimes[i] == 0 then |
|
135 |
tt = "--" |
|
136 |
end |
|
4503 | 137 |
hscore = hscore .. "|" .. string.format(loc("Team %d: "), i+1) .. tt |
4188 | 138 |
end |
139 |
||
4503 | 140 |
ShowMission(loc("TrophyRace"), "", loc("You've reached the goal!| |Time: ") .. (ttime / 1000) .. " s" .. hscore, 0, 0) |
4188 | 141 |
TurnTimeLeft = 0 |
142 |
end |
|
143 |
end |
|
144 |
end |
|
145 |
||
146 |
function onGearAdd(gear) |
|
147 |
if GetGearType(gear) == gtHedgehog then |
|
148 |
hhs[numhhs] = gear |
|
149 |
times[numhhs] = 0 |
|
150 |
numhhs = numhhs + 1 |
|
151 |
elseif GetGearType(gear) == gtRope then -- rope is shot |
|
152 |
||
153 |
end |
|
154 |
end |
|
155 |
||
156 |
function onGearDelete(gear) |
|
157 |
if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope |
|
158 |
--TurnTimeLeft = 0 -- end turn or not? hm... |
|
159 |
lasthog = CurrentHedgehog |
|
160 |
||
161 |
end |
|
162 |
end |