-- 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 someUnit 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) require "unit" someUnit = SomeUnit:new(tilemap, 30, 30) end -- 0: nothing -- 1: holding LMB -- 2: dragging with LMB held local mouseState = 0 local mouseStartX = 0 local mouseStartY = 0 local mouseEndX = 0 local mouseEndY = 0 function love.mousepressed(x, y, button) if button == 1 then if mouseState == 0 then mouseState = 1 mouseStartX = x mouseStartY = y end end end function love.mousemoved(x, y, dx, dy) if mouseState == 1 then mouseState = 2 end -- fallthrough if mouseState == 2 then mouseEndX = x mouseEndY = y end end function love.mousereleased(x, y, button) if button == 1 then if mouseState == 1 then -- TODO: callback elseif mouseState == 2 then -- TODO: callback end mouseState = 0 end 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 local tilemapPosX = 10 local tilemapPosY = 10 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) someUnit:draw() drawText('Hellorld!', 160, 100) if mouseState == 2 then love.graphics.setColor(0, 255, 255) love.graphics.rectangle("line", mouseStartX, mouseStartY, mouseEndX - mouseStartX, mouseEndY - mouseStartY) love.graphics.setColor(255, 255, 255) end 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