From d2dab6c8efcf126503c004e935fda9190533729c Mon Sep 17 00:00:00 2001 From: cursed22bc Date: Tue, 10 Mar 2026 22:29:39 +0200 Subject: particles --- bloodParticle.lua | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 bloodParticle.lua (limited to 'bloodParticle.lua') diff --git a/bloodParticle.lua b/bloodParticle.lua new file mode 100644 index 0000000..12aa2af --- /dev/null +++ b/bloodParticle.lua @@ -0,0 +1,82 @@ +local BloodParticle = {} +BloodParticle.__index = BloodParticle + +local SHRINK_RATE = 6 +local GRAVITY = 300 +local PARTICLE_COUNT = 32 +local BURST_SPEED_MIN = 40 +local BURST_SPEED_MAX = 160 + +local BLOOD_COLORS = { + {0.22, 0.38, 0.22, 1}, + {0.18, 0.30, 0.18, 1}, + {0.28, 0.44, 0.28, 1}, + {0.14, 0.22, 0.14, 1}, +} + +local GLOW_COLOR = {0.05, 0.7, 0.05, 0.0} -- meh + +function BloodParticle.new(x, y, radius, color, vx, vy) + local self = setmetatable({}, BloodParticle) + self.x = x + self.y = y + self.radius = radius + self.initialRadius = radius + self.color = color + self.vx = vx or 0 + self.vy = vy or 0 + self.stuck = false + self.kill = false + return self +end + +function BloodParticle:update(dt, isSolidAt) + if self.stuck or self.kill then return end + + self.x = self.x + self.vx * dt + self.y = self.y + self.vy * dt + self.vy = self.vy + GRAVITY * dt + + self.radius = self.radius - SHRINK_RATE * dt + + local hitWall = isSolidAt and isSolidAt(self.x, self.y) + if hitWall or self.radius <= self.initialRadius * 0.5 then + self.stuck = true + self.radius = math.max(self.radius, self.initialRadius * 0.35) + self.vx, self.vy = 0, 0 + return + end + + if self.radius <= 0 then + self.kill = true + end +end + +function BloodParticle:draw() + if self.kill then return end + + love.graphics.setBlendMode("add") + love.graphics.setColor(GLOW_COLOR) + love.graphics.circle("fill", self.x, self.y, self.radius * 2.2) + love.graphics.setBlendMode("alpha") + + love.graphics.setColor(self.color) + love.graphics.circle("fill", self.x, self.y, self.radius) + love.graphics.setColor(1, 1, 1, 1) +end + +function BloodParticle.burst(x, y) + local particles = {} + for _ = 1, PARTICLE_COUNT do + local angle = math.random() * math.pi * 2 + local speed = BURST_SPEED_MIN + math.random() * (BURST_SPEED_MAX - BURST_SPEED_MIN) + local vx = math.cos(angle) * speed + local vy = math.sin(angle) * speed - 40 + local radius = 1.5 + math.random() * 8.0 + local color = BLOOD_COLORS[math.random(#BLOOD_COLORS)] + table.insert(particles, BloodParticle.new(x, y, radius, color, vx, vy)) + end + return particles +end + +return BloodParticle -- cgit v1.2.3