Initial commit
This commit is contained in:
commit
f765ec74ef
6 changed files with 181 additions and 0 deletions
50
line.lua
Normal file
50
line.lua
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
require "gridpoint"
|
||||
|
||||
-- Line table, interactive game object
|
||||
-- NOTE: uses GridPoint
|
||||
Line = {}
|
||||
|
||||
-- Factory function
|
||||
function Line:new( startpoint, endpoint, color )
|
||||
local line = {
|
||||
startpoint = startpoint,
|
||||
endpoint = endpoint,
|
||||
points = {
|
||||
startpoint
|
||||
},
|
||||
color = color
|
||||
}
|
||||
|
||||
setmetatable( line, { __index = self } )
|
||||
|
||||
return line
|
||||
end
|
||||
|
||||
-- Push point to the end of points stack
|
||||
function Line:push( point )
|
||||
table.insert( self.points, point )
|
||||
end
|
||||
|
||||
-- Pop point from points stack
|
||||
function Line:pop()
|
||||
return table.remove( self.points )
|
||||
end
|
||||
|
||||
-- Draw line with connected dots
|
||||
function Line:draw()
|
||||
love.graphics.setColor( self.color )
|
||||
-- Draw start and end points (should look like rings)
|
||||
local sx, sy = self.startpoint:globalCoords()
|
||||
love.graphics.circle( "fill", sx, sy, Config.linePointRadius )
|
||||
local ex, ey = self.endpoint:globalCoords()
|
||||
love.graphics.circle( "fill", ex, ey, Config.linePointRadius )
|
||||
-- Draw line
|
||||
local points = {}
|
||||
for _, point in ipairs( self.points ) do
|
||||
local x, y = point:globalCoords()
|
||||
table.insert( points, x )
|
||||
table.insert( points, y )
|
||||
end
|
||||
love.graphics.line( points )
|
||||
love.graphics.setColor( Color.white )
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue