Last active
June 28, 2022 08:54
-
-
Save Achie72/b528c49987b2550d37c9d45a5ccbcaad to your computer and use it in GitHub Desktop.
Making Abilities Look Better
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 retro platformer | |
-- 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. | |
-- fire flower | |
if pickup.tpe == 1 then | |
-- set the powerUp state | |
player.powerUp = 2 | |
-- create the fast animation effect like coins | |
pickup.animSpeed = pickup.animSpeed*2 | |
pickup.deleteTime = time() + 0.1 | |
score = 400 | |
player.score += score | |
-- here we add the various particles | |
-- the particle creation basically looks like this: | |
-- function add_particle( _x, _y, _maxAge, _color, _type, _goal, _velocity) | |
-- where 2 is the "draw circle around the point" particle | |
-- color is a table for colors, that are used based on the age of the particle | |
-- see below on particle update. | |
-- variation achieved by rnd() calls and different life time values. | |
add_particle(pickup.x + 4 + rnd(5), pickup.y + 4 + rnd(5), 15, {8, 7, 8, 2, 5}, 2, nil, nil) | |
add_particle(pickup.x + 4 + rnd(5), pickup.y + 4 + rnd(5), 25, {8, 7, 8, 2, 5}, 2, nil, nil) | |
add_particle(pickup.x + 4 + rnd(5), pickup.y + 4 + rnd(5), 30, {8, 7, 8, 2, 5}, 2, nil, nil) | |
global.camShake = true | |
global.camShakeTime = time() + 1.5 | |
global.offset = 0.07 | |
global.pauseTime = time() + 1 | |
player.powerUpTime = time() + 1 | |
sfx(4) | |
end | |
-- for reference dash particles look like this: | |
add_particle(pickup.x + 4 + rnd(5), pickup.y + 4 + rnd(5), 15, {10,7,10,9,6}, 2, nil, nil) | |
add_particle(pickup.x + 4 + rnd(5), pickup.y + 4 + rnd(5), 25, {10,7,10,9,6}, 2, nil, nil) | |
add_particle(pickup.x + 4 + rnd(5), pickup.y + 4 + rnd(5), 30, {10,7,10,9,6}, 2, nil, nil) | |
-- notice that the only difference is the color map | |
-- hence we can create a range of variation around this | |
-- particle update | |
function update_particles() | |
if not (#particles == 0) then | |
for particle in all(particles) do | |
-- lifetime and color changes | |
if particle.lifeTime > particle.maxAge then | |
del(particles, particle) | |
else | |
if #particle.color_range == 1 then | |
particle.clr = particle.color_range[1] | |
else | |
local idx = particle.lifeTime / particle.maxAge | |
idx = 1 + flr(idx * #particle.color_range) | |
if idx > #particle.color_range then idx = #particle.color_range end | |
particle.clr = particle.color_range[idx] | |
end | |
end | |
-- reduce lifetime | |
particle.lifeTime +=1 | |
if not (particle.velocity == nil) then | |
particle.x += particle.velocity.x | |
particle.y += particle.velocity.y | |
end | |
end | |
end | |
end | |
-- and the particle draw | |
function draw_particles() | |
if not (#particles == 0) then | |
for particle in all(particles) do | |
-- moving dot particle | |
if particle.tpe == 1 then | |
circfill(particle.x + sin(rnd()), particle.y + sin(rnd()), particle.lifeTime / 10, particle.clr ) | |
end | |
-- circle particles | |
if particle.tpe == 2 then | |
if sin(rnd()) > 0.3 then | |
circ(particle.x+rnd(), particle.y+rnd(), particle.lifeTime, particle.clr) | |
end | |
-- circl fill particle | |
end | |
if particle.tpe == 3 then | |
circfill( particle.x+sin(rnd()), particle.y+sin(rnd()), particle.lifeTime/1, particle.clr ) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment