73 lines
2 KiB
Lua
73 lines
2 KiB
Lua
require 'grid'
|
|
require 'point'
|
|
require 'line'
|
|
require 'mouse'
|
|
require 'levelhandler'
|
|
require 'button'
|
|
Input = require 'input'
|
|
|
|
InMenu = true
|
|
|
|
local function updateCellSize()
|
|
local width, height = love.graphics.getDimensions()
|
|
local gridX, gridY = GameGrid.size:coords();
|
|
local isWidthBased = (width / height) / (gridX / gridY)
|
|
Config.cellSize = math.floor(isWidthBased and height / gridY or width / gridX)
|
|
love.graphics.setLineWidth( Config.cellSize * Config.lineWidth )
|
|
end
|
|
|
|
function love.load()
|
|
love.window.setMode( 800, 480 )
|
|
|
|
local menuButtonReleased = function()
|
|
InMenu = false
|
|
GameGrid = LevelHandler:first()
|
|
updateCellSize()
|
|
end
|
|
|
|
MenuStartButton = Button:new( Point:new( 240, 120 ), Point:new( 320, 80 ), nil, nil, menuButtonReleased )
|
|
|
|
|
|
love.graphics.setLineStyle( Config.lineStyle )
|
|
end
|
|
|
|
function love.update( dt )
|
|
Mouse:update()
|
|
Input:update()
|
|
if InMenu then
|
|
MenuStartButton:update( dt, Point:new( Mouse.x, Mouse.y ), Mouse.pressed )
|
|
else
|
|
if Input:actionReleased( 'exit' ) then
|
|
love.event.quit()
|
|
end
|
|
|
|
if Input:actionReleased( 'nextlevel' ) then
|
|
if GameGrid:isCompleted() then
|
|
GameGrid = LevelHandler:next()
|
|
updateCellSize()
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function love.draw()
|
|
if InMenu then
|
|
MenuStartButton:draw()
|
|
else
|
|
GameGrid:draw()
|
|
|
|
local text = string.format( "%d:%d global\n%d:%d local\n%d:%d from start", Mouse.x, Mouse.y, Mouse.point.x, Mouse.point.y, Mouse.startX - Mouse.x, Mouse.startY - Mouse.y )
|
|
love.graphics.print( text, 64, 256 )
|
|
|
|
if Mouse.dragged then
|
|
love.graphics.print( "drag", 64, 300 )
|
|
end
|
|
if Mouse.lastLine ~= nil then
|
|
love.graphics.print( tostring( Mouse.lastLine ), 128, 300 )
|
|
end
|
|
|
|
if GameGrid:isCompleted() then
|
|
love.graphics.print( "Grid completed. Press space to proceed to next", 64, 320 )
|
|
end
|
|
end
|
|
end
|