Setup script examplesAdding a tree with a starting level of 2 (need to level up once to plant the root)
a = AddAsteroidWithAttribs(4600,-4600, 0.3,0.6,0.6)
a.Owner = 1
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
Add a tree with a flower or mine
a = AddAsteroidWithAttribs(4600,-4600, 0.3,0.6,0.6)
a.Owner = 1
-- add a flower on a dyson tree
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
flower = s:AddFlower()
flower:GrowToMax()
-- add a mine on a defense tree
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
s:LevelUp()
flower = s:AddFlower()
flower:GrowToMax()
Add a superseedling tree
a = AddAsteroidWithAttribs(4600,-4600, 0.3,0.6,0.6)
a.Owner = 1
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
s.Enhanced = true
Have an asteroid with superseedlings on it at the start
a = AddAsteroidWithAttribs(4600,-4600, 0.3,0.6,0.6)
a.Owner = 1
a:AddSuperSeedlings(50)
Level logic examplesAdding a scripted section of a fixed duration:
timeNow = GetGameTime()
while GetGameTime() < timeNow + 10 do
coroutine.yield()
end
-- This script runs for ten seconds.
Of course, you can also check the time any other point e.g.
winGame = false
timedSeedlingRelease = GetGameTime()
asteroid = GetAsteroid(1) -- assume we know for sure asteroid 1 exists
while not wingame do
if GetGameTime() > timedSeedlingRelease + 5 then
asteroid:AddSeedlings(1)
timedSeedlingRelease = GetGameTime()
end
coroutine.yield()
end
-- releases a seedling every five seconds to asteroid 1
Drawing examplesHere's a code block that shows some stuff being drawn in the level draw routine, including drawing stuff at a fixed size on screen, checking to see if something is on the screen and levels of detail:
function LevelDraw()
DrawLine(0,0,1000,1200,0,0,1,1,0,1,0,1,3)
l = 0
while l < 2*math.pi do
DrawTexLine(2, 0,0,math.sin(l)*100,math.cos(l)*100, 1,0.5,0,1,0.7,0.1,0,1, 1)
l = l + math.pi/5
end
if IsOnScreen(0,0,500) then
a = GetLODAlpha(2)
if a > 0 then
DrawSprite(5, -500,0, 0.7,0.1,0,a*0.98, 100)
end
a = GetLODAlpha(1)
if a > 0 then
DrawSprite(5, -500,0, 0.1,0.7,0,a*0.98, 500)
end
a = GetLODAlpha(0)
if a > 0 then
DrawSprite(5, -500,0, 0.1,0.0,0.7,a*0.98, 50/GetCameraScale())
end
end
end
callback examplesoneshot asteroid taken script example
enemyActivated = false
--Activates the enemy if still dormant, once th eplayer gets close enough.
function OnAsteroidTaken(id, owner)
if (id == 10 or id == 11) and enemyActivated then
GetAsteroid(7): SetGraceTime(1)
GetAsteroid(8): SetGraceTime(1)
GetAsteroid(9): SetGraceTime(1)
GetAsteroid(12): SetGraceTime(1)
enemyActivated = true
end
end
etc