commit 41f6c65a462d09b9e5d70ef8fa7deaa876f195a7 Author: Patrick Schwarzer Date: Fri Apr 11 18:13:24 2025 +0200 Initial Commit diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f309009 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/main.lua", + "type": "node-terminal", + "command": "./love-11.5-x86_64.AppImage . && exit" + } + ] +} \ No newline at end of file diff --git a/font.png b/font.png new file mode 100644 index 0000000..2ce8e88 Binary files /dev/null and b/font.png differ diff --git a/games/test.lua b/games/test.lua new file mode 100644 index 0000000..98eb91a --- /dev/null +++ b/games/test.lua @@ -0,0 +1,14 @@ + +local test = 1 +local delay = 0 + +function Update(dt, curTime) + if (curTime > delay) then + delay = curTime + 1 + test = test + 1 + end +end + +function Draw() + print("Counter: " .. test, 10, 10) +end diff --git a/love-11.5-x86_64.AppImage b/love-11.5-x86_64.AppImage new file mode 100755 index 0000000..69d212f Binary files /dev/null and b/love-11.5-x86_64.AppImage differ diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..43d5cc1 --- /dev/null +++ b/main.lua @@ -0,0 +1,112 @@ + +local curTime = 0 +function CurTime() + return curTime +end + + + +local consoleEnv = { + Load = function() end, + Update = function(dt) end, + Draw = function() end, + KeyPressed = love.keypressed, + KeyDown = love.keyboard.wasPressed, + print = love.graphics.print, +} +consoleEnv._G = consoleEnv +setmetatable(consoleEnv, { + __index = function(_, key) + return function(...) end + end +}) + +function loadGame(gameName) + local fn, err = loadfile("games/" .. gameName .. ".lua", "t", consoleEnv) + if not fn then + error("Failed to load sandbox file (1): " .. err) + end + + local ok, execErr = pcall(fn) + if not ok then + error("Error running sandbox file (2): " .. execErr) + end +end + + + +local maxScaling = 4 +function love.load() + love.window.setTitle("Fantasy Console") + love.graphics.setDefaultFilter("nearest", "nearest") + + font = love.graphics.newImageFont("font.png", " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.:;<=>?-+*/)('&%$#ß!@[ß]^_{|}~", -1) + --font = love.graphics.newFont("monogram.ttf", 16) + --font:setFilter("nearest", "nearest") + + scaling = 4 + love.window.updateWindow() + + love.keyboard.keysPressed = {} + + + loadGame("test") + + + -- Track memory usage using this + info = love.filesystem.getInfo( "font.png" ) + + print(info.size) +end + +function love.keypressed(key) + if key == "escape" then + love.event.quit() + end + + love.keyboard.keysPressed[key] = true + + if (consoleEnv.WasKeyPressed) then + consoleEnv.WasKeyPressed(key) + end +end + +function love.keyboard.wasPressed(key) + return love.keyboard.keysPressed[key] +end + +function love.window.updateWindow() + love.window.setMode(scaling*240, scaling*160, {resizable=false, vsync=0}) +end + +function love.update(dt) + curTime = curTime + dt + + if (love.keyboard.wasPressed("f1")) then + scaling = scaling + 1 + + if (scaling == maxScaling+1) then + scaling = 1 + end + + love.window.updateWindow() + end + + love.keyboard.keysPressed = {} + + if (consoleEnv.Update) then + consoleEnv.Update(dt, curTime) + end +end + +function love.draw() + love.graphics.scale(scaling, scaling) + + love.graphics.setFont(font) + + love.graphics.print("0/32 KB used", 3, 0) + + if (consoleEnv.Draw) then + consoleEnv.Draw() + end +end diff --git a/monogram.ttf b/monogram.ttf new file mode 100644 index 0000000..aceaeba Binary files /dev/null and b/monogram.ttf differ diff --git a/testSprites.png b/testSprites.png new file mode 100644 index 0000000..c843ce3 Binary files /dev/null and b/testSprites.png differ