From 265dd002130ad7a788451dae58e4aa497b5d5510 Mon Sep 17 00:00:00 2001 From: Ivan Kuzmenko <6745157+rndtrash@users.noreply.github.com> Date: Fri, 5 Sep 2025 22:41:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=20=D0=B8=D0=B3=D1=80=D1=8B,=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D0=B0=20=D1=82=D0=B0=D0=B9=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- game/conf.lua | 3 ++ game/main.lua | 65 +++++++++++++++++++++++++------ game/{ => res}/font.png | Bin game/{ => res}/hammouse.gif | Bin game/{ => res}/hammouse.png | Bin game/res/kenney/t0000.png | Bin 0 -> 99 bytes game/res/kenney/t0001.png | Bin 0 -> 123 bytes game/res/kenney/t0002.png | Bin 0 -> 144 bytes game/tilemap.lua | 75 ++++++++++++++++++++++++++++++++++++ 10 files changed, 132 insertions(+), 13 deletions(-) create mode 100644 game/conf.lua rename game/{ => res}/font.png (100%) rename game/{ => res}/hammouse.gif (100%) rename game/{ => res}/hammouse.png (100%) create mode 100644 game/res/kenney/t0000.png create mode 100644 game/res/kenney/t0001.png create mode 100644 game/res/kenney/t0002.png create mode 100644 game/tilemap.lua diff --git a/README.md b/README.md index 9180eb0..a735ae4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# LÖVE DOS/Native Abstraction +# DOSember Jam 2025 Entry by Tea Sanctuary ## Setup diff --git a/game/conf.lua b/game/conf.lua new file mode 100644 index 0000000..ed9d1dc --- /dev/null +++ b/game/conf.lua @@ -0,0 +1,3 @@ +function love.conf(t) + t.console = true +end diff --git a/game/main.lua b/game/main.lua index 3cc12db..523d5a2 100644 --- a/game/main.lua +++ b/game/main.lua @@ -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()) diff --git a/game/font.png b/game/res/font.png similarity index 100% rename from game/font.png rename to game/res/font.png diff --git a/game/hammouse.gif b/game/res/hammouse.gif similarity index 100% rename from game/hammouse.gif rename to game/res/hammouse.gif diff --git a/game/hammouse.png b/game/res/hammouse.png similarity index 100% rename from game/hammouse.png rename to game/res/hammouse.png diff --git a/game/res/kenney/t0000.png b/game/res/kenney/t0000.png new file mode 100644 index 0000000000000000000000000000000000000000..e743c54239ad02d5d34f9b8ce3c98d5b9e4c8feb GIT binary patch literal 99 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|WIbIRLo9le vb1bL*oZrZFz@_t9AhR2!lvI6;>0X`wF z^I!kJ`Tc+C}E^@DrE3<^>bP0l+XkKiU1^& literal 0 HcmV?d00001 diff --git a/game/res/kenney/t0002.png b/game/res/kenney/t0002.png new file mode 100644 index 0000000000000000000000000000000000000000..9f8471ab183cd7cc2fc9e3d7d90fa2bcb57be26f GIT binary patch literal 144 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!93?!50ihlx9Ea{HEjtmSN`?>!lvI6;>0X`wF z-8X7emxi?*%dGRu=L8BGdAc};a9mH0U}fRqo|SOqQl>*vs8|Ps=bET#tSVuLc6uCX oQfr&3kaTm^(#sA>kqMj(F(DdjlViLEfw~zyUHx3vIVCg!00E~dC;$Ke literal 0 HcmV?d00001 diff --git a/game/tilemap.lua b/game/tilemap.lua new file mode 100644 index 0000000..e43eafd --- /dev/null +++ b/game/tilemap.lua @@ -0,0 +1,75 @@ +TileMap = {} +TileMap.__index = TileMap + +function TileMap:new(size, tiles, map, blendMode, canvasWidth, canvasHeight) + local this = {} + this.size = size + this.tiles = tiles or {} + this.map = map or {} + this.blendMode = blendMode + this.canvasWidth = canvasWidth or 320 + this.canvasHeight = canvasHeight or canvasWidth or 200 + + this.offsetX = 0 + this.offsetY = 0 + this.tilesCanvasW = math.floor(this.canvasWidth / this.size) + this.tilesCanvasH = math.floor(this.canvasHeight / this.size) + this.canvas = love.graphics.newCanvas(this.canvasWidth, this.canvasHeight) + + return setmetatable(this, TileMap) +end + +function TileMap:random(x, y) + local map = {} + local tilesCount = #self.tiles + + -- Заполнение массива + for i = 1, y do + map[i] = {} + for j = 1, x do + map[i][j] = math.random(1, tilesCount) + end + end + + self.map = map +end + +function TileMap:update() + if self.map[1] == nil then + return + end + local mapHeight = #self.map + local mapWidth = #self.map[1] + local x = self.offsetX + local y = self.offsetY + local jOffset = math.max(math.floor(x / self.size) + 1, 1) + local iOffset = math.max(math.floor(y / self.size) + 1, 1) + -- print(x, iOffset) + if jOffset > mapWidth or iOffset > mapHeight or -x >= self.canvasWidth or -y >= self.canvasHeight then + return + end + local jUpper = math.min(jOffset + self.tilesCanvasW, mapWidth) + local iUpper = math.min(iOffset + self.tilesCanvasH, mapHeight) + + local prevCanvas = love.graphics.getCanvas() + love.graphics.setCanvas(self.canvas) + local prevBlendMode = love.graphics.getBlendMode() + love.graphics.setBlendMode(self.blendMode) + + love.graphics.clear(0, 255, 0) -- TODO: debug + + for i = iOffset, iUpper do + for j = jOffset, jUpper do + local tileIndex = self.map[i][j] + love.graphics.draw(self.tiles[tileIndex], self.size * (j - 1) - x, self.size * (i - 1) - y) + -- love.graphics.print(tostring(tileIndex), self.size * (j - 1) - x, self.size * (i - 1) - y) + end + end + + love.graphics.setBlendMode(prevBlendMode) + love.graphics.setCanvas(prevCanvas) +end + +function TileMap:draw(x, y) + love.graphics.draw(self.canvas, x, y) +end