Hello,
I just wanted to try this out and see if it worked, and it did, pretty well:
displayMode(FULLSCREEN)
function setup()
props = {}
table.insert(props,physics.body(CHAIN,loop,
vec2(0,0),
vec2(WIDTH,0),
vec2(WIDTH,HEIGHT),
vec2(0,HEIGHT),
vec2(0,0)
))
for i = 1,200 do
local box = physics.body(POLYGON,vec2(-10,-10),vec2(-10,10),vec2(10,10),vec2(10,-10))
box.type = STATIC
box.restitution = .5
box.x = math.random()*WIDTH
box.y = math.random()*HEIGHT
table.insert(props,box)
end
player = physics.body(CIRCLE,10)
player.x = math.random()*WIDTH
player.y = math.random()*HEIGHT
player.sleepingAllowed = false
lightMesh = mesh()
lightMesh:setColors(255,255,255,255)
end
function draw()
background(0, 0, 0, 255)
physics.gravity(Gravity)
for i,v in ipairs(props) do
--drawBody(v)
end
pushStyle()
strokeWidth(3)
local res = 3
lightVertices = {}
for i = 1, 360*res do
local endPos = vec2(
player.x+math.cos(math.rad(i/res))*WIDTH,
player.y+math.sin(math.rad(i/res))*HEIGHT)
local raycast = physics.raycast(vec2(player.x,player.y),endPos)
if raycast then
table.insert(lightVertices,raycast.point)
end
end
local lightFan = {}
for i = 1,#lightVertices do
local currentObj = lightVertices[i]
local neighborObj = lightVertices[(i % #lightVertices)+1]
table.insert(lightFan,player.position)
table.insert(lightFan,currentObj)
table.insert(lightFan,neighborObj)
end
lightMesh.vertices = lightFan
lightMesh:draw()
ellipse(player.x,player.y,player.radius*2)
popStyle()
end
function drawBody(body)
pushMatrix()
translate(body.x, body.y)
rotate(body.angle)
if body.type == STATIC then
stroke(255,255,255,255)
elseif body.type == DYNAMIC then
stroke(150,255,150,255)
elseif body.type == KINEMATIC then
stroke(150,150,255,255)
end
if body.shapeType == POLYGON then
strokeWidth(3.0)
local points = body.points
for j = 1,#points do
a = points[j]
b = points[(j % #points)+1]
line(a.x, a.y, b.x, b.y)
end
elseif body.shapeType == CHAIN or body.shapeType == EDGE then
strokeWidth(3.0)
local points = body.points
for j = 1,#points-1 do
a = points[j]
b = points[j+1]
line(a.x, a.y, b.x, b.y)
end
elseif body.shapeType == CIRCLE then
strokeWidth(3.0)
line(0,0,body.radius-3,0)
ellipse(0,0,body.radius*2)
end
popMatrix()
end