Author Topic: Guide to making levels for Absolute Beginners  (Read 16545 times)

0 Members and 1 Guest are viewing this topic.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Guide to making levels for Absolute Beginners
« on: February 06, 2010, 09:40:03 PM »
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




2.
Click on "Run".




3.
Type "notepad.exe" into the box as shown, and click OK.




4.
Notepad opens.




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:

(click to show/hide)




6.
Now click "File" in the top left of Notepad, and choose "Save As".




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.




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.

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!




10.
When it loads up, this is what it should look like.




11.
If you send a scout to the asteroid next door, you should see that there are enemy seedlings orbiting it.





If you got this far, congratulations - you are through the biggest barrier, which is getting started.  It will be plain sailing from here!
« Last Edit: May 28, 2012, 01:06:17 PM by Eufloria Admin »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #1 on: February 06, 2010, 09:40:34 PM »
Now that we've made a simple level, lets experiment with it by changing some values.



12.
To start with, lets change the number of seedlings that the Player starts with from 90 up to 500.  Make the change indicated below:




13.
Now that we've made the change, it is important that we remember to save the file.  Otherwise our changes won't be apparent when we try to play the level.




14.
Now go back to Eufloria and try loading up the level like before.  You should start with loads of seedlings this time!




15.
Next lets try to change the size of the Player's asteroid.  Make the change indicated below, and don't forget to save the level afterwards by clicking "File" and "Save", like in step 13.




16.
Now load the game up, and lo and behold your asteroid has swollen to epic proportions!




17.
Next lets try changing the maximum number of trees allowed on the Player's asteroid.  Make the change indicated below - make sure you change the right asteroid!  Then save the level again.




18.
Load it up in Eufloria and now we can plant up to 20 trees :>





Now try changing some of the other values yourself.  I would suggest to only change one thing at a time - that way if you accidentally break the level, it's easy to know what to undo to fix the problem.
« Last Edit: February 07, 2010, 12:13:10 AM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #2 on: February 06, 2010, 10:28:17 PM »
19.
Hopefully by now you should be getting an idea of how this works.
You can kind of tell what each line means... it doesn't take a genius to work out that "SendDistance" is how far the asteroid can send seedlings.

However, one command is not so obvious, and that is the AddAsteroidWithAttribs command, which as you might guess is used to create asteroids and set their basic attributes.  Lets take a moment to look at that line, because it's a good example to teach us about the other commands as well.



Lets deal with the bits in brackets first.

There are 5 values seperated by commas.

The first two values are the X and Y coordinates of the asteroid - it tells the game where on the map the asteroid is located.  These have to be integers (whole numbers).

This map hopefully gives you an idea of what sort of values you can use.






20.
The next three values are the Energy, Strength, and Speed of the asteroid.



You can use any number between 0 and 1.  So you could have 0.5, or you could have 0.55555 or whatever you like really.




21.
Now that we've dealt with the brackets, lets look at the bit at the start:



The command starts with an "a = ".  The "a" is sort of like the name of the asteroid that we are creating.
Then we can use the various functions and property commands to tell the game what the asteroid is like.

This is what a.TreeCap is doing - we refer to the asteroid called "a", and then we tell the game that "a" has a Tree Cap of...whatever we set it to.






22.

You might notice that we use "a" a second time to make the second asteroid:



It doesn't matter if we use it twice in a row like that.  When we use it to make the second asteroid, we are just telling the game to "forget" which asteroid "a" is, because now this asteroid is called "a".  We just overwrite the old value by declaring a new one.

Then we can set the properties for the second asteroid using the same commands like before, such as "a.TreeCap" and "a:AddSeedlings()" and so on.

Note: You can give each asteroid a unique name if you wish, rather than just re-using "a" all the time.  This can actually be useful if you want to refer to them in your scripts later on.
fluffy = AddAsteroidWithAttribs is perfectly acceptable.  :>  fluffy.TreeCap and other commands will work without problems.



"a." (with a dot) is used to set properties, and "a:" (with a colon) is used for functions.  You must be careful not to mix them up, or the level won't load.
A complete list of the different commands you can use for asteroid properties can be found in the LUA Scripting Reference Sticky.




23.
Finally, the complete command looks like this:

NAME = AddAsteroidWithAttribs(Horizontal Position,Vertical Position,Energy,Strength,Speed)




24.
Now to try adding a new asteroid to your level.

You need to make sure you put it within the bounds of the function LevelSetup().  That is, it must appear after the LevelSetup() command, and before the end command, as shown.



Lets make an asteroid by typing in the code for it where the red arrow indicates.

First we should make a comment to remind ourselves later on that this is Asteroid 2 (remember we had asteroid 0, 1, and this will be asteroid 2).
So type in "-- Asteroid 2" like this:






25.
Now lets type the command to add an asteroid, and pick some values for the new asteroid.
I'll use coordinates 2000, -2000 and energy 0.8, strength 0.6, speed 0.9.






26.
To save some time, I'll copy and paste the commands I used on the previous asteroids.






27.
Now I'll change the values around a bit to make the asteroid the way I want it:






28.
Now lets save the level, load it up, and check out the new roid! :D







29.
There are some other nifty commands you can use in LevelSetup.
A really handy one is SetBackdropColour() which lets you change the background colour using 3 comma-seperated RGB values between 0 and 255.
Lets make the background red!






30.
And the fruits of our work so far....







31.
Maybe you noticed by now that the asteroid positions don't seem to be quite right.  Because of their large size the game is squashing them apart.
To prevent this behaviour, add this line to each of your asteroids:






32.
Save the level and try playing it.  Now the asteroids are positioned exactly where we specified them in our coordinates.  :>

« Last Edit: February 08, 2010, 07:29:01 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #3 on: February 06, 2010, 10:31:06 PM »
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.






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:
(click to show/hide)




Load up the level to test it out:





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!).

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.

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.

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.



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.





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.



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. :>







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.





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:
(click to show/hide)



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:
(click to show/hide)





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:









42.
Now you know enough to begin making your own levels.
I hope you will read the LUA Scripting Reference 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
« Last Edit: February 08, 2010, 07:22:53 PM by annikk.exe »

cinemabaroque

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
Re: Guide to making levels for Absolute Beginners
« Reply #4 on: February 06, 2010, 11:16:40 PM »
I would also recommend using the SciTE text editor which has a lot of Lua functionality.  If you are running windows you can go to http://luaforwindows.luaforge.net/ and download Lua for Windows which has SciTE and other Lua documentation and examples as well as a Lua command line which is sometimes useful for testing out scripts before you drop them into your game.

It has tabbed windows and color coding specific to Lua.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #5 on: February 06, 2010, 11:46:28 PM »
yeah I use Notepad ++ which I highly recommend.  Does basically the same thing you are describing.  If you are getting serious with your level design it's highly recommended to get one of these programs.  :>

But I felt for a basic guide, advanced text editors were maybe a bit beyond the necessary scope..

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #6 on: February 07, 2010, 06:12:56 PM »
Feedback on this would be great :>

Rudolf

  • Administrator
  • Old Oak
  • *****
  • Thank You
  • -Given: 4
  • -Receive: 13
  • Posts: 635
  • Euflorian Ambassador
    • Omni Systems Limited
  • Eufloria: Yes
Re: Guide to making levels for Absolute Beginners
« Reply #7 on: February 07, 2010, 06:43:56 PM »
This is an extremely useful level creation guide, many thanks to annik for putting things together. The key thing is to try to replicate these kinds of typical level functionality in a few tryout levels, so you really understand what is going on, and then start to make your own variations. Then you can start to study all the additional things you can do, for example as descibed in the scripting reference thread. (http://www.dyson-game.com/smf/index.php?topic=212.0)

I think this is really going to help loads of people Annik, we should try to get this content on ModDB as well and invite some modders over :-)
I will mail you about this!
-----------------------------------------------------
Rudolf Kremers - Grand Poobah

http://www.omni-labs.com
http://www.rudolfkremers.com
http://rudolfkremers.tumblr.com/

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #8 on: February 07, 2010, 07:40:52 PM »
Thanks.  Am still proof-reading/editing.  I replied to your email. :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #9 on: February 08, 2010, 07:40:49 PM »
Just made another raft of changes to it, trying to clarify some bits... changed the greeting text to make more sense with the winning conditions, etc

If anyone is super-bored and happens to be reading through this and notices any continuity errors or anything, please let me know.  :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #10 on: February 15, 2010, 05:21:23 AM »
This has been posted on moddb.com now, but it's still awaiting authorisation.

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: Guide to making levels for Absolute Beginners
« Reply #11 on: August 11, 2010, 11:07:03 PM »
@annikk.exe



Much much thanks for this guide i really am glad there are great people like you sharing their lvl making wisdom :D  ;D
i noticed some things that were unclear so if i get the time i'll make a list of feedback on the guide :)
thanks again for the guide, us dummies (in lvl making) are really helped by this :D.
Gonna have some lvl fun now :D

P.S. : i worked trough the guide making the lvl (playing around with some values :P).
I got everything to work except for the sending of the reinforcements
the spawning of those 400 seeds and the sending is at the same time and because of that dyson sends all seedling at the planet and then spawns 400.
The result is that only 100 ( the starting ones) seedlings are send at your planet and the 400 reinforcements stay at the enemy's planet.
I tried fixing it by setting a new timer but then it first wait's like 5 seconds before it sends those 400
 ??? ??? ???

BC wins
« Last Edit: August 12, 2010, 09:40:56 PM by BC wins »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #12 on: August 15, 2010, 12:18:30 AM »
Can you post your code, BC?  I'll have a look :>


By the way, is it ok if I post my reply to your PM on the forum?  Then others can benefit from it too :>

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: Guide to making levels for Absolute Beginners
« Reply #13 on: August 16, 2010, 12:15:47 AM »
ofcourse :)
i'll post a spoiler in that topic :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Guide to making levels for Absolute Beginners
« Reply #14 on: August 16, 2010, 08:04:20 AM »
BC's PM and my reply:



Quote
Hi Smiley
i read your guide and made the level ready to make some of my own but for that i am wondering what those global values mean

-- Set Global Values
   Globals.G.Asteroids=(0)
   Globals.G.EnemyFactionsMin=(1)
   Globals.G.EnemyFactionsMax=(1)

you don't explain that in your guide

BC wins


Hi BC,

I'll explain each one :>


Code: [Select]
   Globals.G.Asteroids=(0)
This is the "global minimum number of asteroids".  If you don't specifically create more than this number of asteroids, the game will automatically create some for you.

So for example if you used the a = AddAsteroidWithAttribs(1000,1000,1,1,1) command (those values are just examples) and you used it to make three asteroids, but you set the Globals.G.Asteroids value to be 5, then when you load the game, there will be 5 asteroids there - two of them auto-created by the game due to the Global setting.



Code: [Select]
   Globals.G.EnemyFactionsMin=(1)
The minimum number of enemy factions.
If you don't give any asteroid to the enemy faction and this is set to 1 (like in the above example), the game will automatically make one of the asteroids an AI asteroid, and add some seedlings for it.


Code: [Select]
   Globals.G.EnemyFactionsMax=(1)
Continuing on from the logic above, if you set the Max value to 5, the game would create between 1 and 5 AI player asteroids like the one mentioned above.


The reason these are set to 1, is that in the example map in the beginner's guide, there is one enemy faction.  Since we specifically add this faction, these settings mean no additional AI asteroids are added.


Hope this explains it.  :>