demo completed
This commit is contained in:
parent
2eb4f33864
commit
d50e5c0c35
4 changed files with 193 additions and 31 deletions
71
main.lua
71
main.lua
|
|
@ -4,48 +4,53 @@ require 'mouse'
|
|||
require 'mechanism'
|
||||
require 'port'
|
||||
require 'tablefuncs'
|
||||
Input = require 'input'
|
||||
require 'selector'
|
||||
|
||||
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} )
|
||||
Mechs = {}
|
||||
|
||||
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}
|
||||
Selected = nil
|
||||
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
|
||||
Mouse:update()
|
||||
Input:update()
|
||||
selectorUpdate()
|
||||
|
||||
Selected = getSelected()
|
||||
|
||||
if Selected ~= nil then
|
||||
Selected.position = Mouse.point
|
||||
if Mouse.lastPressed and not Mouse.pressed then
|
||||
local intersects = TableHas( Mechs, Selected, function(this, other)
|
||||
return this:intersectsOther( other )
|
||||
end
|
||||
)
|
||||
if not intersects then
|
||||
local mech = Selected:clone()
|
||||
mech.position = GridPoint:new( Mouse.point.x, Mouse.point.y )
|
||||
mech.xcorner = GridPoint:new( Selected.xcorner.x, Selected.xcorner.y )
|
||||
table.insert( Mechs, mech )
|
||||
end
|
||||
end
|
||||
)
|
||||
if index ~= nil then
|
||||
Mechs[index]:rotateClockwise()
|
||||
end
|
||||
|
||||
if Input:actionReleased( 'rotate' ) then
|
||||
if Selected ~= nil then
|
||||
Selected:rotateClockwise()
|
||||
else
|
||||
local index = TableFind(Mechs, Mouse.point, function(mp, mech)
|
||||
return mech:intersectsPoint( mp )
|
||||
end
|
||||
)
|
||||
if index ~= nil then
|
||||
Mechs[index]:rotateClockwise()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -67,4 +72,8 @@ function love.draw()
|
|||
for _, mech in ipairs(Mechs) do
|
||||
mech:draw()
|
||||
end
|
||||
|
||||
if Selected ~= nil then
|
||||
Selected:draw()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue