dosember-jam-2025/game/main.lua

99 lines
2.5 KiB
Lua

-- if love.system.getOS() ~= 'DOS' then
-- local lick = require "3rd.lick"
-- lick.updateAllFiles = true
-- end
local platform = require "platform.platform"
require "tilemap"
local bf
local hamsterMouse
local tilemap
local mapX = 0
local mapY = 0
local mapSpeed = 32
local function drawText(str, x, y)
local font = love.graphics.getFont()
love.graphics.print(str, x - font:getWidth(str) / 2, y - font:getHeight() / 2)
end
function love.load()
platform.init()
math.randomseed(os.time())
bf = love.graphics.newImageFont("res/font.png",
" abcdefghijklmnopqrstuvwxyz" ..
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
"123456789.,!?-+/():;%&`'*#=[]\"")
if love.system.getOS() == 'DOS' then
hamsterMouse = love.graphics.newImage("res/hammouse.gif")
else
hamsterMouse = love.graphics.newImage("res/hammouse.png")
end
tilemap = TileMap:new(
16,
-- TODO: replace the Kenney tiles
{
love.graphics.newImage("res/kenney/t0000.png"),
love.graphics.newImage("res/kenney/t0001.png"),
love.graphics.newImage("res/kenney/t0002.png")
},
{},
platform.isNative and "replace" or "fast",
16 * 5
)
tilemap:random(10, 10)
end
function love.update(dt)
if love.keyboard.isDown("d") then
mapX = mapX + mapSpeed * dt
elseif love.keyboard.isDown("a") then
mapX = mapX - mapSpeed * dt
end
if love.keyboard.isDown("w") then
mapY = mapY - mapSpeed * dt
elseif love.keyboard.isDown("s") then
mapY = mapY + mapSpeed * dt
end
end
function love.draw()
platform.drawStart()
love.graphics.clear()
love.graphics.setFont(bf)
tilemap.offsetX = math.floor(mapX)
tilemap.offsetY = math.floor(mapY)
-- local time = love.timer.getTime()
-- tilemap.offsetX = 50 + math.floor(math.cos(time) * 25)
-- tilemap.offsetY = 50 + math.floor(math.sin(time) * 25)
tilemap:update()
local tilemapPosX = tilemap.offsetX
local tilemapPosY = tilemap.offsetY
tilemap:draw(tilemapPosX, tilemapPosY)
love.graphics.setColor(255, 0, 0)
love.graphics.rectangle("line", tilemapPosX - 1, tilemapPosY - 1, 16 * 5 + 1, 16 * 5 + 1)
love.graphics.setColor(255, 255, 255)
drawText('Hellorld!', 160, 100)
love.graphics.draw(hamsterMouse, love.mouse.getX(), love.mouse.getY())
platform.drawEnd()
end
function love.keypressed(key)
if key == "space" then
print("TEST!!")
end
if key == "escape" then
os.exit()
end
end