Первый коммит игры, карта тайлов

This commit is contained in:
Иван Кузьменко 2025-09-05 22:41:25 +03:00
parent eff0fe1b23
commit 265dd00213
10 changed files with 132 additions and 13 deletions

View file

@ -1,12 +1,18 @@
if love.system.getOS() ~= 'DOS' then
local lick = require "3rd.lick"
lick.updateAllFiles = true
-- local lick = require "3rd.lick"
-- lick.updateAllFiles = true
end
local platform = require "platform.platform"
local ttf
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()
@ -16,15 +22,42 @@ end
function love.load()
platform.init()
ttf = love.graphics.newFont()
bf = love.graphics.newImageFont("font.png",
bf = love.graphics.newImageFont("res/font.png",
" abcdefghijklmnopqrstuvwxyz" ..
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
"123456789.,!?-+/():;%&`'*#=[]\"")
if love.system.getOS() == 'DOS' then
hamsterMouse = love.graphics.newImage("hammouse.gif")
hamsterMouse = love.graphics.newImage("res/hammouse.gif")
else
hamsterMouse = love.graphics.newImage("hammouse.png")
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
@ -32,12 +65,20 @@ function love.draw()
platform.drawStart()
love.graphics.clear()
love.graphics.setFont(ttf)
drawText('Hellorld!', 160, 100)
love.graphics.setFont(bf)
love.graphics.print(" abcdefghijklmnopqrstuvwxyz", 0, 110)
love.graphics.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ0", 0, 130)
love.graphics.print("123456789.,!?-+/():;%&`'*#=[]\"", 0, 150)
-- local time = love.timer.getTime()
tilemap.offsetX = math.floor(mapX) -- 50 + math.floor(math.cos(time) * 25)
tilemap.offsetY = math.floor(mapY) -- 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())