SuperTux2 Level Editor - Candle Object

This topic was published by and viewed 1396 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author

  • Jarret Buse
    • Topics - 25
    • @jbuse1

    One of the objects in SuperTux is the Candle. The Candle Object is very useful for ambiance in a dark place.

    By making the Sector's AmbientLight to a dark color (not completely black), the candles produce light around itself.

    When placing candles in a Sector, the candles can be given a name. The candle name is not required, but if you want to be able to manipulate the candle it must have a name.

    By manipulating a candle, you have two methods by which you can do so. The methods are:


    The first method, "get_burning()", is used to test if a candle is presently burning. The result is either "true" or "false". The result is "true" when the candle is currently lit and "false" is it is not burning.

    The second method, "set_burning(boolean)", allows you to set whether the candle is burning or not. If the candle is currently extinguished, by setting the method to "true", the candle will relight. If the candle is lit, the flame will go out if the value "false" is passed to the method.

    For example, a candle is placed in the Sector and given the name "candle1" and it is set be burning when the level begins. It can be manipulated when Tux enters a ScriptTrigger. If Tux enters a ScriptTrigger and we want the candle to be extinguished if it is lit or lit if it is extinguished: the code would be:

    if(candle1.get_burning()==true) {

    Let's break this down a bit. The first line is an "if' statement. An "if" statement checks to see if a condition is true or false. Depending on the result, certain statements will be executed. In the "if" statement, the condition being tested is that candle1 is currently burning. In the statement, the method "get_burning()" is being checked on the object "candle1". If the condition is true (==true), then perform the statements within the curly brackets ({}). The statement being run if the condition is true is "candle1.set_burning(false);" is executed. Here, the method for the "candle1" object causes the fire to be extinguished on the candle. More statements can be placed between the curly brackets which is called a Block.

    The first Block is ended with a closing curly bracket followed by the word "else". The "else" statement allows for another Block of statements to be processed if the condition is "false". The whole statement is an "if-else" statement. So, if "candle1" is not burning, then set it to burning.

    NOTE: Be aware that if multiple candles have the same name, the Methods will not work. Each Object must have a unique name.

    The "boolean" refers to a condition of wither "true" or "false". Since "get_burning" returns a boolean value, it is either "true" or "false". The "set_burning" method requires a boolean value of either "true" or "false". When setting the value, the value should not be placed in quotes.

    For an example, I have included a SuperTux Level (stl) called "Haunted Castle.stl". On the level are columns of 3 candles. The first column has three candles name "candle1a", "canlde1b" and "candle1c". The second column of candles are called "candle2a", "candle2b" and "candle2c". Between the two columns is a ScriptTrigger with the following script:

    if(candle1a.get_burning()==true) {

    The first block is used to turn on the candles to the right of the ScriptTrigger and turn off the candles to the left of Tux. When Tux moves to the right side of the screen, this makes the candles turn on as he walks along. The candles behind him turn off. The second block of code does the same thing when Tux walks to the left side of the screen.

    Open the "Haunted Castle.stl", the level is shown in Figure 1, in the Level Editor and play it to see how the script works. There are multiple ScriptTriggers for other candles until Tux reaches the end of the hallway. There is no exit or level end since the reason for the level is to see how the script works.

    Figure 1 (SuperTux Haunted House)
    Figure 1 (SuperTux Haunted House)

    Before starting the level, copy the Scary.ogg and to the "/usr/share/games/supertux2/music" folder.

    If you look at the level, you can see that I also included Thunderstorm and Ghost Particles to make the level "haunted". There are windows on the background level to allow the lightning flashes to be visible.

    The Ghost Particles are placed behind the foreground and in front of the Interactive layer. Because of the layer placement, the Ghosts will not be visible in front of the foreground bricks so they only appear in the hallway with Tux.

    Haunted-House (SuperTux Level) -

    Further Reading

    You must be logged in to view attached files.
Viewing 1 post (of 1 total)