2014-09-26 16:48:46 +00:00
|
|
|
--[[
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2014-11-28 21:56:05 +00:00
|
|
|
Copyright (c) 2014 Marcus Ihde, Tim Anema
|
2014-09-26 16:48:46 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
]]
|
2014-10-27 19:16:21 +00:00
|
|
|
local _PACKAGE = string.gsub(...,"%.","/") or ""
|
|
|
|
if string.len(_PACKAGE) > 0 then
|
|
|
|
_PACKAGE = _PACKAGE .. "/"
|
|
|
|
end
|
|
|
|
local class = require(_PACKAGE..'class')
|
|
|
|
local Light = require(_PACKAGE..'light')
|
|
|
|
local Body = require(_PACKAGE..'body')
|
|
|
|
local util = require(_PACKAGE..'util')
|
|
|
|
local normal_map = require(_PACKAGE..'normal_map')
|
|
|
|
local PostShader = require(_PACKAGE..'postshader')
|
|
|
|
require(_PACKAGE..'postshader')
|
2014-09-26 16:48:46 +00:00
|
|
|
|
2014-09-26 20:52:16 +00:00
|
|
|
local light_world = class()
|
|
|
|
|
2014-10-27 19:16:21 +00:00
|
|
|
light_world.blurv = love.graphics.newShader(_PACKAGE.."shaders/blurv.glsl")
|
|
|
|
light_world.blurh = love.graphics.newShader(_PACKAGE.."shaders/blurh.glsl")
|
|
|
|
light_world.refractionShader = love.graphics.newShader(_PACKAGE.."shaders/refraction.glsl")
|
|
|
|
light_world.reflectionShader = love.graphics.newShader(_PACKAGE.."shaders/reflection.glsl")
|
2014-09-29 14:03:15 +00:00
|
|
|
|
2014-10-03 00:32:31 +00:00
|
|
|
function light_world:init(options)
|
2014-09-26 20:52:16 +00:00
|
|
|
self.lights = {}
|
|
|
|
self.body = {}
|
2014-10-06 21:27:41 +00:00
|
|
|
self.post_shader = PostShader()
|
2014-09-29 14:03:15 +00:00
|
|
|
|
|
|
|
self.ambient = {0, 0, 0}
|
2014-10-03 00:32:31 +00:00
|
|
|
|
2014-09-29 14:03:15 +00:00
|
|
|
self.refractionStrength = 8.0
|
|
|
|
self.reflectionStrength = 16.0
|
2014-09-26 20:52:16 +00:00
|
|
|
self.reflectionVisibility = 1.0
|
2014-10-03 00:32:31 +00:00
|
|
|
|
2014-09-29 14:03:15 +00:00
|
|
|
self.blur = 2.0
|
2014-10-03 00:32:31 +00:00
|
|
|
self.glowBlur = 1.0
|
2014-10-27 13:20:01 +00:00
|
|
|
|
2014-10-03 00:32:31 +00:00
|
|
|
self.glowTimer = 0.0
|
|
|
|
self.glowDown = false
|
|
|
|
|
|
|
|
self.drawBackground = function() end
|
2014-10-28 01:32:51 +00:00
|
|
|
self.drawForeground = function() end
|
2014-10-03 00:32:31 +00:00
|
|
|
|
|
|
|
options = options or {}
|
|
|
|
for k, v in pairs(options) do self[k] = v end
|
2014-09-29 14:03:15 +00:00
|
|
|
|
2014-10-08 12:55:05 +00:00
|
|
|
self:refreshScreenSize()
|
2014-09-26 20:52:16 +00:00
|
|
|
end
|
2014-09-26 17:38:55 +00:00
|
|
|
|
2014-10-08 12:55:05 +00:00
|
|
|
function light_world:refreshScreenSize(w, h)
|
|
|
|
w, h = w or love.window.getWidth(), h or love.window.getHeight()
|
|
|
|
|
2014-10-06 13:31:14 +00:00
|
|
|
self.render_buffer = love.graphics.newCanvas(w, h)
|
2014-11-28 15:55:43 +00:00
|
|
|
self.normal = love.graphics.newCanvas(w, h)
|
|
|
|
self.normal2 = love.graphics.newCanvas(w, h)
|
2014-10-06 13:31:14 +00:00
|
|
|
self.normalMap = love.graphics.newCanvas(w, h)
|
2014-11-30 00:10:15 +00:00
|
|
|
self.shadowMap = love.graphics.newCanvas(w, h)
|
2014-10-06 13:31:14 +00:00
|
|
|
self.glowMap = love.graphics.newCanvas(w, h)
|
|
|
|
self.glowMap2 = love.graphics.newCanvas(w, h)
|
|
|
|
self.refractionMap = love.graphics.newCanvas(w, h)
|
|
|
|
self.refractionMap2 = love.graphics.newCanvas(w, h)
|
|
|
|
self.reflectionMap = love.graphics.newCanvas(w, h)
|
|
|
|
self.reflectionMap2 = love.graphics.newCanvas(w, h)
|
|
|
|
|
|
|
|
self.blurv:send("screen", {w, h})
|
|
|
|
self.blurh:send("screen", {w, h})
|
|
|
|
self.refractionShader:send("screen", {w, h})
|
|
|
|
self.reflectionShader:send("screen", {w, h})
|
2014-10-03 00:32:31 +00:00
|
|
|
|
|
|
|
for i = 1, #self.lights do
|
2014-10-08 12:55:05 +00:00
|
|
|
self.lights[i]:refresh(w, h)
|
2014-10-03 00:32:31 +00:00
|
|
|
end
|
2014-10-08 12:55:05 +00:00
|
|
|
|
|
|
|
self.post_shader:refreshScreenSize(w, h)
|
2014-09-26 17:38:55 +00:00
|
|
|
end
|
2014-09-27 16:54:48 +00:00
|
|
|
|
2014-10-22 02:48:19 +00:00
|
|
|
function light_world:draw(l,t,s)
|
|
|
|
l,t,s = (l or 0), (t or 0), s or 1
|
2014-10-22 12:37:19 +00:00
|
|
|
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
|
2014-10-22 02:48:19 +00:00
|
|
|
util.drawto(self.render_buffer, l, t, s, function()
|
2014-11-29 13:54:43 +00:00
|
|
|
self.drawBackground( l,t,w,h,s)
|
|
|
|
self.drawForeground( l,t,w,h,s)
|
|
|
|
self:drawMaterial( l,t,w,h,s)
|
|
|
|
self:drawNormalShading( l,t,w,h,s)
|
|
|
|
self:drawGlow( l,t,w,h,s)
|
|
|
|
self:drawRefraction( l,t,w,h,s)
|
|
|
|
self:drawReflection( l,t,w,h,s)
|
2014-10-22 02:48:19 +00:00
|
|
|
end)
|
2014-10-22 12:37:19 +00:00
|
|
|
self.post_shader:drawWith(self.render_buffer, l, t, s)
|
|
|
|
end
|
2014-10-22 02:48:19 +00:00
|
|
|
|
2014-10-22 12:37:19 +00:00
|
|
|
function light_world:drawBlur(blendmode, blur, canvas, canvas2, l, t, w, h, s)
|
|
|
|
if blur <= 0 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
canvas2:clear()
|
|
|
|
self.blurv:send("steps", blur)
|
|
|
|
self.blurh:send("steps", blur)
|
|
|
|
util.drawCanvasToCanvas(canvas, canvas2, {shader = self.blurv, blendmode = blendmode})
|
|
|
|
util.drawCanvasToCanvas(canvas2, canvas, {shader = self.blurh, blendmode = blendmode})
|
2014-09-30 22:19:37 +00:00
|
|
|
end
|
|
|
|
|
2014-11-28 15:55:43 +00:00
|
|
|
-- draw normal shading
|
|
|
|
function light_world:drawNormalShading(l,t,w,h,s)
|
2014-10-03 00:32:31 +00:00
|
|
|
if not self.isShadows then
|
2014-09-27 16:59:51 +00:00
|
|
|
return
|
|
|
|
end
|
2014-10-22 12:37:19 +00:00
|
|
|
-- create normal map
|
|
|
|
self.normalMap:clear()
|
|
|
|
util.drawto(self.normalMap, l, t, s, function()
|
|
|
|
for i = 1, #self.body do
|
2014-11-30 00:10:15 +00:00
|
|
|
self.body[i]:drawNormal()
|
2014-10-22 12:37:19 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2014-11-28 15:55:43 +00:00
|
|
|
self.normal2:clear()
|
2014-10-22 12:37:19 +00:00
|
|
|
for i = 1, #self.lights do
|
2014-11-30 00:10:15 +00:00
|
|
|
self.shadowMap:clear()
|
|
|
|
util.drawto(self.shadowMap, l, t, s, function()
|
|
|
|
for k = 1, #self.body do
|
|
|
|
self.body[k]:drawCalculatedShadow(self.lights[i])
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
self.lights[i]:drawNormalShading(l,t,w,h,s, self.normalMap, self.shadowMap, self.normal2)
|
2014-10-22 12:37:19 +00:00
|
|
|
end
|
|
|
|
|
2014-11-28 15:55:43 +00:00
|
|
|
self.normal:clear(255, 255, 255)
|
|
|
|
util.drawCanvasToCanvas(self.normal2, self.normal, {blendmode = "alpha"})
|
|
|
|
util.drawto(self.normal, l, t, s, function()
|
2014-10-22 12:37:19 +00:00
|
|
|
love.graphics.setBlendMode("additive")
|
|
|
|
love.graphics.setColor({self.ambient[1], self.ambient[2], self.ambient[3]})
|
2014-11-07 01:03:00 +00:00
|
|
|
love.graphics.rectangle("fill", -l/s, -t/s, w/s,h/s)
|
2014-10-22 12:37:19 +00:00
|
|
|
end)
|
|
|
|
|
2014-11-28 15:55:43 +00:00
|
|
|
util.drawCanvasToCanvas(self.normal, self.render_buffer, {blendmode = "multiplicative"})
|
2014-09-27 16:59:51 +00:00
|
|
|
end
|
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- draw material
|
2014-10-03 00:32:31 +00:00
|
|
|
function light_world:drawMaterial(l,t,w,h,s)
|
2014-09-26 17:38:55 +00:00
|
|
|
for i = 1, #self.body do
|
2014-10-24 01:35:35 +00:00
|
|
|
self.body[i]:drawMaterial()
|
2014-09-26 17:38:55 +00:00
|
|
|
end
|
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- draw glow
|
2014-10-03 00:32:31 +00:00
|
|
|
function light_world:drawGlow(l,t,w,h,s)
|
|
|
|
if not self.isShadows then
|
2014-09-27 16:59:51 +00:00
|
|
|
return
|
|
|
|
end
|
2014-10-22 12:37:19 +00:00
|
|
|
|
|
|
|
-- create glow map
|
|
|
|
self.glowMap:clear(0, 0, 0)
|
|
|
|
util.drawto(self.glowMap, l, t, s, function()
|
|
|
|
if self.glowDown then
|
|
|
|
self.glowTimer = math.max(0.0, self.glowTimer - love.timer.getDelta())
|
|
|
|
if self.glowTimer == 0.0 then
|
|
|
|
self.glowDown = not self.glowDown
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.glowTimer = math.min(self.glowTimer + love.timer.getDelta(), 1.0)
|
|
|
|
if self.glowTimer == 1.0 then
|
|
|
|
self.glowDown = not self.glowDown
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, #self.body do
|
2014-10-24 01:35:35 +00:00
|
|
|
self.body[i]:drawGlow()
|
2014-10-22 12:37:19 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
light_world:drawBlur("alpha", self.glowBlur, self.glowMap, self.glowMap2, l, t, w, h, s)
|
|
|
|
util.drawCanvasToCanvas(self.glowMap, self.render_buffer, {blendmode = "additive"})
|
2014-09-26 17:38:55 +00:00
|
|
|
end
|
|
|
|
-- draw refraction
|
2014-10-03 00:32:31 +00:00
|
|
|
function light_world:drawRefraction(l,t,w,h,s)
|
2014-09-29 14:03:15 +00:00
|
|
|
if not self.isRefraction then
|
2014-09-27 16:59:51 +00:00
|
|
|
return
|
|
|
|
end
|
2014-10-22 12:37:19 +00:00
|
|
|
|
|
|
|
-- create refraction map
|
|
|
|
self.refractionMap:clear()
|
|
|
|
util.drawto(self.refractionMap, l, t, s, function()
|
|
|
|
for i = 1, #self.body do
|
2014-10-24 01:35:35 +00:00
|
|
|
self.body[i]:drawRefraction()
|
2014-10-22 12:37:19 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
util.drawCanvasToCanvas(self.render_buffer, self.refractionMap2)
|
2014-10-01 13:03:59 +00:00
|
|
|
self.refractionShader:send("backBuffer", self.refractionMap2)
|
|
|
|
self.refractionShader:send("refractionStrength", self.refractionStrength)
|
2014-10-22 12:37:19 +00:00
|
|
|
util.drawCanvasToCanvas(self.refractionMap, self.render_buffer, {shader = self.refractionShader})
|
2014-09-26 17:38:55 +00:00
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- draw reflection
|
2014-10-03 00:32:31 +00:00
|
|
|
function light_world:drawReflection(l,t,w,h,s)
|
2014-09-29 14:03:15 +00:00
|
|
|
if not self.isReflection then
|
2014-09-27 16:59:51 +00:00
|
|
|
return
|
|
|
|
end
|
2014-10-22 12:37:19 +00:00
|
|
|
|
|
|
|
-- create reflection map
|
|
|
|
self.reflectionMap:clear(0, 0, 0)
|
|
|
|
util.drawto(self.reflectionMap, l, t, s, function()
|
|
|
|
for i = 1, #self.body do
|
2014-10-24 01:35:35 +00:00
|
|
|
self.body[i]:drawReflection()
|
2014-10-22 12:37:19 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
util.drawCanvasToCanvas(self.render_buffer, self.reflectionMap2)
|
2014-10-01 13:03:59 +00:00
|
|
|
self.reflectionShader:send("backBuffer", self.reflectionMap2)
|
|
|
|
self.reflectionShader:send("reflectionStrength", self.reflectionStrength)
|
|
|
|
self.reflectionShader:send("reflectionVisibility", self.reflectionVisibility)
|
2014-10-22 12:37:19 +00:00
|
|
|
util.drawCanvasToCanvas(self.reflectionMap, self.render_buffer, {shader = self.reflectionShader})
|
2014-09-26 17:38:55 +00:00
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new light
|
|
|
|
function light_world:newLight(x, y, red, green, blue, range)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.lights[#self.lights + 1] = Light(x, y, red, green, blue, range)
|
2014-09-26 17:38:55 +00:00
|
|
|
self.isLight = true
|
|
|
|
return self.lights[#self.lights]
|
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-10-27 13:20:01 +00:00
|
|
|
function light_world:clear()
|
|
|
|
light_world:clearLights()
|
2014-10-28 01:32:51 +00:00
|
|
|
light_world:clearBodies()
|
2014-10-27 13:20:01 +00:00
|
|
|
end
|
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- clear lights
|
|
|
|
function light_world:clearLights()
|
|
|
|
self.lights = {}
|
|
|
|
self.isLight = false
|
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- clear objects
|
2014-10-28 01:32:51 +00:00
|
|
|
function light_world:clearBodies()
|
2014-09-26 17:38:55 +00:00
|
|
|
self.body = {}
|
|
|
|
self.isShadows = false
|
|
|
|
self.isRefraction = false
|
|
|
|
self.isReflection = false
|
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-10-03 00:32:31 +00:00
|
|
|
function light_world:setBackgroundMethod(fn)
|
|
|
|
self.drawBackground = fn or function() end
|
|
|
|
end
|
|
|
|
|
|
|
|
function light_world:setForegroundMethod(fn)
|
2014-10-28 01:32:51 +00:00
|
|
|
self.drawForeground = fn or function() end
|
2014-10-03 00:32:31 +00:00
|
|
|
end
|
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- set ambient color
|
|
|
|
function light_world:setAmbientColor(red, green, blue)
|
|
|
|
self.ambient = {red, green, blue}
|
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- set blur
|
|
|
|
function light_world:setBlur(blur)
|
|
|
|
self.blur = blur
|
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- set blur
|
|
|
|
function light_world:setShadowBlur(blur)
|
|
|
|
self.blur = blur
|
|
|
|
end
|
2014-09-27 16:59:51 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- set glow blur
|
|
|
|
function light_world:setGlowStrength(strength)
|
|
|
|
self.glowBlur = strength
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- set refraction blur
|
|
|
|
function light_world:setRefractionStrength(strength)
|
|
|
|
self.refractionStrength = strength
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- set reflection strength
|
|
|
|
function light_world:setReflectionStrength(strength)
|
|
|
|
self.reflectionStrength = strength
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- set reflection visibility
|
|
|
|
function light_world:setReflectionVisibility(visibility)
|
|
|
|
self.reflectionVisibility = visibility
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new rectangle
|
|
|
|
function light_world:newRectangle(x, y, w, h)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.isShadows = true
|
2014-10-28 01:41:25 +00:00
|
|
|
return self:newBody("rectangle", x, y, w, h)
|
2014-09-26 17:38:55 +00:00
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new circle
|
|
|
|
function light_world:newCircle(x, y, r)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.isShadows = true
|
|
|
|
return self:newBody("circle", x, y, r)
|
2014-09-26 17:38:55 +00:00
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new polygon
|
|
|
|
function light_world:newPolygon(...)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.isShadows = true
|
2014-09-26 17:38:55 +00:00
|
|
|
return self:newBody("polygon", ...)
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new image
|
|
|
|
function light_world:newImage(img, x, y, width, height, ox, oy)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.isShadows = true
|
2014-09-26 17:38:55 +00:00
|
|
|
return self:newBody("image", img, x, y, width, height, ox, oy)
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new refraction
|
|
|
|
function light_world:newRefraction(normal, x, y, width, height)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.isRefraction = true
|
2014-09-26 17:38:55 +00:00
|
|
|
return self:newBody("refraction", normal, x, y, width, height)
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new refraction from height map
|
|
|
|
function light_world:newRefractionHeightMap(heightMap, x, y, strength)
|
2014-10-03 14:43:26 +00:00
|
|
|
local normal = normal_map.fromHeightMap(heightMap, strength)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.isRefraction = true
|
2014-09-26 17:38:55 +00:00
|
|
|
return self.newRefraction(p, normal, x, y)
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new reflection
|
|
|
|
function light_world:newReflection(normal, x, y, width, height)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.isReflection = true
|
2014-09-26 17:38:55 +00:00
|
|
|
return self:newBody("reflection", normal, x, y, width, height)
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new reflection from height map
|
|
|
|
function light_world:newReflectionHeightMap(heightMap, x, y, strength)
|
2014-10-03 14:43:26 +00:00
|
|
|
local normal = normal_map.fromHeightMap(heightMap, strength)
|
2014-10-03 00:32:31 +00:00
|
|
|
self.isReflection = true
|
2014-09-26 17:38:55 +00:00
|
|
|
return self.newReflection(p, normal, x, y)
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- new body
|
|
|
|
function light_world:newBody(type, ...)
|
|
|
|
local id = #self.body + 1
|
2014-10-03 00:32:31 +00:00
|
|
|
self.body[id] = Body(id, type, ...)
|
2014-09-26 17:38:55 +00:00
|
|
|
return self.body[#self.body]
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
|
|
|
-- get body count
|
2014-09-26 17:38:55 +00:00
|
|
|
function light_world:getBodyCount()
|
|
|
|
return #self.body
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
|
|
|
-- get light
|
|
|
|
function light_world:getBody(n)
|
|
|
|
return self.body[n]
|
2014-09-26 17:38:55 +00:00
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
-- get light count
|
|
|
|
function light_world:getLightCount()
|
|
|
|
return #self.lights
|
|
|
|
end
|
2014-09-27 17:46:46 +00:00
|
|
|
|
|
|
|
-- get light
|
|
|
|
function light_world:getLight(n)
|
|
|
|
return self.lights[n]
|
2014-09-26 16:48:46 +00:00
|
|
|
end
|
2014-09-26 17:38:55 +00:00
|
|
|
|
2014-11-03 22:54:15 +00:00
|
|
|
function light_world:remove(to_kill)
|
|
|
|
if to_kill:is_a(Body) then
|
|
|
|
for i = 1, #self.body do
|
|
|
|
if self.body[i] == to_kill then
|
|
|
|
table.remove(self.body, i)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif to_kill:is_a(Light) then
|
|
|
|
for i = 1, #self.lights do
|
|
|
|
if self.lights[i] == to_kill then
|
|
|
|
table.remove(self.lights, i)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- failed to find it
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2014-09-26 17:38:55 +00:00
|
|
|
return light_world
|