Apc.lua
apc.lua (advanced player collisions)
This library adds a couple of new block types to SMBX, as well as advanced player collision detectors.
It requires the Colliders and Vectors libraries in order to work. To install, just unpack apc.lua and drop it into the LuaScriptsLib.
apc.lua can be called with:
local apc = loadAPI("apc")
Values
Variables to access
| Name | Type | Description |
|---|---|---|
| apc.debug | boolean | If set to true, the primitive collider objects created with this library will be visible. |
| ropeBlocks | table | Contains the IDs of all rope-type blocks in the level. (nil if there aren't any) |
| bouncySpikes | table | Contains the IDs of all bouncy spike blocks in the level. (nil if there aren't any) |
| p1colliders | table | Contains a box collider on each side of player 1. They can be called collectively, or one at a time by adding .top, .left, .right, or .bottom to the end. (ex: p1colliders.top) |
| p2colliders | table | Contains a box collider on each side of player 2. They can be called collectively, or one at a time by adding .top, .left, .right, or .bottom to the end. (ex: p2colliders.top) |
Block Functions
These are functions which change the behavior of blocks. Note that each function may only be used once, but it will accept a table for its argument. These functions must be called in onLoop(), but to prevent lag, it is recommended to only run them on the first loop of the level. (See usage example below.)
| apc.rope | ids | |
|---|---|---|
| This function makes the selected block(s) behave like a "rope-type" block. If you play SMW hacks, you may have seen these. A "rope-type" block behaves like a cloud block, but you can go through it if you press DOWN. This only works if used on a cloud-type block. | ropeBlocks | table
ID(s) of blocks to be this type. Use cloud-type blocks ONLY. |
| apc.bouncySpike | ids | |
| This function makes a block act like an upward pointing spike block, but spinjumping on it will bounce the player instead of harming him. The block must NOT already harm the player, or it won't work. It is not recommended to place this block on a moving layer, as it will not work correctly. | bouncySpikes | table
ID(s) of blocks to be this type. Do not place on a moving layer. |
Usage Examples
local apc = loadAPI("apc")
function onLoop()
if not oneTimeStuff then
oneTimeStuff = true
apc.rope{8}
apc.bouncySpike{1}
end
end
This will cause block-8 to become a rope-type block and block-1 to become a spinjumpable spike block.
local apc = loadAPI("apc")
function onLoop()
for k,v in pairs(Block.get()) do
if (colliders.collide(p1colliders.top, v)) or (colliders.collide(p1colliders.left, v)) or (colliders.collide(p1colliders.right, v)) then
if not (colliders.collide(p1colliders.bottom, v)) then
v:remove(true)
end
end
end
end
This will destroy all blocks the player touches except the ones on which he is standing.