Author Topic: New, clean asteroidmaking!(FUNCTION)  (Read 4897 times)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
New, clean asteroidmaking!(FUNCTION)
« on: February 03, 2011, 05:44:44 AM »
So, I just wanted to put up a code for people making a lots of asteroids on their maps, this will simply cutting asteroidmaking into one line (+ some for the trees you make!).

Code: [Select]
function LevelSetup()

roid = {}
roidnumb=(0)
AddRoid(0,0, 0.3,0.6,0.4, 1, 5, 450, 500, 30, false,) --Players start
AddTree("def", 3) --Adds a defense tree
AddRoid(2000,0, 0.5,0.5,0.5, 2, 2, 250, 165, 45, false) --Enemy start
AddTree("dys", 5) --Adds a dyson tree
AddTree("def", 2) --Adds a defense tree
AddRoid(-2000,0, 0.1,0.9,0.4, 1, 4, 200, 75, 75, true) --Third roid for fun :D

--How it works
--AddRoid(x,y, energy,strength,speed, owner, treecap, radius, seedlings at start, superseedlings, movable)
--AddTree(type, level(5 = level 4 + enhanced!))

end

function AddRoid(roidx,roidy, roidenergy,roidstrength,roidspeed, roidowner, roidtrees, roidradius, roidseedlings, roidsuperseedlings, roidmoving)

roid[roidnumb] = AddAsteroidWithAttribs(roidx,roidy, roidenergy, roidstrength, roidspeed)
roid[roidnumb].Owner = roidowner
roid[roidnumb].TreeCap = roidtrees
roid[roidnumb]:SetRadius(roidradius)
roid[roidnumb]:AddSeedlings(roidseedlings)
roid[roidnumb]:AddSuperSeedlings(roidsuperseedlings)
roid[roidnumb].Moveable = roidmoves
if roid[roidnumb].Owner == 1 then
roid[roidnumb]:Reveal(1)
end

roidnumb = roidnumb + 1
end

function AddTree(treetype, treelevel)

if treetype == "dys" or treetype == "dyson" then
temptree = roid[roidnumb]:AddDysonTree()
elseif treetype == "def" or treetype == "defense" then
temptree = roid[roidnumb]:AddDefenseTree()
end
if treelevel > 0 and treelevel < 5 then
for treelevel = 1, treelevel do
temptree:LevelUp()
end
elseif treelevel == 5 then
for treelevel = 1, 4 do
temptree:LevelUp()
end
temptree:AddFlower()
end

end

function LevelLogic()



end

or the one with more goodies including:
- Random attribs when set to zero.
- Naming
- Roidselecting for trees, if it is -1 it selects the current roid that has been made!

Here it is:
Code: [Select]
function LevelSetup()

roid = {}
roidnumb=(0)
AddRoid(0,0,0.5,0.6,0.5,1, 5, 500, 0, 0, false,"lololol")
AddTree(-1,"dys",4)
AddRoid(2000,0,0,0,0, 1, 5, 250, 0, 0, false,"remove me if you want random name")
AddRoid(-2000,0,0,0,0, 1, 5, 250, 0, 0, false,"like the one under me!!!")
AddRoid(2000,-2000,0,0,0, 1, 5, 350, 0, 0, false)
AddRoid(-2000,-2000, 0,0,0, 1, 5, 350, 0, 0, false)
AddRoid(-2000,-1000, 0,0,0, 1, 5, 100, 0, 0, false)
AddRoid(10000,0,0,0,0, 1, 5, 450, 0, 0, false)
AddRoid(5000,0,0,0,0, 1, 5, 450, 0, 0, false)
AddRoid(0,10000,0,0,0, 2, 5, 450, 0, 0, false)
--How it works
--AddRoid(x,y, en,str,speed, owner, treecap, radius, seedlings, superseedlings, movable, name(remove the name and the comma for random name!))
--AddTree(ateroidroidnumber, type, level(5 = level 4 + enhanced!))

end

function AddRoid(roidx,roidy, roidenergy,roidstrength,roidspeed, roidowner, roidtrees, roidradius, roidseedlings, roidsuperseedlings, roidmoving, roidname)

if roidenergy == 0.0 then
roidenergy = math.random()
end
if roidstrength == 0.0 then
roidstrength = math.random()
end
if roidspeed == 0.0 then
roidspeed = math.random()
end

roid[roidnumb] = AddAsteroidWithAttribs(roidx,roidy, roidenergy, roidstrength, roidspeed)
roid[roidnumb].Owner = roidowner
roid[roidnumb].TreeCap = roidtrees
roid[roidnumb]:SetRadius(roidradius)
roid[roidnumb]:AddSeedlings(roidseedlings)
roid[roidnumb]:AddSuperSeedlings(roidsuperseedlings)
roid[roidnumb].Moveable = roidmoves
if roidname ~= nil then
roid[roidnumb].Name = roidname
end
if roid[roidnumb].Owner == 1 then
roid[roidnumb]:Reveal(1)
end

