-- * function for rounding up decimals to a precise amount of places * --
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
-- * function for generating a random value * --
function rand(a, b)
math.randomseed(os.time())
-- + --
if a == nil and b == nil then
return math.random()
elseif a ~= nil and b ~= nil then
return math.random(a, b)
else
return math.random(a)
end
end
print( round(rand(), 2) ) -- random decimal value between 0.0 and 1
print( rand(3,7) ) -- random value between 3 and 7
print( rand(5) ) -- random value between 0 and 5
print( os.time() .. " = " .. os.date("!%c", os.time()) )
local x, y
function isRectInsidePolygon(obj, w, h)
x = (game.ScrollPosition.x + getCursorPos().x); y = (game.ScrollPosition.y + getCursorPos().y)
p1 = { x = (x - 1), y = (y - 1) }
p2 = { x = (x + w), y = (y - 1) }
p3 = { x = (x - 1), y = (y + h) }
p4 = { x = (x + w), y = (y + h) }
if not isPointInsidePolygon( p1, obj ) and not isPointInsidePolygon( p2, obj ) and not isPointInsidePolygon( p3, obj ) and not isPointInsidePolygon( p4, obj ) then
startAction("Actions[no]")
else
startAction("Actions[yes]")
end
end
isRectInsidePolygon(game.CurrentScene.SceneObjects["Rock"].ObjectPolygon, 15, 22)
function objectDetect()
Objects.OBJ_symbol.ObjectOffset = { x = ( getCursorPos().x - 35 ), y = ( getCursorPos().y - 39 )}
for k,v in pairs(Objects.OBJ_symbol.ObjectPolygon) do
local point = { x = v["x"], y = v["y"]}
local poly = Objects.OBJ_heart_01.ObjectPolygon
if isPointInsidePolygon(point, poly) then
print( "true")
end
end
end
registerEventHandler("mainLoop", "objectDetect")