For example:
function LevelSetup()
-- some random globals.. can't remember what I all need...
Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
Globals.G.MinAsteroidSeparation=500
Globals.G.MaxAsteroidNeighbourDist=3500
Globals.G.StartingSeedlings=(10)
Globals.G.GreysProbability=0
-- add some asteroids... a start roid
a = AddAsteroidWithAttribs(0,0, 1,1,1)
a.Name = "Start"
a.Owner = 1
s = a:AddDysonTree()
-- and a destination roid... we need some roids so we can
-- have some kind of fixed, known frame of reference to
-- test the transition effect..
a = AddAsteroidWithAttribs(2000,-1000, 1,1,1)
a.Name = "Destination"
a.Owner = 1
s = a:AddDysonTree()
end
function LevelLogic()
-- initialise variables
startTransition = true
p = 0
camX = GetCameraX()
camY = GetCameraY()
startX = camX
startY = camY
destX = 2000
destY = -1000
-- begin shenanigans
while GameRunning() do
-- Hallo ! Is this the start? Are we transitioning ?
if startTransition == true and GetGameTime() > 3 then
-- if we are, start incrementing the counter...
p = p + 0.02
-- if we've reached the end of the transition..
if (p > 1) then
-- set p to a nice round 1, and flip the latch so the base conditional will no longer trigger.
p = 1
startTransition = false
end
-- time to set the camera distance.
-- camera position = start coordinate + ((destination coordinate - start coordinate) * the counter)
camX = startX + ((destX - startX) * p)
camY = startY + ((destY - startY) * p)
-- set the camera to the newly calculated coordinates
SetCameraPosition(camX, camY)
end
coroutine.yield()
end
end
Again, fully working level.
The only change I needed to make was this line:
if startTransition then
I changed it to this:
if startTransition == true and GetGameTime() > 3 then
if startTransition and if startTransition == true are the same, I just prefer the latter because I think it's clearer. :>