From d2dab6c8efcf126503c004e935fda9190533729c Mon Sep 17 00:00:00 2001 From: cursed22bc Date: Tue, 10 Mar 2026 22:29:39 +0200 Subject: particles --- world.lua | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'world.lua') diff --git a/world.lua b/world.lua index a4d7f12..0678804 100644 --- a/world.lua +++ b/world.lua @@ -4,6 +4,8 @@ local Player = require("player") local Camera = require("camera") local Textbox = require("textbox") local Enemy = require("enemy") +local BloodParticle = require("bloodParticle") +local DustSystem = require("dustParticle") local World = {} World.__index = World @@ -39,6 +41,9 @@ function World:new() self.contactKind = {} self.pendingPlayerDeath = nil self.playerTextbox = Textbox:new() + self.bloodParticles = {} + self.bloodSplatters = {} + self.dustSystem = DustSystem.new() return self end @@ -395,6 +400,21 @@ function World:isTileSolidAtPixel(x, y) return gid and gid ~= 0 end +function World:spawnBlood(x, y) + local newParticles = BloodParticle.burst(x, y) + for _, p in ipairs(newParticles) do + table.insert(self.bloodParticles, p) + end +end + +function World:drawBloodSplatters() + for _, s in ipairs(self.bloodSplatters) do + love.graphics.setColor(s.color) + love.graphics.circle("fill", s.x, s.y, s.radius) + end + love.graphics.setColor(1, 1, 1, 1) +end + local function drawTileLayer(layer, mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) if not layer or not layer.visible or not layer.data then return end local w = layer.width or 0 @@ -485,6 +505,7 @@ function World:draw() love.graphics.setCanvas(self.refractionCanvas) love.graphics.clear(0, 0, 0, 1) drawTileLayer(self.tilemap:getFargroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) + self:drawBloodSplatters() drawTileLayer(self.tilemap:getDecorationBackgroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) drawTileLayer(self.tilemap:getBackgroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) drawTileLayer(self.tilemap:getGroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) @@ -494,6 +515,9 @@ function World:draw() for _, e in ipairs(self.entities) do if e.draw then e:draw() else World.drawEntityDefault(self, e) end end + for _, p in ipairs(self.bloodParticles) do + p:draw() + end drawTileLayer(self.tilemap:getForegroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) drawTileLayer(self.tilemap:getDecorationForegroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) love.graphics.setCanvas(mainCanvas) @@ -544,6 +568,7 @@ function World:draw() drawTileLayer(self.tilemap:getDecorationBackgroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) drawTileLayer(self.tilemap:getGroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) drawTileLayer(self.tilemap:getFargroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) + self:drawBloodSplatters() drawTileLayer(self.tilemap:getDecorationBackgroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) love.graphics.setColor(0.25, 0.5, 0.9, 0.6) @@ -569,13 +594,17 @@ function World:draw() if not useRefraction then for _, e in ipairs(self.entities) do - print(e) if e.draw then e:draw() else World.drawEntityDefault(self, e) end end + for _, p in ipairs(self.bloodParticles) do + p:draw() + end drawTileLayer(self.tilemap:getForegroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) drawTileLayer(self.tilemap:getDecorationForegroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) end + self.dustSystem:draw() + if DEBUG then World.drawPhysicsBodyOutlines(self.entities) World.drawPhysicsBodyOutlines(self.groundEntities) @@ -619,6 +648,9 @@ function World:update(dt) self.physicsWorld:update(PHYSICS_DT) if self.pendingPlayerDeath and self.player then + local px = self.player.x + self.player.width / 2 + local py = self.player.y + self.player.height / 2 + self:spawnBlood(px, py) self.player:die(self.pendingPlayerDeath.nx, self.pendingPlayerDeath.ny) self.pendingPlayerDeath = nil end @@ -659,6 +691,18 @@ function World:update(dt) if spike.update then spike:update(dt) end end + local solidCheck = function(x, y) return self:isTileSolidAtPixel(x, y) end + for i = #self.bloodParticles, 1, -1 do + local p = self.bloodParticles[i] + p:update(dt, solidCheck) + if p.stuck then + table.insert(self.bloodSplatters, { x = p.x, y = p.y, radius = p.radius, color = p.color }) + table.remove(self.bloodParticles, i) + elseif p.kill then + table.remove(self.bloodParticles, i) + end + end + for i = #self.activeSplashes, 1, -1 do self.activeSplashes[i].t = self.activeSplashes[i].t + dt * 2 if self.activeSplashes[i].t >= 1 then @@ -674,6 +718,7 @@ function World:update(dt) if self.camera then self.camera:setTarget(self.player) self.camera:update(dt) + self.dustSystem:update(dt, self.camera.x, self.camera.y, self.camera.width, self.camera.height) end if self.playerTextbox.active and self.player then -- cgit v1.2.3