Map

Map extends MutableShape, adding functions and properties to it.
Map is not creatable, there's only one instance of it. It can only be accessed through its globally exposed variable.

Map is a global variable that represents the game map.

How to load a map for your game?

Config = {
  Map = "aduermael.rockies"
}
Config.Map = "aduermael.rockies"

(See Config for more details regarding Map & Items loading)

Functions

Adds a Block to the Map.

Returns created Block (or nil if it fails).

local block = Block(1, 10, 10, 10)
someMutableShape:AddBlock(block)

-- AddBlock can also be called using
-- block's palette index and coordinates:
someMutableShape:AddBlock(1, 10, 10, 10)

-- created block is returned:
local newBlock = someMutableShape:AddBlock(1, 10, 10, 10)
if newBlock ~= nil then
  -- block successfully created!
end

-- ⚠️
local block = Block(1, 10, 10, 10)
local newBlock = someMutableShape:AddBlock(block)
-- Here `newBlock` is not the same as `block`
-- they both have the same palette index and coordinates
-- but `newBlock` has a parent shape while `block` doesn't.
nil AddChild ( Object child )

Adds given Object as a child.

Object extensions like Shape or MutableShape are naturally accepted too.

local o = Object()
local myShape = Shape(Items.someuser.someitem)
o:AddChild(myShape)

Gets a Block from the Map.
Returns nil if there is no Block at the given coordinates (i. e. if it's "air").

nil GetChild ( integer index )

Get child Object at index.

if o.ChildrenCount > 0 then
  print(o:GetChild(1)) -- prints first child
end

Unsets parent/child relationship with child parameter. The child ends up being deleted if it has no other references.

o:RemoveChild(someChildObject)

Unsets parent/child relationship with all children. Individual children end up being deleted if they have no other references.

o:RemoveChildren()

Properties

Map's continuous acceleration.

Default value: {0,0,0}.

⚠️ Acceleration is nil and can't be set if Map.Physics is false.

-- Acceleration can be used to compensate gravity: 
myObject.Acceleration = -Config.ConstantAcceleration
-- myObject's acceleration is now the invert of 
-- Config.ConstantAcceleration, cancelling it.

Returns number of child Objects.

number Depth read-only

Returns Map's depth, measured in cubes.

number Height read-only

Returns Map's height, measured in cubes.

Can be set to true for the Map to be hidden.
Nothing else changes, the Map remains in the scene and it keeps being affected by the simulation (collisions, etc.).

boolean IsOnGround read-only

true when the Map is not falling.

⚠️ IsOnGround only makes sense when Map.Physics is true.

Returns an array of BlockProperties (Palette)

Note: non-opaque and light emissive block colors can't be changed after game start.

number LossyScale read-only

Convenience property that attempts to match the actual world scale as much as it can.

number Width read-only

Returns Map's width, measured in cubes.