Add more methods.

This commit is contained in:
Marcus Ihde 2014-03-06 21:39:29 +01:00
parent 6a20a6f72f
commit efb7ab918b

132
light.lua
View File

@ -370,6 +370,10 @@ function love.light.newWorld()
o.getLightY = function(n) o.getLightY = function(n)
return o.lights[n].y return o.lights[n].y
end end
-- get type
o.getType = function()
return "world"
end
return o return o
end end
@ -399,6 +403,14 @@ function love.light.newLight(p, x, y, red, green, blue, range)
o.changed = true o.changed = true
end end
end end
-- get x
o.getX = function()
return o.x
end
-- get y
o.getY = function()
return o.y
end
-- set x -- set x
o.setX = function(x) o.setX = function(x)
if x ~= o.x then if x ~= o.x then
@ -451,38 +463,38 @@ function love.light.newLight(p, x, y, red, green, blue, range)
end end
-- rectangle object -- rectangle object
function love.light.newRectangle(p, x, y, w, h) function love.light.newRectangle(p, x, y, width, height)
local o = {} local o = {}
p.poly[#p.poly + 1] = o p.poly[#p.poly + 1] = o
o.id = #p.poly o.id = #p.poly
o.x = x o.x = x or 0
o.y = y o.y = y or 0
o.w = w o.width = width or 64
o.h = h o.height = height or 64
o.ox = w / 2 o.ox = o.width / 2
o.oy = h / 2 o.oy = o.height / 2
o.shine = true o.shine = true
p.changed = true p.changed = true
o.data = { o.data = {
o.x - o.ox, o.x - o.ox,
o.y - o.oy, o.y - o.oy,
o.x - o.ox + o.w, o.x - o.ox + o.width,
o.y - o.oy, o.y - o.oy,
o.x - o.ox + o.w, o.x - o.ox + o.width,
o.y - o.oy + o.h, o.y - o.oy + o.height,
o.x - o.ox, o.x - o.ox,
o.y - o.oy + o.h o.y - o.oy + o.height
} }
-- refresh -- refresh
o.refresh = function() o.refresh = function()
o.data[1] = o.x - o.ox o.data[1] = o.x - o.ox
o.data[2] = o.y - o.oy o.data[2] = o.y - o.oy
o.data[3] = o.x - o.ox + o.w o.data[3] = o.x - o.ox + o.width
o.data[4] = o.y - o.oy o.data[4] = o.y - o.oy
o.data[5] = o.x - o.ox + o.w o.data[5] = o.x - o.ox + o.width
o.data[6] = o.y - o.oy + o.h o.data[6] = o.y - o.oy + o.height
o.data[7] = o.x - o.ox o.data[7] = o.x - o.ox
o.data[8] = o.y - o.oy + o.h o.data[8] = o.y - o.oy + o.height
end end
-- set position -- set position
o.setPosition = function(x, y) o.setPosition = function(x, y)
@ -493,10 +505,26 @@ function love.light.newRectangle(p, x, y, w, h)
p.changed = true p.changed = true
end end
end end
-- set x
o.setX = function(x)
if x ~= o.x then
o.x = x
o.refresh()
p.changed = true
end
end
-- set y
o.setY = function(y)
if y ~= o.y then
o.y = y
o.refresh()
p.changed = true
end
end
-- set dimension -- set dimension
o.setDimension = function(w, h) o.setDimension = function(width, height)
o.w = w o.width = width
o.h = h o.height = height
o.refresh() o.refresh()
p.changed = true p.changed = true
end end
@ -518,6 +546,18 @@ function love.light.newRectangle(p, x, y, w, h)
o.getY = function() o.getY = function()
return o.y return o.y
end end
-- get width
o.getWidth = function()
return o.width
end
-- get height
o.getHeight = function()
return o.height
end
-- get rectangle data
o.getPoints = function()
return unpack(o.data)
end
-- get type -- get type
o.getType = function() o.getType = function()
return "rectangle" return "rectangle"
@ -531,9 +571,9 @@ function love.light.newCircle(p, x, y, radius)
local o = {} local o = {}
p.circle[#p.circle + 1] = o p.circle[#p.circle + 1] = o
o.id = #p.circle o.id = #p.circle
o.x = x o.x = x or 0
o.y = y o.y = y or 0
o.radius = radius o.radius = radius or 200
o.shine = true o.shine = true
p.changed = true p.changed = true
-- set position -- set position
@ -544,6 +584,20 @@ function love.light.newCircle(p, x, y, radius)
p.changed = true p.changed = true
end end
end end
-- set x
o.setX = function(x)
if x ~= o.x then
o.x = x
p.changed = true
end
end
-- set y
o.setY = function(y)
if y ~= o.y then
o.y = y
p.changed = true
end
end
-- set radius -- set radius
o.setRadius = function(radius) o.setRadius = function(radius)
if radius ~= o.radius then if radius ~= o.radius then
@ -629,8 +683,8 @@ function love.light.newImage(p, img, x, y, width, height, ox, oy)
o.img = img o.img = img
o.normal = nil o.normal = nil
o.glow = nil o.glow = nil
o.x = x o.x = x or 0
o.y = y o.y = y or 0
o.width = width or img:getWidth() o.width = width or img:getWidth()
o.height = height or img:getHeight() o.height = height or img:getHeight()
o.ox = o.width / 2.0 o.ox = o.width / 2.0
@ -671,6 +725,38 @@ function love.light.newImage(p, img, x, y, width, height, ox, oy)
p.changed = true p.changed = true
end end
end end
-- set x position
o.setX = function(x)
if x ~= o.x then
o.x = x
o.refresh()
p.changed = true
end
end
-- set y position
o.setY = function(y)
if y ~= o.y then
o.y = y
o.refresh()
p.changed = true
end
end
-- get width
o.getWidth = function()
return o.width
end
-- get height
o.getHeight = function()
return o.height
end
-- get image width
o.getImageWidth = function()
return o.imgWidth
end
-- get image height
o.getImageHeight = function()
return o.imgHeight
end
-- set dimension -- set dimension
o.setDimension = function(width, height) o.setDimension = function(width, height)
o.width = width o.width = width