View.Set ("offscreenonly")
colourback (black)
var sparkx, sparky, velx, vely : flexible array 1 .. 0 of real
var explx, exply, duration, ctr : flexible array 1 .. 0 of int
var x, y, button : int
var sparkdelete, expldelete, sparknum : int := 0
proc create_explosion
new explx, upper (explx) + 1
new exply, upper (exply) + 1
new duration, upper (duration) + 1
new ctr, upper (ctr) + 1
explx (upper (explx)) := x
exply (upper (exply)) := y
duration (upper (duration)) := 10
ctr (upper (ctr)) := 0
sparknum := 3
end create_explosion
loop
mousewhere (x, y, button)
View.Update
Time.DelaySinceLast (30)
cls
for i : 1 .. upper (explx)
for pppp : 1 .. sparknum
new sparkx, upper (sparkx) + 1
new sparky, upper (sparky) + 1
new velx, upper (velx) + 1
new vely, upper (vely) + 1
sparkx (upper (sparkx)) := explx (i)
sparky (upper (sparky)) := exply (i)
velx (upper (velx)) := (Rand.Int (-5, 5) * Rand.Real)
vely (upper (vely)) := (Rand.Int (-5, 5) * Rand.Real)
end for
Text.Colour (0)
ctr (i) += 1
if ctr (i) >= duration (i) then
expldelete := i
end if
end for
%%%% DELETING EXPLOSIONS %%%%
if expldelete > 0 then
for i : expldelete + 1 .. upper (explx)
explx (i - 1) := explx (i)
exply (i - 1) := exply (i)
duration (i - 1) := duration (i)
ctr (i - 1) := ctr (i)
end for
new explx, upper (explx) - 1
new exply, upper (exply) - 1
new duration, upper (duration) - 1
new ctr, upper (ctr) - 1
expldelete := 0
end if
if button = 1 then
create_explosion
end if
put upper (sparkx)
for i : 1 .. upper (sparkx)
sparkx (i) += velx (i)
sparky (i) += vely (i)
drawdot (round (sparkx (i)), round (sparky (i)), 0)
vely (i) -= 0.607
if sparkx (i) < 0 or sparkx (i) > maxx or sparky (i) < 0 or sparky (i) > maxy then
sparkdelete := i
end if
end for
%%%% DELETING SPARKLES %%%%
if sparkdelete > 0 then
for i : sparkdelete + 1 .. upper (sparkx)
sparkx (i - 1) := sparkx (i)
sparky (i - 1) := sparky (i)
velx (i - 1) := velx (i)
vely (i - 1) := vely (i)
end for
new sparkx, upper (sparkx) - 1
new sparky, upper (sparky) - 1
new velx, upper (velx) - 1
new vely, upper (vely) - 1
sparkdelete := 0
end if
end loop
|