Witch Game Explosions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Created for my Ko-fi article about my game | |
-- dev journey with my witch smup game | |
-- https://ko-fi.com/post/ENGHUN-Unnamed-Project--Making-Abilites-Look-B-X8X2DH3X2 | |
-- Code is In progress, heavily not optimized | |
-- and geared towards readability until PICO_8 | |
-- token counts come into play | |
-- creating the particles. We use sx and sy parameters | |
-- for movement later and _clr to determine our color | |
-- values. Notice the first bigger size particle we add | |
-- which is the middle white flash | |
function explode_part(_x, _y, _tpe, _clr) | |
local part = { | |
x = _x, | |
y = _y, | |
sx = 0, | |
sy = 0, | |
age = 0+rnd(10), | |
size = 3+rnd(3), | |
maxAge = 5 + rnd(10), | |
tpe = _tpe, | |
clr = 7, | |
sclr = 7 | |
} | |
add(particles, part) | |
for i=1,10 do | |
local part = { | |
x = _x, | |
y = _y, | |
sx = rnd()*4-2, | |
sy = rnd()*4-2, | |
age = 0+rnd(10), | |
size= 1+rnd(2), | |
maxAge = 30 + rnd(10), | |
tpe = _tpe, | |
clr = _clr, | |
sclr = _clr | |
} | |
add(particles, part) | |
end | |
end | |
-- in update we check for the color and update our | |
-- fading colors based on a table we determine | |
-- this way it is easy to add or modify new color fades | |
function update_particles() | |
-- pink and blue part colors shades, 14, 12, 7 | |
local partColors = {{8,2}, {1,5}, {6,5}} | |
for part in all(particles) do | |
local colorIndex = 1 | |
if part.sclr == 12 then colorIndex = 2 end | |
if part.sclr == 7 then colorIndex = 3 end | |
-- update position | |
part.x += part.sx | |
part.y += part.sy | |
part.age+=1 | |
-- we let circle explosions to fade aways | |
-- before deleting them after they reach | |
-- their lifetime | |
if part.age >= part.maxAge then | |
if not (part.tpe == "circle") then | |
del(particles, part) | |
else | |
part.size=part.size*0.9 | |
if part.size <= 1 then | |
del(particles, part) | |
end | |
end | |
end | |
-- setting the color fades for the explosion particles | |
if (part.tpe == "dot") or (part.tpe == "circle") then | |
if part.age > 10 then | |
part.clr = partColors[colorIndex][1] | |
end | |
if part.age > 20 then | |
part.clr = partColors[colorIndex][2] | |
end | |
end | |
-- applying simulated friction to slowly diminish speed | |
part.sx = part.sx * 0.9 | |
part.sy = part.sy * 0.9 | |
end | |
-- shockwaves for later | |
for sw in all(shockwaves) do | |
sw.size += sw.spd | |
if sw.size > sw.targetSize then | |
del(shockwaves, sw) | |
end | |
end | |
end | |
-- we just iterate through our collection | |
-- and draw the particle accordingly of it's | |
-- type | |
function draw_particles() | |
for part in all(particles) do | |
if part.tpe == "circle" then | |
circfill(part.x, part.y, part.size, part.clr) | |
elseif part.tpe == "dot" then | |
pset(part.x, part.y, part.clr) | |
end | |
end | |
for sw in all(shockwaves) do | |
circ(sw.x+rnd()*5, sw.y+rnd()*5, sw.size, sw.clr) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment