diff options
Diffstat (limited to 'main.lua')
| -rw-r--r-- | main.lua | 51 |
1 files changed, 47 insertions, 4 deletions
@@ -1,7 +1,7 @@ local VIRTUAL_WIDTH, VIRTUAL_HEIGHT = 16*10*5, 9*10*5 local CANVAS_PADDING = 6 -DEBUG = true +DEBUG = false local CANVAS_WIDTH = VIRTUAL_WIDTH + CANVAS_PADDING local CANVAS_HEIGHT = VIRTUAL_HEIGHT + CANVAS_PADDING @@ -18,6 +18,9 @@ local shaderEnabled = true local cameraModule = require("camera") local camera = nil local fonts = require("fonts") +local HUD = require("hud") +local hud = nil +local previousState = nil local currentState = "game" local currentMapPath = "assets/maps/tilemap.lua" @@ -30,7 +33,8 @@ local world = nil local states = { game = {}, menu = {}, - settings = {} + settings = {}, + hud = {}, } local function recalcScale(w, h) @@ -48,6 +52,7 @@ function states.game.load() local target = world:getPlayer() or { x = 0, y = 0, width = 16, height = 16 } camera = cameraModule:new(target, VIRTUAL_WIDTH/2, VIRTUAL_HEIGHT/2, true, WORLD_TO_CANVAS) world:setCamera(camera) + hud = HUD:new() end function states.game.update(dt) @@ -82,6 +87,19 @@ function states.settings.draw() love.graphics.print("Settings", 10, 10) end +function states.hud.update(dt) + if hud then + local w, h = love.graphics.getWidth(), love.graphics.getHeight() + hud:update(dt, w, h, finalScale) + end +end + +function states.hud.draw() + if camera then camera:set() end + if world then world:draw() end + if camera then camera:unset() end +end + function love.load() love.graphics.setDefaultFilter("nearest", "nearest") love.window.setTitle("Openformer") @@ -100,6 +118,8 @@ function love.load() local w, h = love.graphics.getWidth(), love.graphics.getHeight() recalcScale(w, h) + love.mouse.setVisible(false) + local state = states[currentState] if state and state.load then state.load() end end @@ -123,9 +143,28 @@ function love.keypressed(key, scancode, isrepeat) if key == "f1" and DEBUG then shaderEnabled = not shaderEnabled end + if key == "tab" and not isrepeat then + if currentState == "game" then + previousState = currentState + currentState = "hud" + love.mouse.setVisible(true) + elseif currentState == "hud" then + currentState = previousState or "game" + previousState = nil + love.mouse.setVisible(false) + end + end if (key == "space" or key == "up" or key == "w") and not isrepeat then - local player = world and world:getPlayer() - if player then player:jump() end + if currentState == "game" then + local player = world and world:getPlayer() + if player then player:jump() end + end + end +end + +function love.mousepressed(x, y, button) + if currentState == "hud" and hud then + hud:mousepressed(x, y, button) end end @@ -162,6 +201,10 @@ function love.draw() love.graphics.setShader() end + if currentState == "hud" and hud then + hud:draw() + end + if DEBUG then local fps = love.timer.getFPS() local shaderLoaded = smoothCameraShader ~= nil |
