Difference between revisions of "Programming levelgens"
Line 46: | Line 46: | ||
'''getPlayerCount()''' - Returns the number of players currently on the server. Note that player counts may change during the game. Note also that when testing your level in the editor, the number of players will reported as 0. The best way to test different player configurations is to use a dummy player count instead of getPlayerCount() until you are ready to put your level into production.<br> | '''getPlayerCount()''' - Returns the number of players currently on the server. Note that player counts may change during the game. Note also that when testing your level in the editor, the number of players will reported as 0. The best way to test different player configurations is to use a dummy player count instead of getPlayerCount() until you are ready to put your level into production.<br> | ||
<source lang="lua"> | <source lang="lua"> | ||
− | -- Add an asteroid for each player at (10,10) | + | -- Add an asteroid for each player at (10,10), (11, 11), etc. |
for i = 1, levelgen:getPlayerCount() do | for i = 1, levelgen:getPlayerCount() do | ||
− | + | levelgen:addItem("Asteroid", 10 + i, 10 + i) | |
end | end | ||
</source> | </source> |
Revision as of 08:13, 26 August 2010
Creating levelgen scripts is very straightforward. The methodology basically follows that used in the level definition files. If you are familiar with that format, you will find understanding the levelgen methods very easy. The easiest way to learn how level files are structured is to create a sample level in the editor, and examine it in a text editor. Don't worry, it's not complicated!
addItem( <args> ) - Adds an item to the game
Takes a variable number of arguments, and follows the same argument order as that used in level files.
For example:
-- Create a 10 x 10 block of RepairItems for i = 0, 10 do for j = 0, 10 do levelgen:addItem("RepairItem", 1 + i * .2, 1 + j * .2) end end
addWall( wallsize, issolid, points ) - Adds a wall to the game. The wallsize param is the thickness of the wall, in the same units as used in the editor (the standard wall has a thickness of 50). The issolid parameter is not yet fully supported, so use "false" for this value for now. Finally, points is a Lua table containing 2 or more Points.
For example:
-- Create a U-shaped segment of wall. To create a closed loop, -- repeat the first point at the end of the list. levelgen:addWall(50, false, { Point(1,1), Point(1,5), Point(5,5), Point(5,1) } )
addLevelLine( line ) - Feeds a raw level line to the level processor. You can use any line from a level definition file as an argument.
-- Some raw lines levelgen:addLevelLine("LoadoutZone 0 4.8 4.2 7.1 3.9 7.2 4.8 4.8 4.5") levelgen:addLevelLine("BarrierMaker 50 5.5 3 5.5 3.5")
getGridSize() - Returns the current level's gridsize
-- Create a 1x1 square of wall that is as thick as it is long -- Use + 1 to make adjacent blocks overlap a tiny bit and thus appear -- to merge. Note that defining one long wall is MUCH better than creating -- a series of many sorter segments. levelgen:addWall(levelgen:getGridSize() + 1, false, { Point(0,0), Point(1,0) } )
getPlayerCount() - Returns the number of players currently on the server. Note that player counts may change during the game. Note also that when testing your level in the editor, the number of players will reported as 0. The best way to test different player configurations is to use a dummy player count instead of getPlayerCount() until you are ready to put your level into production.
-- Add an asteroid for each player at (10,10), (11, 11), etc. for i = 1, levelgen:getPlayerCount() do levelgen:addItem("Asteroid", 10 + i, 10 + i) end