Modifying the gameplay

Since the gameplay is about to change, this may change in future as well.

The gameplay is defined by two components:

  • game.lua: creates the game, the player, manages projectiles, enemies
    • loads enemy behavior files (scripts/enemies) which steer the enemie's actions
  • levelfile: can load further scripts if the player reaches a certain point

The easiest way to manipulate the gameplay is to use the mapeditor and use the trigger scripts to load additional scripts. These scripts can install various hooks or can change parameters (player's health, ship masses etc), so these scripts can be very powerful. Currently, these scripts are located in the directory "scripts/ingame" and are then loaded without the directory prefix. These scripts will be moved into a levelfile dependent directory.

There's currently a script located: "scripts/ingame/repair.lua".

This script can be loaded if the mapeditor places a triggernode that loads "repair.lua". The script is quite simple:

local damagerestore = {delay = 0}
function damagerestore:think()
    if game.player.destroyed then return 1 end
    self.delay = self.delay + 1
    if game.player.extracounter>=40 and 
            Keyboard.isKeyDown("R") and 
            self.delay>20 and 
            game.player.hp<100 then
        self.delay = 0
        game.player.hp = 100
        game.player.extracounter = 
            game.player.extracounter - 40
    end
end

game:addthink(damagerestore)

Always keep in mind that everything must be GCable? and that a script can (currently) damage the GC process which is required for reloading the level. If for instance a global value is created that points to "game", all the game objects won't be collected, even if they should.

The local table damagerestor keeps a delay value which is used to prevent permanent repairing if the player holds down the key.

The idea of the script itself is to use 40 scrapparts for a full repair of the ship.

The tablecontains also a function named think, which returns 1 if the player is destroyed. If the function returns a value that is not nil or false, the table is removed from the thinking queue. As long as no value is returned from this function, it will be called once per game step (every 20ms). This allows us to check if the player presed buttons or checking for a certain condition. In this case, we register our table as think object (game:addthink(damagerestore)) and from now on, the script is repeated until the player dies. If the player presses "R" and we can actually repair the ship, the values are restored again.

If you want to show a simple message to the player (i.e. "incoming boss"), you can just call

game : showMessage ("incoming boss")