Module level

Level related variables and functions.

Functions

getBlockAt (x, y) Finds a block in the specific coordinates.
getAllBlocks () Gets a list of all blocks existing in the level.
switchblocks (x1, y1, x2, y2) Given the coordinates of two blocks, turn all blocks in the level of each type into the other.
newAlien (speed, seed, vars) Summons a (client-sided) alien.
removeAllAliens () Removes all Lua-created aliens from the client.
newArtLayer (depth, layerNum) Creates a (client-sided) artlayer, which can be drawn to via Lua, and have sprites and stamps applied to it.
destroyAllArtLayers () Destroys all Lua-created art layers.
newStamp (width, height) Creates a new raster-graphics stamp, which can be drawn to via Lua, and be applied to artlayers and other stamps.
destroyAllStamps () Destroys all Lua-created stamps.
newSprite () Creates a new vector-graphics sprite, which can be drawn to via Lua, and be applied to artlayers and other stamps.
destroyAllSprites () Destroys all Lua-created sprites.

Fields

minX The left-most boundary of the level.
maxX The right-most boundary of the level.
minY The top-most boundary of the level.
maxY The bottom-most boundary of the level.


Functions

getBlockAt (x, y)
Finds a block in the specific coordinates.

Parameters:

  • x int The absolute x position.
  • y int The absolute y position.

Returns:

    block Returns the found block, or nil if not found.
getAllBlocks ()
Gets a list of all blocks existing in the level.

Returns:

    An AS3 array of all blocks in the level.

See also:

Usage:

    local blocks = totable(game.level.getAllBlocks())
    for i, v in pairs(blocks) do
        v.setmetatable("index", i)
    end
switchblocks (x1, y1, x2, y2)
Given the coordinates of two blocks, turn all blocks in the level of each type into the other.

Parameters:

  • x1 int The absolute x position of the first block.
  • y1 int The absolute y position of the first block.
  • x2 int The absolute x position of the second block.
  • y2 int The absolute y position of the second block.
newAlien (speed, seed, vars)
Summons a (client-sided) alien.

Parameters:

  • speed float The multiplier to apply to the alien's movement speed. By default 1.
  • seed float The seed number for the alien's pseudorandom number generator, which generates its behavior. A random seed will be generated if none is provided.
  • vars An AS3 object containing the parameters for the alien's behavior. By default nil. All fields listed in the alien module (except alienspeed) can be set via this vars object.

Returns:

    alien The summoned alien as an object. Can be used to get and set its x and y position, among other things.

See also:

Usage:

    local funnyAlien = game.level.newAlien(1, os.time(), toobject{damage = 9999})
    funnyAlien.x, funnyAlien.y = 0, 0
removeAllAliens ()
Removes all Lua-created aliens from the client.
newArtLayer (depth, layerNum)
Creates a (client-sided) artlayer, which can be drawn to via Lua, and have sprites and stamps applied to it. This function fails and returns nil if the player has backgrounds disabled in their settings.

Parameters:

  • depth float The depth of the art layer. By default 1.
  • layerNum int The layerNum of the art layer (equivalent to the ">" icon in Level Editor). By default 1. Greater layerNum layers are drawn above lesser layerNum layers, regardless of layer depth. layerNums of 2 or greater draw above blocks. 3 or greater draws above players, hats, projectiles, and other visual effects.

Returns:

    artlayer The new art layer, or nil if the player has backgrounds disabled in their settings.

See also:

Usage:

    local layer = tolua(game.level.newArtLayer(1, 3))
    if layer then
        layer.drawStamp(someStamp)
    end
destroyAllArtLayers ()
Destroys all Lua-created art layers.
newStamp (width, height)
Creates a new raster-graphics stamp, which can be drawn to via Lua, and be applied to artlayers and other stamps. This function fails and returns nil if the player has backgrounds disabled in their settings or if the given width and/or height were invalid.

"Raster graphics" refers to pixel data. Stamps are used for directly storing and manipulating pixel data before drawing to an artlayer, rather than performing the more artsy operations you'd find on a sprite.

An example use case is to draw some pixel data and then draw it to an art layer with some translation, scaling, and/or rotation applied. Another example use case would be to draw the same pixels to multiple art layers. Instead of repeating the same draw operations for each layer, you can perform the operations to one stamp, and then draw the stamp to each layer.

Parameters:

  • width int The width of the stamp in pixels. By default 64. This value is clamped to the range of 1-512.
  • height int The height of the stamp in pixels. By default 64. This value is clamped to the range of 1-512.

Returns:

    stamp The new stamp, or nil if the player has backgrounds disabled in their settings.

See also:

Usage:

    local stamp = tolua(game.level.newStamp(500, 500))
    if stamp then
        stamp.setRect(0, 0, 500, 500, 0xFF000000)
        someLayer.drawStamp(stamp)
    end
destroyAllStamps ()
Destroys all Lua-created stamps. Does not undraw any stamps already drawn to any existing art layers.
newSprite ()
Creates a new vector-graphics sprite, which can be drawn to via Lua, and be applied to artlayers and other stamps. This function fails and returns nil if the player has backgrounds disabled in their settings.

"Vector graphics" refers to artsy shape data, such as lines, circles, gradients, text, etc. The functions available to a sprite are very similar to drawing tools you'd find in an art program or in the Level Editor / Block Editor. This contrasts to the raw data-driven manipulations available for a stamp.

A sprite may also be set as the "parent" of other sprites or stamps, meaning that they will also be rendered whenever the sprite is rendered to an art layer, and with the same transformations as the sprite.

Returns:

    sprite The new sprite, or nil if the player has backgrounds disabled in their settings.

See also:

Usage:

    local sprite = tolua(game.level.newSprite())
    if sprite then
        sprite.beginFill(0xFF000000) -- Draw everything with a solid, fully opaque black.
        sprite.drawCircle(0, 0, 250)
        sprite.endFill()
        someLayer.drawSprite(sprite)
    end
destroyAllSprites ()
Destroys all Lua-created sprites. Does not undraw any sprites already rendered to any existing art layers or stamps.

Fields

minX
The left-most boundary of the level. No blocks exist beyond those coordinates. The player will be safetied if they travel too far beyond these bounds. Read-only.
maxX
The right-most boundary of the level. No blocks exist beyond those coordinates. The player will be safetied if they travel too far beyond these bounds. Read-only.
minY
The top-most boundary of the level. No blocks exist beyond those coordinates. The player will be safetied if they travel too far beyond these bounds. Read-only.
maxY
The bottom-most boundary of the level. No blocks exist beyond those coordinates. The player will be safetied if they travel too far beyond these bounds. Read-only.
generated by LDoc 1.5.0 Last updated 2023-11-25 17:53:31