Orbits.lua
~Not yet released or pushed to the SMBX2 repo. for Beta 4.~
orbits.lua allows the creation of various NPC circles. Originally intended for coin circles (as can be seen in NSMBWii) but as can be seen in the list of args below, any ID can be used. At this time it is suggested that you only create coin/Rupee circles, Boo circles, and firebar circles. There is no guaranteed support for all NPCs but feel free to do what you wish with this API.
Download Latest Version: Not yet available to be downloaded
For an example, see the level included which has fully documented code.
Installation
Place the file orbits.lua into the LuaScriptsLib folder.
Documentation
To enable the orbits library for a specific level, add this line to lunadll.lua:
local orbits = API.load("orbits");
This will load the orbits API.
The Creator Function
This function creates an orbit. Only create orbits onStart(); they SHOULD NOT be created in onTick(), onDraw(), etc. (though some exceptions may apply).
| new{named args} |
|---|
The following are named arguments usable to create an orbit:
| x | int | X-coordinate of the center of the orbit. (Required unless following an NPC.) |
|---|---|---|
| y | int | Y-coordinate of the center of the orbit. (Required unless following an NPC.) |
| speedX | int | Horizontal speed of the orbit. (Default: 0) |
| speedY | int | Vertical speed of the orbit. (Default: 0) |
| attachToNPC | table or NPC | See below for description. |
| radius | int | The radius of the orbit. (Default: orbits.DEF_RADIUS, which unless changed is 96) |
| radiusX | int | The horizontal radius of the orbit. Used to create ellipses. |
| radiusY | int | The vertical radius of the orbit. Used to create ellipses. |
| id | int | The ID of the orbiting NPCs. (Default: 10--SMB3 Coin) |
| number | int | The number of orbiting NPCs. (Default: 4) |
| rotationSpeed | int | The speed of the orbit's revolutions. (Default: orbits.DEF_ROTATIONSPEED, which unless changed is 256) |
| friendly | bool | Whether or not the orbiting NPCs can harm the player. (Default: false--can hurt the player) |
| placeCenter | bool | Whether or not the center of the circle should be indicated by a block being placed. (Default: false--don't place a block) |
| centerID | int | The ID of the center block; only matters if placeCenter is true. (Default: orbits.DEF_CENTERID, which unless changed is 630--SMB3 dungeon stone ball) |
Arg: attachToNPC
Can be used to attach an orbit to any NPC in the level. The following are options for attaching an orbit to an NPC:
local orbits = API.load("orbits");
function onStart()
orbits.new{...attachToNPC = {x = -200000, y = -200000, id = 1}...};
end
This is best when the NPC has been placed in the editor. The arguments of the attachToNPC table are as follows:
local orbits = API.load("orbits");
local myOrbit;
function onTick()
local npc = NPC.get(1)[1];
if myOrbit == nil then
myOrbit = orbits.new{...attachToNPC = npc...};
end
end
This is best during runtime, especially for LunaLua-spawned NPCs are unique NPCs (such as bosses) that there are only one of as it is more condensed. The only argument is an NPC object.
Other Functions
The following functions are also available for use via this library:
| getOrbitingNPCs | uid | |
|---|---|---|
| Returns all of the NPCs in a given orbit, based on uid. | table of NPC | number
The uid returned by the creator function of the desired orbital. |
| getFollowedNPC | uid | |
| Returns the NPC being followed in a given orbit, based on uid, that is following an NPC. | NPC or nil | number
The uid returned by the creator function of the desired orbital. |
| destroy | uid | |
| Removes an orbit. | nil | number
The uid returned by the creator function of the desired orbital. |