Overwhelmed by the thought of trying to code your own levels?
Don't worry, Fluffy is here to halp.
Follow this guide and you'll be making levels in no time!
(If you actually try everything suggested here for yourself, it will take you about 40-60 mins to learn how to make levels.)
To start with we will create a very simple level, and then learn by adjusting values and playing the level each time to see what has changed.
1.
Click Start
(http://img6.imageshack.us/img6/142/36526858.jpg)
2.
Click on "Run".
(http://img710.imageshack.us/img710/8116/36419182.jpg)
3.
Type "notepad.exe" into the box as shown, and click OK.
(http://img204.imageshack.us/img204/922/65731594.jpg)
4.
Notepad opens.
(http://img6.imageshack.us/img6/8894/14841297.jpg)
5.
Enter the text shown below into Notepad.
If you would prefer to copy & paste the text instead of typing it out yourself, click the "Spoiler" button below:
function LevelSetup()
-- Set Global Values
Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(1)
Globals.G.EnemyFactionsMax=(1)
-- Asteroid 0 - starting asteroid
a = AddAsteroidWithAttribs(0,0, 0.7,0.6,0.5)
a.Owner = 1
a.TreeCap = 1
a:SetRadius(250)
a.SendDistance = 2500
a:AddSeedlings(90)
-- Asteroid 1
a = AddAsteroidWithAttribs(2000,0, 0.3,0.3,0.3)
a.Owner = 2
a.TreeCap = 2
a:SetRadius(450)
a.SendDistance = 2500
a:AddSeedlings(100)
end
function LevelLogic()
end
(http://www.hpruk.com/annikk/5.JPG)
6.
Now click "File" in the top left of Notepad, and choose "Save As".
(http://img10.imageshack.us/img10/6420/57757928.jpg)
7.
We need to make sure we save it in the right folder.
The picture below shows the correct location of the "Maps" folder.
Use the drop-down box at the top of the "Save As" window to navigate to the right folder.
(http://img22.imageshack.us/img22/5870/20113803.jpg)
8.
Give your level a name, and make sure that it ends with ".lua"
Set the file type to All Files.
Set Encoding to ANSI.
(http://img685.imageshack.us/img685/4331/65826991.jpg)
Then click the Save button. Now it's time to check out our level.
9.
Load up Eufloria, choose "Custom Levels" from the main menu, and your new level should be waiting there.
Click on it to try playing it!
(http://img205.imageshack.us/img205/849/52530803.jpg)
10.
When it loads up, this is what it should look like.
(http://img24.imageshack.us/img24/8132/84046997.jpg)
11.
If you send a scout to the asteroid next door, you should see that there are enemy seedlings orbiting it.
(http://img37.imageshack.us/img37/5839/93108433.jpg)
If you got this far, congratulations - you are through the biggest barrier, which is getting started. It will be plain sailing from here!
33.
We have been studying the section called function LevelSetup(), which deals with the creation of the level and all the initial conditions.
Now it's time to have a look at the function LevelLogic() section. This section lets you make things happen during play, such as scripted events.
(http://img710.imageshack.us/img710/284/36266925.jpg)
34.
To begin with, lets make a Message Box appear after 5 seconds of game time has passed.
The messagebox could contain a greeting, and instructions for the player.
Add this code:
-- Greet the player
Timer = GetGameTime() + 5
while GetGameTime() < Timer do
coroutine.yield()
end
Pause()
MessageBox("Take the asteroid to the east to win. Don't lose yours.")
WaitDialog()
Unpause()
(http://www.hpruk.com/annikk/2.JPG)
Load up the level to test it out:
(http://www.hpruk.com/annikk/3.JPG)
35.
So what happened there? Lets think about this for a minute before we move on.
a.
Well, first we created a variable called Timer (case sensitive!).
(http://img168.imageshack.us/img168/7460/88808303.jpg)
We set it to Game Time + 5, and since it is the first thing the game evaluates once it's running, Timer must have a value of 0:05 seconds.
b.
Then we used something called a While loop to create a delay.
(http://img709.imageshack.us/img709/6391/59126537.jpg)
We told the game, while the game time is less than Timer, just keep repeating these commands.
c.
The part which tells it the loop has ended is the coroutine.yield() command.
(http://img3.imageshack.us/img3/1229/34929163.jpg)
This command tells the game the loop has ended and the game should go back up and check if the conditions of the While statement are still being met.
We don't have any commands in between our While statement and our coroutine.yield(). So basically the game just does nothing for 5 seconds. :>
d.
Once the 5 seconds are up, the While loop exits at the end statement.
(http://img4.imageshack.us/img4/9681/59964157.jpg)
e.
Then next thing that happens is that the game pauses, a Message Box appears, and when the player clicks OK, the game unpauses again.
(http://img341.imageshack.us/img341/7088/72836962.jpg)
Look at the commands and read over this part a few times if you need to. It is helpful if you can conceptualise what is going on here.
36.
The level is a bit easy at the moment. Lets add a scripted event where a bunch of enemy seedlings spawn on Asteroid 1.
I'll make mine 20 seconds after the Message Box appears, and I guess I'll add about... 400 seedlings.
You might notice I've started adding comments as well, to remind myself what each part does later on.
(http://img189.imageshack.us/img189/7690/27886850.jpg)
Did you notice we used the :AddSeedlings command in LevelSetup() too? Most of the commands used there are also usable here. In this case, we weren't able to refer to it by a name like "a" because "a" had been replaced with a different asteroid, so instead we just tell the game which asteroid we mean with GetAsteroid(ID). Hence, GetAsteroid(1):AddSeedlings(400) is the command to add 400 seedlings to asteroid 1.
37.
Lets save the level and see if the the enemies spawn correctly. :>
(http://img40.imageshack.us/img40/9678/36076019.png)
38.
If you would like to make it even more interesting, you can add the following line after:
GetAsteroid(1):SendSeedlingsToTarget(2,400,GetAsteroid(0))
This sends seedlings from Asteroid 1, belonging to player 2... it sends 400 of them, to Asteroid 0.
(http://img693.imageshack.us/img693/7725/24226274.jpg)
39.
At the moment, if the player takes over all the asteroids, the game just continues running. There is no way to "win".
We will create a winning condition and a losing condition, so that the game can actually be won or lost by the player.
Add this code:
gamewon = 0
while gamewon == 0 do
coroutine.yield()
end
if gamewon == 1 then
Pause()
MessageBox("You have won.")
WaitDialog()
Unpause()
Quit(true)
end
if gamewon == 2 then
Pause()
MessageBox("You have lost.")
WaitDialog()
Unpause()
Quit(false)
end
(http://www.hpruk.com/annikk/C.JPG)
There are three new things here.
Quit(true) means the game ends and the player won.
Quit(false) means the game ends and the player lost.
If and then statements. These check if something is true, and if so, does something.
So if the variable gamewon is equal to 1, then the player is told they have won and the game ends in victory.
But if the variable gamewon is equal to 2, it skips the first If statement and proceeds to the second If statement... resulting in the player being told they have lost, and the game ending in defeat.
You might also notice that in some places we use a single "=", and in other places we use the double: "==".
A single equals sign "=" is used to set values, whereas the double "==" is used to compare values.
40.
Now that we have created the winning and losing code, we need to have some way to trigger the victory or defeat.
For this example, we will say that if Player 1 gets asteroid 1, the player wins (gamewon = 1). And if Player 2 gets Asteroid 0, the player loses (gamewon = 2).
The easiest way to check this is to use an entirely new function - seperate entirely from function LevelLogic - this new one is called function OnAsteroidTaken, and we place it below everything else.
Add this code:
function OnAsteroidTaken(id, owner)
if id == 1 and owner == 1 then
gamewon = 1
return
end
if id == 0 and owner == 2 then
gamewon = 2
return
end
end
(http://img683.imageshack.us/img683/6806/72432968.jpg)
41.
function OnAsteroidTaken is triggered every time an asteroid changes owner.
We can put If statements in there to check the asteroid and the owner, and if appropriate, change the gamewon variable to either 1 or 2.
Once we change the gamewon variable to something other than 0, the While loop that we made in our function LevelLogic() for the victory/defeat code ends. Straight after that loop ends, the gamewon variable is evaluated to see whether the player lost or won. Go and look again at the code in step 39 and make sure you understand how this works.
Now you should understand the mechanism of our victory/defeat detection system.
Lets give it a try:
(http://img686.imageshack.us/img686/4022/57887165.jpg)
(http://img199.imageshack.us/img199/13/99095502.jpg)
42.
Now you know enough to begin making your own levels.
I hope you will read the LUA Scripting Reference (http://www.dyson-game.com/smf/index.php?topic=212.0) as well and see all the crazy things it's possible to change in this game, and let your imagination run wild :>
Happy coding,
-Fluffy
I really hope a wild map coder appears soon D:
The forums could need it, And I'm quite annoyed by the amount of guests but no users too, but I don't really mind it either... I like to talk: maybe noticed xD
It's so sad that many people are shy at the internet, nobody knows you, and if you make a mistake, atleast here, nobody cares: we just wanna help :)