roidnumb = roidnumb + 1
end

function AddTree(roidnumber, treetype, treelevel)

if roidnumber == -1 then
roidnumber = roidnumb-1
end

if treetype == "dys" or treetype == "dyson" then
temptree = roid[roidnumber]:AddDysonTree()
elseif treetype == "def" or treetype == "defense" then
temptree = roid[roidnumber]:AddDefenseTree()
end
if treelevel > 0 and treelevel < 5 then
for treelevel = 1, treelevel do
temptree:LevelUp()
end
elseif treelevel == 5 then
for treelevel = 1, 4 do
temptree:LevelUp()
end
temptree:AddFlower()
end

end

function LevelLogic()




end

Just wanted to share, hope some of you who haven't figured out wants to use this :D

Remember that this won't include anything else, you got to make the rest of the map yourself :)
Don't hate me for this xD

EDIT: Added a filefor download if you want that :)

EDIT 2: Now you have two choises, FIX 1 and Simple Roids 2, FIX 1 only fix the bug and 2 includes the new stuff :)
« Last Edit: February 05, 2011, 08:43:37 AM by Aino »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Cleaning up roid making
« Reply #1 on: February 03, 2011, 05:45:07 PM »
That's pretty cool man.  :>  Looks like the guide on building your own functions did some good then!

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Cleaning up roid making
« Reply #2 on: February 03, 2011, 09:02:52 PM »
Have you made a guide for that? o.O

But I got to thanks you for the functions though... Cause I saw you used it in one of you map, think it was the gravity engine I saw it in :)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Cleaning up roid making
« Reply #3 on: February 03, 2011, 10:16:22 PM »
Ok, I found an error in the code:

Code: [Select]
function AddTree(treetype, treelevel)

if treetype == "dys" or treetype == "dyson" then
temptree = roid[roidnumb]:AddDysonTree()
elseif treetype == "def" or treetype == "defense" then
temptree = roid[roidnumb]:AddDefenseTree()
end

just change it to

Code: [Select]
function AddTree(treetype, treelevel)

if treetype == "dys" or treetype == "dyson" then
temptree = roid[roidnumb-1]:AddDysonTree()
elseif treetype == "def" or treetype == "defense" then
temptree = roid[roidnumb-1]:AddDefenseTree()
end

One question, this worked for me yesterday, why not after i reboot my computer? Same with my first level, I ran it fine, reboot after it didn't work...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Cleaning up roid making
« Reply #4 on: February 03, 2011, 10:21:18 PM »
Problems like that usually derive from old variables being preserved between games.

For example, if I play a level and in the code somewhere I set a non-local variable such as:

Code: [Select]
fluffy = 1

If I then remove that line, and replace it with:

Code: [Select]
if fluffy == 1 then
MessageBox("hallo fluffy")
end

...I believe that it will be triggered, because the previous load stored a value for a variable of that name.


I am not 100% that it works in this way, but to be on the safe side, it's always best to initialise all your variables at the start of the level so that everything gets reset when you load the level in Eufloria.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Cleaning up roid making
« Reply #5 on: February 03, 2011, 10:35:11 PM »
Maybe you can clean the RAM and it will be reset? :D

Bonobo

  • Achiever
  • Old Oak
  • ****
  • Thank You
  • -Given: 139
  • -Receive: 12
  • Posts: 670
  • Eufloria: Yes
Question re: rebooting and preserved, old variables
« Reply #6 on: February 03, 2011, 10:44:51 PM »
Re: rebooting the computer and old variables being preserved:

Does this mean that it is recomended to r/b Windows just so often when playing custom levels?

I’m asking this b/c I run Windows Vista in a virtual machine (w/ Parallels Desktop, on an iMac), and therefore I usually don’t shutdown but suspend … and therefore this Vista can be “on” for weeks, if not months.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Cleaning up roid making
« Reply #7 on: February 03, 2011, 10:56:12 PM »
Maybe you can clean the RAM and it will be reset? :D

Restarting Eufloria itself - or your entire computer - would mean old variable values are no longer preserved.  I think.



Quote
Re: rebooting the computer and old variables being preserved:

Does this mean that it is recomended to r/b Windows just so often when playing custom levels?

I’m asking this b/c I run Windows Vista in a virtual machine (w/ Parallels Desktop, on an iMac), and therefore I usually don’t shutdown but suspend … and therefore this Vista can be “on” for weeks, if not months.

Shouldn't really be necessary... during testing, a designer will typically play the map over and over.  If anything it will not work correctly after the game has been closed and reopened.


I don't think I explained this very well unfortunately.  I'll try to think of a better way of explaining it.