summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua33
1 files changed, 29 insertions, 4 deletions
diff --git a/main.lua b/main.lua
index 5a4e2f0..9a18611 100644
--- a/main.lua
+++ b/main.lua
@@ -12,6 +12,7 @@ local offsetX, offsetY = 0, 0
local dpiScale = 1
local canvas = nil
local smoothCameraShader = nil
+local shaderEnabled = true
local cameraModule = require("camera")
local camera = nil
@@ -19,7 +20,10 @@ local fonts = require("fonts")
local currentState = "game"
local currentMapPath = "assets/maps/tilemap.lua"
-local currentTilesetPath = "assets/maps/tileset.png"
+local currentTilesets = {
+ tileset = { path = "assets/maps/tileset.png", tilewidth = 16, tileheight = 16 },
+ ground = { path = "assets/maps/ground.png", tilewidth = 8, tileheight = 8 },
+}
local world = nil
local states = {
@@ -39,7 +43,7 @@ end
function states.game.load()
local World = require("world")
world = World:new()
- world:load(currentMapPath, currentTilesetPath)
+ world:load(currentMapPath, currentTilesets)
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)
@@ -116,6 +120,9 @@ function love.keypressed(key, scancode, isrepeat)
if key == "f11" then
love.window.setFullscreen(not love.window.getFullscreen(), "desktop")
end
+ if key == "f1" and DEBUG then
+ shaderEnabled = not shaderEnabled
+ 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
@@ -143,16 +150,34 @@ function love.draw()
local uvOffsetX = subDx * WORLD_TO_CANVAS / CANVAS_WIDTH
local uvOffsetY = subDy * WORLD_TO_CANVAS / CANVAS_HEIGHT
- if smoothCameraShader and (subDx ~= 0 or subDy ~= 0) then
+ if shaderEnabled and smoothCameraShader and (subDx ~= 0 or subDy ~= 0) then
smoothCameraShader:send("offset", { uvOffsetX, uvOffsetY })
love.graphics.setShader(smoothCameraShader)
end
love.graphics.draw(canvas, math.floor(drawX), math.floor(drawY), 0, finalScale, finalScale)
- if smoothCameraShader then
+ if shaderEnabled and smoothCameraShader then
love.graphics.setShader()
end
+
+ if DEBUG then
+ local fps = love.timer.getFPS()
+ local shaderLoaded = smoothCameraShader ~= nil
+ local shaderApplied = shaderEnabled and shaderLoaded and (subDx ~= 0 or subDy ~= 0)
+ local shaderName = shaderLoaded and "smooth_camera.glsl" or "none (fallback)"
+ local shaderState = not shaderLoaded and "unavailable"
+ or not shaderEnabled and "disabled [F1]"
+ or shaderApplied and "active"
+ or "idle"
+ local shaderLine = "shader: " .. shaderName .. " (" .. shaderState .. ")"
+ love.graphics.setColor(0, 0, 0, 0.5)
+ love.graphics.rectangle("fill", 4, 4, 280, 36)
+ love.graphics.setColor(1, 1, 0, 1)
+ love.graphics.print("FPS: " .. fps, 8, 8)
+ love.graphics.print(shaderLine, 8, 22)
+ love.graphics.setColor(1, 1, 1, 1)
+ end
end
return nil