require 'point' require 'gridpoint' require 'mouse' require 'mechanism' require 'port' require 'tablefuncs' function love.load() Screenw, Screenh = love.window.getMode() Gridw, Gridh = Screenw / Config.cellSize, Screenh / Config.cellSize local port1 = Port:new( GridPoint:new(-1, 0), PortRotation.left, { 0.8, 0.8, 0, 1 } ) local port2 = Port:new( GridPoint:new(0, -1), PortRotation.up, { 0.8, 0, 0.8, 1 } ) local port3 = Port:new( GridPoint:new(3, 2), PortRotation.right, { 0.8, 0, 0, 1 } ) local port4 = Port:new( GridPoint:new(2, 3), PortRotation.down, { 0, 0, 0.8, 1 } ) local mecha1 = Mechanism:new( GridPoint:new(5, 5), GridPoint:new(3, 3), { port1, port2, port3, port4 }, {0.5, 0.5, 0.5, 1} ) local port5 = Port:new( GridPoint:new(-1, 0), PortRotation.left, { 0.8, 0.8, 0, 1 } ) local port6 = Port:new( GridPoint:new(0, -1), PortRotation.up, { 0.8, 0, 0.8, 1 } ) local port7 = Port:new( GridPoint:new(2, 1), PortRotation.right, { 0.8, 0, 0, 1 } ) local port8 = Port:new( GridPoint:new(1, 2), PortRotation.down, { 0, 0, 0.8, 1 } ) local mecha2 = Mechanism:new( GridPoint:new(10, 5), GridPoint:new(2, 2), { port5, port6, port7, port8 }, {0.5, 1, 0.5, 1} ) local port9 = Port:new( GridPoint:new(-1, 0), PortRotation.left, { 0.8, 0.8, 0, 1 } ) local port10 = Port:new( GridPoint:new(0, -1), PortRotation.up, { 0.8, 0, 0.8, 1 } ) local port11 = Port:new( GridPoint:new(2, 0), PortRotation.right, { 0.8, 0, 0, 1 } ) local port12 = Port:new( GridPoint:new(1, 1), PortRotation.down, { 0, 0, 0.8, 1 } ) local mecha3 = Mechanism:new( GridPoint:new(13, 5), GridPoint:new(2, 1), { port9, port10, port11, port12 }, {1, 0.5, 0.5, 1} ) local port13 = Port:new( GridPoint:new(-1, 0), PortRotation.left, { 0.8, 0.8, 0, 1 } ) local port14 = Port:new( GridPoint:new(0, -1), PortRotation.up, { 0.8, 0, 0.8, 1 } ) local port15 = Port:new( GridPoint:new(2, 0), PortRotation.right, { 0.8, 0, 0, 1 } ) local port16 = Port:new( GridPoint:new(1, 1), PortRotation.down, { 0, 0, 0.8, 1 } ) local mecha4 = Mechanism:new( GridPoint:new(16, 5), GridPoint:new(2, 1), { port13, port14, port15, port16 }, {0.5, 0.5, 1, 1} ) Mechs = {mecha1, mecha2, mecha3, mecha4} end function love.update( dt ) dt = dt Mouse:update() if Mouse.lastPressed and not Mouse.pressed then local index = TableFind(Mechs, Mouse.point, function(mp, mech) return mp.x >= mech.position.x and mp.x < mech.position.x + mech.size.x and mp.y >= mech.position.y and mp.y < mech.position.y + mech.size.y end ) if index ~= nil then Mechs[index]:rotateClockwise() end end end function love.draw() love.graphics.setColor(1, 1, 1, 1) for i = 1, Gridw do love.graphics.line( i * Config.cellSize, 0, i * Config.cellSize, Screenh ) end for j = 1, Gridh do love.graphics.line( 0, j * Config.cellSize, Screenw, j * Config.cellSize ) end local mx, my = Mouse.point:globalCoords() local mh, mw = Config.cellSize, Config.cellSize love.graphics.rectangle("fill", mx, my, mh, mw) love.graphics.print(string.format("%s, %s", Mouse.point.x, Mouse.point.y), 100, 100) for _, mech in ipairs(Mechs) do mech:draw() end end