Author Topic: CheckPoints and Lives System  (Read 1244 times)

0 Members and 1 Guest are viewing this topic.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #15 on: May 30, 2012, 04:15:45 PM »
Modified the code to have tabs instead of spaces, and added some additional comments such as Asteroid ID numbers.

Haven't spotted the problem yet though. :>


Code: [Select]
function LevelSetup()

SetBackdropColour(200,200,200)

--Custom Story Mode Created by: Tomfloria
--Wouldn't have been possible without help from: Annikk.exe, Aino, Pilchard123
--iOS installation tutorial can be found here: http://www.dyson-game.com/smf/index.php?topic=1541.0
--Big thanks to the creaters of Eufloria, without them I wouldn't have done this.
--Contact me at Thomasbiggin@gmail.com

Globals():Get("Asteroids"):Set("RadiusPowerRule",4)
Globals():Get("Asteroids"):Set("SizeFromEnergy",530)
Globals():Get("Asteroids"):Set("SizeFromStrength",530)
Globals():Get("Asteroids"):Set("SizeFromSpeed",540)
Globals():Get("Asteroids"):Set("MinCoreHealth",75)
Globals():Get("Asteroids"):Set("MaxCoreHealth",350)
Globals():Get("Asteroids"):Set("CoreHealthPowerRule",2.5)
Globals():Get("Asteroids"):Set("MinSendDistance",3500)
Globals():Get("Asteroids"):Set("MaxSendDistance",5500)
Globals():Get("Asteroids"):Set("SendPowerRule",2.0)
Globals():Get("Asteroids"):Set("SpawnCap", 20)
Globals():Get("Structures"):Set("LevelDuration1",15)
Globals():Get("Structures"):Set("LevelDuration2",30)
Globals():Get("Structures"):Set("LevelDuration3",60)
Globals():Get("Structures"):Set("LevelDuration4",100)
Globals():Get("Structures"):Set("SpawnTime1",15)
Globals():Get("Structures"):Set("SpawnTime2",12)
Globals():Get("Structures"):Set("SpawnTime3",10)
Globals():Get("Structures"):Set("SpawnTime4",8)
Globals():Get("Flowers"):Set("Available",0)
Globals():Get("Game"):Set("GreysProbability",0)

--FIRST PATH TO PUZZLE--
-- ID 0
a = AddAsteroidWithAttribs(0,0, 0.0,0.0,0.5)
a.Owner = 1
--a:AddSeedlings(1)
a:SetRadius(180)
a.TreeCap = 0
a:Reveal(1)

-- ID 1
a = AddAsteroidWithAttribs(100,-600, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- ID 2
a = AddAsteroidWithAttribs(-1000,-2300, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- ID 3
a = AddAsteroidWithAttribs(200,-4000, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- ID 4
a = AddAsteroidWithAttribs(3000,-3500, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- ID 5
a = AddAsteroidWithAttribs(3000,-1300, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- ID 6
a = AddAsteroidWithAttribs(4000,1000, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- ID 7
a = AddAsteroidWithAttribs(6000,-1000, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- ID 8
a = AddAsteroidWithAttribs(8000,-3500, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- ID 9
a = AddAsteroidWithAttribs(8500,-5500, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:AddSeedlings(1)
a:Reveal(1)

-- ID 10
a = AddAsteroidWithAttribs(8500,-7500, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Hide(1)
--END OF PATH TO PUZZLE--



--START OF PUZZLE--THE PRATROLERS

--MIDDLE ASTEROID--11
a = AddAsteroidWithAttribs(8500,-13000, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
a.Owner = 1
a:SetRadius(300)
a.Moveable = false
a:Hide(1)

--BOTTOM ASTEROID--12
a = AddAsteroidWithAttribs(8500,-10000, 1,1,0.3)
a.Owner = 1
a.TreeCap = 0
a.Moveable = false
a:SetRadius(200)
a:Hide(1)

--BOTTOM LEFT ASTEROID--13
a = AddAsteroidWithAttribs(6500,-11000, 1,1,0.3)
a.Owner = 0
a.TreeCap = 0
a:AddSeedlings(100)
a.Moveable = false
a:SetGraceTime(999999)
a:SetRadius(200)
a:Hide(1)

--LEFT ASTEROID--14
a = AddAsteroidWithAttribs(5500,-13000, 1,1,0.3)
a.Owner = 0
a.TreeCap = 0
a:AddSeedlings(100)
a.Moveable = false
a:SetGraceTime(999999)
a:SetRadius(200)
a:Hide(1)

--TOP LEFT ASTEROID--15
a = AddAsteroidWithAttribs(6500,-15000, 1,1,0.3)
a.Owner = 0
a.TreeCap = 0
a:AddSeedlings(100)
a.Moveable = false
a:SetGraceTime(999999)
a:SetRadius(200)
a:Hide(1)

--TOP ASTEROID--16
a = AddAsteroidWithAttribs(8500,-16000, 1,1,0.3)
a.Owner = 0
a.TreeCap = 0
a:AddSeedlings(100)
a.Moveable = false
a:SetGraceTime(999999)
a:SetRadius(200)
a:Hide(1)

--TOP RIGHT ASTEROID--17
a = AddAsteroidWithAttribs(10500,-15000, 1,1,0.3)
a.Owner = 0
a.TreeCap = 0
a:AddSeedlings(100)
a.Moveable = false
a:SetGraceTime(999999)
a:SetRadius(200)
a:Hide(1)

--RIGHT ASTEROID--18
a = AddAsteroidWithAttribs(11500,-13000, 1,1,0.3)
a.Owner = 0
a.TreeCap = 0
a:AddSeedlings(100)
a.Moveable = false
a:SetGraceTime(999999)
a:SetRadius(200)
a:Hide(1)

--BOTTOM RIGHT ASTEROID--19
a = AddAsteroidWithAttribs(10500,-11000, 1,1,0.3)
a.Owner = 0
a.TreeCap = 0
a:AddSeedlings(100)
a.Moveable = false
a:SetGraceTime(999999)
a:SetRadius(200)
a:Hide(1)

--END OF PUZZLE 1--



--SECOND PATH TO PUZZLE 2 - ID 20
a = AddAsteroidWithAttribs(10500,-19000, 1,1,0.3)
a.Owner = 1
a:SetRadius(math.random(150,400))
a.TreeCap = 0
a.Moveable = false
a.SendDistance = 100
a:Reveal(1)

-- Disable buttons
SetDysonTreeButtonAvailable(false)
SetDefenseTreeButtonAvailable(false)
SetFlowerDefenseButtonAvailable(false)
SetFlowerSeederButtonAvailable(false)
SetTerraformingButtonAvailable(false)
SetBeaconButtonAvailable(false)

if IsiOS() then
SetEnemyInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)
SetSpeedSwitchAvailable(true)
SetSendModeScoutAvailable(true)
SetSendModeUnitsSelectorAvailable(true)
SetSendModeButtonAvailable(true)
SetSendModeHoldAvailable(true)
SetSendModeDragAvailable(true)
else
SetTreeInfoAvailable(true)
SetEnemyInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)
end

SetCameraPosition(0,0)

end



function LevelLogic()
StartLevelLogic()

Lives = 10
Puzzle = 0
startroid = {}
startroid[1] = GetAsteroid(9)
startroid[2] = GetAsteroid(9)
GetAsteroid(16).Owner = 1
GetAsteroid(16):Hide(1)

while GameRunning() do
if Puzzle == 1 then
WaitReal(10)
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
end

CheckConditions()
coroutine.yield()       
end
end




function CheckConditions()

if gameFinished then
return
end

if GetEmpire(0).NumDysonTrees == 0 and GetEmpire(0).NumSeedlings == 0 then
GameOver(true, "")
Message("You successfully protected the Captured Seedlings.~Well Done", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(true)
end

LivesCheck()

if GetEmpire(1).NumSeedlings == 0 and Lives == 1 then
Lives = 0
GameOver(false, "")
Message("Unfortunately you have failed to complete the tasks.", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(false)
end

end


function LivesCheck()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 9 seedlings left.", true, 1.0, "Centre")
Lives = 9
end

if Lives == 9 then
if GetEmpire(1).NumSeedlings == 0 then
startroid[CheckPoint]:AddSeedlings(1)
end
Message("You have 8 seedlings left.", true, 1.0, "Centre")
Lives = 8
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 8 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 7 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 7
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 7 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 6 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 6
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 6 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 5 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 5
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 5 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 4 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 4
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 4 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 3 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 3
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 3 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 2 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 2
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 2 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 1 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 1
end
end


function OnAsteroidRevealed(id, owner)
if id == 10 then
Puzzle = 1
GetAsteroid(11):Reveal(1)
GetAsteroid(12):Reveal(1)
GetAsteroid(13):Reveal(1)
GetAsteroid(14):Reveal(1)
GetAsteroid(15):Reveal(1)
GetAsteroid(16):Reveal(1)
GetAsteroid(17):Reveal(1)
GetAsteroid(18):Reveal(1)
GetAsteroid(19):Reveal(1)
CheckPoint = 1
end
end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #16 on: May 30, 2012, 04:29:29 PM »
Think I may have figured it out.


Try changing this code:


Code: [Select]
startroid[CheckPoint]:AddSeedlings(1)
To this:


Code: [Select]
startroid[CheckPoint]:AddSeedlings(1, 1, 1,1,1)

The original command says "Add 1 seedling for whoever owns this asteroid".
The new command says "Add 1 seedling to the asteroid for Empire 1, with stats of 1, 1, 1".

Here's what I think happens.
The player seedling dies, so the code detects that Empire 1 has 0 seedlings.  So it decrements 1 from the life counter, and adds a seedling to startroid[checkpoint]

But because the asteroid referred to by startroid[CheckPoint] is owned by the greys, the seedlings that are added belong to the grays too!  So the player doesn't actually get a seedling...

What does the code do next?  Well, it runs through the loop again, and guess what!  Player 1 STILL has 0 seedlings!  So we lose another life, another seedling is added to the startroid, etc... this repeats until all lives are exhausted and 10 seedlings have been added to the asteroid.  Then because we're out of lives, it stops, and tells you that you lost.

Tada! :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #17 on: June 01, 2012, 02:11:54 AM »
So...did that fix it? :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CheckPoints and Lives System
« Reply #18 on: June 01, 2012, 01:08:37 PM »
Hey Annikk, I've only just got some spare time! Not had a chance to code in last few days

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CheckPoints and Lives System
« Reply #19 on: June 04, 2012, 02:40:42 PM »
Just been able to try out your code Annikk, and nope, doesn't even spawn a seedlings :P haha

sillytuna

  • Eufloria lacky
  • Administrator
  • Arboreal Being
  • *****
  • Thank You
  • -Given: 45
  • -Receive: 37
  • Posts: 341
    • TunaHQ
  • Eufloria: Yes
Re: CheckPoints and Lives System
« Reply #20 on: June 29, 2012, 09:36:55 AM »
Messages - unsure why you can't make a string up. Does it not even work if you create the string before and put it into a variable? I can look at this and try to fix it.

Lives and checkpoints - can you explain what exactly you want to happen? Do you want to be able to demolish all trees and kill all seedlings on an asteroid then add player seedlings and put it in the hands of the player? I can add a couple of commands to do this :)

Just adding seedlings to an asteroid won't work for the reasons mentioned, and also you could just throw the player in against a load of enemies, even defence trees, which would be bad.

sillytuna

  • Eufloria lacky
  • Administrator
  • Arboreal Being
  • *****
  • Thank You
  • -Given: 45
  • -Receive: 37
  • Posts: 341
    • TunaHQ
  • Eufloria: Yes
Re: CheckPoints and Lives System
« Reply #21 on: July 05, 2012, 06:24:15 PM »
I've added supported for an asteroid Wipe() command, and I also checked that Message("abc" .. myVar .. "def", ...) works (which it does).

This is in the new script format so may not make much sense right now. The new format does not support yield so the update runs every frame in full. This means it is now state based. Current scripts have been changed to use if/elseif/end which is simply but can be a bit yucky. Waits work by not calling update until the wait is complete, but code DOES run immediately after the wait so these commands are typically at the bottom of each state 'block'. I'll doc this all up once the iPhone is out. I could clean things up more but it's risky enough changing the existing scripts as it is!

Here is an example of using lives:

Code: [Select]
if GameState == "Start" then
Lives = 3; -- Number of lives
ResurrectionAsteroid = 5 -- Asteroid to be resurrected on
PlayerMustHaveTreesSeedlings = false -- Tells the game not to quit when the player has lots their army

GameState = "Died"
WaitGame(5)

elseif GameState == "Died" then
-- Fade out
SetLevelDim(true)

-- Get the chosen asteroid
a = GetAsteroid(ResurrectionAsteroid)

-- Protect the asteroid to prevent anything attacking it
GetAsteroid(ResurrectionAsteroid):SetProtected(true)

-- SUGGESTION: Do the same to a neighbouring asteroid or two to give the player a chance

-- Report to the player
Message("Oh noes!## You're deaded!", true, 1.0, "Centre")

GameState = "PreWipe"

-- Put in a brief delay (in game time) so that any attacking seedlings (on their travels) have time to arrive
WaitGame(5) -- Use whatever value in here seems sensible
-- There is no real way to guarantee other enemies won't be approaching without internal AI adjustments

elseif GameState == "PreWipe" then
-- Point at the resurrection asteroid
SetCameraFocusToAsteroidID(ResurrectionAsteroid, 2400)

-- Clear the currently selected asteroid
SelectionClear()

GameState = "Wipe"
ClearMessage(2) -- Clear the previous message and include a brief wait (real time)

elseif GameState == "Wipe" then
-- Wipe out the resurrection asteroid
GetAsteroid(ResurrectionAsteroid):Wipe()

-- SUGGESTION: Do the same to a neighbouring asteroid or two to give the player a chance

-- Report to the player
Message("You'll be born Again!~ You have " .. Lives .. " lives left", true, 1.0, "Centre")

-- Time to read the message and for the mess to clear (real time)
GameState = "Resurrect"
WaitReal(4)

elseif GameState == "Resurrect" then
-- Give the asteroid to the player
a = GetAsteroid(ResurrectionAsteroid)
a.Owner = 1
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
a:AddSeedlings(29)

-- Fade in
SetLevelDim(false)

GameState = "Unprotect"

-- Give the player some time to sort themselves out (game time)
WaitGame(20)

elseif GameState == "Unprotect" then
-- Unprotect the asteroid so it can be attached again
GetAsteroid(ResurrectionAsteroid):SetProtected(false)

-- REMEMBER TO UNPROTECT ANY OTHER ASTEROIDS HERE OR IN RESURRECT!!!

GameState = "End"
end

Note that PlayerMustHaveTreesSeedlings is a system variable as the system now assumes they player has lost when they have no trees or seedlings. Setting this to false prevents that check from happening. I ought to rename it - it's a bit horrible really.

I've also not decremented the number of lives or ended the game ;)
« Last Edit: July 05, 2012, 06:27:36 PM by sillytuna »