To create a script for this library, you must define a function that looks something like this:
function myThing(x, y)
-- ...
endAs you may already have guessed, this function gets passed the X and Y coordinates for the particle it creates. This function must return either a falsey value (like nothing, or false) when you want no particle to be created in the X,Y location. Otherwise, this function must return a table of values that specify the particle about to be created. The only value you have to include is type.
(Other values which you can include are life, ctype, x, y, vx, vy, temp, flags, tmp, tmp2, dcolour.)
function myThing(x, y)
return {
type = 'DMND',
dcolour = 0xFF00FF00,
tmp = 1
}
endThe above code is actually a valid callback - it will make the entire screen into DMND.
function myThing(x, y)
if x == 200 and y == 300 then
return { type = 'DMND' }
end
endThis script will make only the particle at (200, 300) into DMND. Everything else will be left untouched.
For a more complex example, see the script below:
function myThing(x, y)
-- Define a center point for the circle.
local hw = 612/2
local hh = 384/2
-- Calculate the distance between the current point and the center point.
-- A = (x, y), B = (hw, hh) in this image:
-- http://mathurl.com/pnjv5wv
local dist = math.sqrt(
(x - hw) * (x - hw) +
(y - hh) * (y - hh)
)
-- If said distance is more than 30 but less than 31 then create the particle.
if dist > 30 and dist < 31 then
return { ['type'] = 'dmnd' }
end
-- Otherwise create no particle.
endTo run any of the above scripts, define the function and afterwards call the runner function defined in my script
with the function as its only parameter.
runner(myThing)Alternatively you could define the function inline and not even name it:
runner( function(x, y) ... end )... And the rest is up to you. Good luck!