-- exploding balloons (commented)
-- by trasevol_dog
-- this cart was made
-- on the 9.9.2016, on my b-day
-- it's balloons exploding
-- into more balloons
-- to celebrate.
-- except i commented the code
-- so now it's useful to people
-- hopefully.
-- beginning here:
-- initializing some important
-- stuff. you could do that in
-- more appropriate places.
-- call me messy, i don't care.
bloons={} -- 'balloons' is long
shkx=0
shky=0
function _init()
-- you can initialize stuff
-- here too.
-- the difference is that here
-- you can call functions
-- written after this.
createbloon(64,64,32,0,8)
-- if you don't have any music
-- just put some sfx at
-- the beginning
sfx(8)
end
function _update()
-- call updating functions here
-- best not actually update
-- anything here, it gets messy
updatebloons()
updateshake()
end
function _draw()
camera(0,0)
-- partially and randomly
-- clears the screen
-- for that weird trail effect
for i=0,1999 do
circ(rnd(128),rnd(128),1,0)
end
camera(shkx,shky)
-- drawing the cool stuff
drawbloons()
end
-- creates one balloon object
-- at x,y position
-- with bigger-circle ray of r
-- a moving speed of spd
-- and c as color.
-- angle and rotating speed 'va'
-- are random.
-- then adds the balloon object
-- to the balloon array.
function createbloon(x,y,r,spd,c)
local b={x=x,y=y,r=r,a=rnd(1),va=(flr(rnd(2))-0.5)*0.5+rnd(0.2),c=c,l=0.8+rnd(0.4)}
local aaa=rnd(1)
b.vx=spd*cos(aaa)
b.vy=spd*sin(aaa)
add(bloons,b)
end
-- updating the balloon objects
-- one by one
function updatebloons()
for b in all(bloons) do
-- updating rotation 'physics'
dma=abs((b.a+0.25)%0.5-0.25)
vvv=-dma*0.005
if (b.a+0.25)%1<0.5 then
b.va+=vvv
elseif (b.a+0.25)%1>0.5 then
b.va-=vvv
end
b.a+=b.va
b.va*=0.96
-- updating position 'physics'
b.x+=b.vx
b.y+=b.vy
if(b.x-b.r<0) b.vx=2-b.vx sfx(4)
if(b.x+b.r>127) b.vx=-2-b.vx sfx(4)
if(b.y-b.r<0) b.vy=2-b.vy sfx(4)
if(b.y+b.r>127) b.vy=-2-b.vy sfx(4)
b.vx*=0.9
b.vy=0.9*b.vy+0.1*(-1)
-- updating life timer
b.l-=0.01
if b.l<0 then
-- timer is at its end...
-- *boom!*
-- creating five new balloons
-- if exploding balloon is
-- big enough
if b.r>4 then
for i=0,4 do
createbloon(b.x,b.y,b.r/4+rnd(b.r/2),8+rnd(8),8+rnd(8))
end
end
-- the 'oompf'
circfill(b.x,b.y,b.r+2,7)
addshake(b.r)
sfx(flr(rnd(4)))
-- delete exploded balloon
del(bloons,b)
end
end
end
-- drawing the balloon objects
-- one by one
function drawbloons()
for b in all(bloons) do
-- uncomment the outline
-- for sweet graphics
-- and low framerate
--outlined(drawbloon,7,b)
drawbloon(b)
end
end
-- draws one balloon
-- actually several circles
-- smaller and smaller,
-- going from balloon's x,y pos
-- along its 'a' angle
function drawbloon(b)
for i=0,7 do
circfill(b.x+i*(b.r/8)*cos(b.a),b.y+i*(b.r/8)*sin(b.a),(1-(i/16))*b.r,b.c)
end
local rrr
if b.r>10 then rrr=2
else rrr=1 end
local rr=7*(b.r/8)+(1-(7/16))*b.r+rrr
circfill(b.x+rr*cos(b.a),b.y+rr*sin(b.a),rrr,b.c)
end
-- addshake adds a screenshake
-- of 'p' power.
-- you have to call updateshake
-- every once in a while
-- (on _update for example)
-- and use 'camera(shkx,shky)'
-- before drawing stuff
-- for the screenshake to work
function addshake(p)
local a=rnd(1)
shkx+=p*cos(a)
shky+=p*sin(a)
end
function updateshake()
if abs(shkx)+abs(shky)<0.5 then
shkx=0
shky=0
end
shkx*=0.7+rnd(0.2)
shky*=0.7+rnd(0.2)
end
-- makes every color
-- being drawn as the color 'c'
-- 'allcolorsto()' resets
function allcolorsto(c)
if c then
for i=0,15 do
pal(i,c)
end
else
for i=0,15 do
pal(i,i)
end
end
end
-- outlines in color 'c'
-- whatever drawing function's
-- callback is set as 'draw',
-- also feeding that function
-- with 'arg' as argument
function outlined(draw,c,arg)
allcolorsto(c)
camera(shkx-1,shky)
draw(arg)
camera(shkx+1,shky)
draw(arg)
camera(shkx,shky-1)
draw(arg)
camera(shkx,shky+1)
draw(arg)
-- uncomment for shadow effect
--camera(shkx,shky-2)
--draw(arg)
camera(shkx,shky)
allcolorsto()
end