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

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
CheckPoints and Lives System
« on: May 29, 2012, 12:47:53 AM »
I want a total of 10 lives and various checkpoints throughout the game and I think i'm very close with the code i've got, but lack a bit of knowledge.

So this is the code i've got at the moment.

Code: [Select]
function LevelLogic()

        StartLevelLogic()

i = 10

        Puzzle = 0

                CheckConditions()
                coroutine.yield()       
        end
end

function CheckConditions()


        if GetEmpire(1).NumSeedlings == 0 and CheckPoint == 1 and Lives == (i) then
           
i = 9
                        GetAsteroid(10):AddSeedlings(1)
Message("You have 9 Seedlings left.", true, 1.0, "Centre")

        end



end

So i've branched out and i've tried to do some stuff. I knew that I couldn't just do CheckPoint == 1 and Lives == 10 because what if they had 9 lives before they got to the first checkpoint? So I have to make Lives == to 0 - 10 all at the same time, but just thinking now, do I actually need to add Lives == 0 - 10 in that code? I could just add something like this below in seperate if statement such as:

Code: [Select]
if Lives == 10 and GetEmpire(1).NumSeedlings == 0 then
Lives = 9
Message("You have 9 Seedlings left.", true, 1.0, "Centre")
end

Wouldn't that work? Brainwave.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: CheckPoints and Lives System
« Reply #1 on: May 29, 2012, 01:11:50 AM »
Why not use

Code: [Select]
if GetEmpire(1).NumSeedlings == 0 then
  Lives = Lives - 1
  Message("You have " .. Lives .. " seedlings left.", true, 1.0, "Centre")
end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #2 on: May 29, 2012, 01:35:58 AM »
Actually that won't work, according to Tom you can't concatenate stuff into a Message string like you can with MessageBoxes.  You also can't use Message to display the value of a variable.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: CheckPoints and Lives System
« Reply #3 on: May 29, 2012, 01:50:00 AM »
Code: [Select]
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
end

That would work, surley.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #4 on: May 29, 2012, 01:54:17 AM »
Yes, with the following caveats:


1) You'd need to make sure you set Lives = 10 somewhere before the While loop begins, otherwise the game will crash because when it checks "if Lives == 10" it will discover that Lives = nil.
2) You'll need 10 seperate conditionals if you want 10 lives!  Are you sure 3 lives isn't enough? :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: CheckPoints and Lives System
« Reply #5 on: May 29, 2012, 02:13:10 AM »
It's going to be a long level, plus think about difficulty, some people can't move fast and that, but maybe i'll post another level test for this, it should be easy to convert to PC this time.

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

if GetEmpire(1).NumSeedlings == 0 and Lives == 9 then
GetAsteroid(10):AddSeedlings(1)
Lives = 8
Message("You have 8 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 8 then
GetAsteroid(10):AddSeedlings(1)
Lives = 7
Message("You have 7 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 7 then
GetAsteroid(10):AddSeedlings(1)
Lives = 6
Message("You have 6 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 6 then
GetAsteroid(10):AddSeedlings(1)
Lives = 5
Message("You have 5 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 5 then
GetAsteroid(10):AddSeedlings(1)
Lives = 4
Message("You have 4 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 4 then
GetAsteroid(10):AddSeedlings(1)
Lives = 3
Message("You have 3 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 3 then
GetAsteroid(10):AddSeedlings(1)
Lives = 2
Message("You have 2 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 2 then
GetAsteroid(10):AddSeedlings(1)
Lives = 1
Message("You have 1 seedlings left.", true, 1.0, "Centre")
end
end

Plus you're forgetting, thats 10 for every checkpoint haha.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: CheckPoints and Lives System
« Reply #6 on: May 29, 2012, 02:14:30 AM »
Would it be easier to put it in a function?

Code: [Select]
if CheckPoint == 1 then
Lives()
end

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

if GetEmpire(1).NumSeedlings == 0 and Lives == 9 then
GetAsteroid(10):AddSeedlings(1)
Lives = 8
Message("You have 8 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 8 then
GetAsteroid(10):AddSeedlings(1)
Lives = 7
Message("You have 7 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 7 then
GetAsteroid(10):AddSeedlings(1)
Lives = 6
Message("You have 6 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 6 then
GetAsteroid(10):AddSeedlings(1)
Lives = 5
Message("You have 5 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 5 then
GetAsteroid(10):AddSeedlings(1)
Lives = 4
Message("You have 4 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 4 then
GetAsteroid(10):AddSeedlings(1)
Lives = 3
Message("You have 3 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 3 then
GetAsteroid(10):AddSeedlings(1)
Lives = 2
Message("You have 2 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 2 then
GetAsteroid(10):AddSeedlings(1)
Lives = 1
Message("You have 1 seedlings left.", true, 1.0, "Centre")
end
end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #7 on: May 29, 2012, 03:01:20 AM »
Agree.  :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: CheckPoints and Lives System
« Reply #8 on: May 29, 2012, 04:48:31 AM »
Just realised something else i'll have to do with this,

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

if GetEmpire(1).NumSeedlings == 0 and Lives == 9 then
GetAsteroid(10):AddSeedlings(1)
Lives = 8
Message("You have 8 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 8 then
GetAsteroid(10):AddSeedlings(1)
Lives = 7
Message("You have 7 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 7 then
GetAsteroid(10):AddSeedlings(1)
Lives = 6
Message("You have 6 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 6 then
GetAsteroid(10):AddSeedlings(1)
Lives = 5
Message("You have 5 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 5 then
GetAsteroid(10):AddSeedlings(1)
Lives = 4
Message("You have 4 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 4 then
GetAsteroid(10):AddSeedlings(1)
Lives = 3
Message("You have 3 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 3 then
GetAsteroid(10):AddSeedlings(1)
Lives = 2
Message("You have 2 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 2 then
GetAsteroid(10):AddSeedlings(1)
Lives = 1
Message("You have 1 seedlings left.", true, 1.0, "Centre")
end
end

So I have in CheckConditions()

Code: [Select]
if CheckPoint == 1 then
LivesCheck()
end

if i do this

Code: [Select]
if CheckPoint == 2 then
LivesCheck()
end

then really, it's not a new checkpoint, cause it will just go back to Asteroid(10) which for checkpoint 2, I don't want, so to save creating another function i decided to do this

Code: [Select]
function CheckConditions()
if (CheckPoint == 1 or CheckPoint == 2) then
LivesCheck()
end

end

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

That would work wouldn't it?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #9 on: May 29, 2012, 05:39:44 AM »
Interesting problem.  I'd suggest using an array.

Consider this code:

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


startroid[CheckPoint] is the new part.

startroid is an array; a numbered list.

So suppose CheckPoint = 1

That's like saying:

Code: [Select]
startroid[1]
If CheckPoint = 2, then startroid[CheckPoint] resolves to:

Code: [Select]
startroid[2]

startroid is an array.  Arrays are like numbered lists.  CheckPoint indicates the item number in the list called startroid.

You can read about arrays in the Intermediate guide.  I urge you to read about them if you haven't already.


You'll need to initialise the array like this:


Code: [Select]
startroid = {}
Then you can declare values for each slot like this:

Code: [Select]
startroid[1] = GetAsteroid(10)
startroid[2] = GetAsteroid(12)
startroid[3] = GetAsteroid(16)


Then, you would just need to make sure you increment the CheckPoint variable each time the player reaches a new Check Point.  :>
« Last Edit: May 29, 2012, 05:43:59 AM by annikk.exe »

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: CheckPoints and Lives System
« Reply #10 on: May 30, 2012, 06:07:00 AM »
Okay so this is what i've got Annikk.
Code: [Select]
function LevelLogic()
        StartLevelLogic()

Lives = 10
        Puzzle = 0
startroid = {}
startroid[1] = GetAsteroid(10)
        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

if (CheckPoint == 1 or CheckPoint == 2) then
LivesCheck()
end

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)
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
end
end

But you see, what happens is this: (Liking my videos now :D)



(WHY WE NEED YOUTUBE TAGS!!!)

Text Version:

Basically it spawns 10 seedlings straight up, not death then one, death then one, just straight up 10.

« Last Edit: May 30, 2012, 07:58:27 AM by Tomfloria »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #11 on: May 30, 2012, 05:28:31 PM »
You haven't included the bit where you initialise CheckPoint.

Please can you post the whole thing?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #12 on: May 30, 2012, 05:37:07 PM »
Code: [Select]
function LivesCheck()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
startroid[CheckPoint]:AddSeedlings(1)
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
end
end

Try removing the WaitReal(4) command from this bit?

I suspect WaitReal() doesn't work well when used inside a loop...

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: CheckPoints and Lives System
« Reply #13 on: May 30, 2012, 07:14:23 PM »
Okay, if you want the whole thing... I'll split into functions just incase you don't want something...

function LevelSetup()
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--

        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)
       
        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)

        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)

       

        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)

       

        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)

       

        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)

       

        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)

       

        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)

       

       

        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)

       

       

        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)

       

        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--

       

        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)

       

        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()
Code: [Select]
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()
Code: [Select]
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()
Code: [Select]
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)
Code: [Select]
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: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #14 on: May 30, 2012, 11:52:57 PM »
Looking at it now.

By the way, a tip I would give you is to use tabs instead of spaces for the code spacing.

For example:


Code: [Select]
function LevelLogic()
if 1 == 1 then
GetAsteroid(0):AddSeedlings(10)
end
end

Instead of:

Code: [Select]
function LevelLogic()
     if 1 == 1 then
          GetAsteroid(0):AddSeedlings(10)
    end
end


That way things line with each other up automatically. :>


Here are those two code snippets again, screenshotted in Notepad++ for comparison:






The lines showing which if pertains to which end, get messed up if you use spaces.
Also it means it takes longer (using cursor keys) to get to the end or start of a deeply nested line, because you have to scroll through 30 spaces first (instead of 6 tabs).



Minor point, and this isn't the cause of your Lives/Checkpoint problem, but I thought I'd mention it here...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #15 on: May 31, 2012, 12:15:45 AM »
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: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #16 on: May 31, 2012, 12:29:29 AM »
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: 4
  • Posts: 1,809
Re: CheckPoints and Lives System
« Reply #17 on: June 01, 2012, 10:11:54 AM »
So...did that fix it? :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: CheckPoints and Lives System
« Reply #18 on: June 01, 2012, 09: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
Re: CheckPoints and Lives System
« Reply #19 on: June 04, 2012, 10: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: 58
  • -Receive: 71
  • Posts: 441
  • Eufloria: Yes
Re: CheckPoints and Lives System
« Reply #20 on: June 29, 2012, 05:36:55 PM »
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: 58
  • -Receive: 71
  • Posts: 441
  • Eufloria: Yes
Re: CheckPoints and Lives System
« Reply #21 on: July 06, 2012, 02:24:15 AM »
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 06, 2012, 02:27:36 AM by sillytuna »