type particle :
record
prevx : int
prevy : int
x : int
y : int
xvel : real
yvel : real
col : int
end record
const MAXPART := 2000
const SPAWNRATE := 10
const GRAV : real := 0.9
const AIR : real := 1
const TRANSFER : real := 0.5
const FRIC := 0.8
const NULL := 9876543
const BACKCOL : int := black
const MAXSIZE := 20
var out, In : int
open : out, "out.txt", put
open : In, "in.txt", get
var mousex, mousey, mouseClick : int
var part : array 1 .. MAXPART of particle
var mouseAngle : real
var chars : array char of boolean
for i : 1 .. MAXPART
part (i).x := NULL
part (i).y := NULL
part (i).prevx := NULL
part (i).prevy := NULL
part (i).xvel := 0
part (i).yvel := 0
part (i).col := 0
end for
var currentPart : int := 0
proc spawnParticle (particlex : int, particley : int)
for k : 1 .. SPAWNRATE
if currentPart = MAXPART then
currentPart := 0
end if
currentPart += 1
part (currentPart).x := particlex % + k
part (currentPart).y := particley
part (currentPart).prevx := particlex % + k
part (currentPart).prevy := particley
part (currentPart).xvel := cosd (Rand.Int (0, 360)) * 10 %Help from http://compsci.ca/v3/viewtopic.php?t=17607
part (currentPart).yvel := sind (Rand.Int (0, 360)) * 10 % help from http://compsci.ca/v3/viewtopic.php?t=17607
part (currentPart).col := Rand.Int (0, 15)
if part (currentPart).col = black then
part (currentPart).col += 1
end if
end for
end spawnParticle
function getMouseAngle (x, y : real) : real %Help from compsci.ca http://compsci.ca/v3/viewtopic.php?t=17607
if x = 0 and y = 0 then
result 0
elsif x = 0 and y > 0 then
result 90
elsif x = 0 and y < 0 then
result 270
elsif y = 0 and x > 0 then
result 0
elsif y = 0 and x < 0 then
result 180
elsif x > 0 and y > 0 then
result arctand (y / x)
elsif x < 0 and y > 0 then
result 180 + arctand (y / x)
elsif x > 0 and y < 0 then
result 360 + arctand (y / x)
elsif x < 0 and y < 0 then
result 180 + arctand (y / x)
else
result 0
end if
end getMouseAngle
proc getInput
Mouse.Where (mousex, mousey, mouseClick)
if mouseClick = 1 then
spawnParticle (mousex, mousey)
end if
end getInput
proc physics
for i : 1 .. upper (part)
Input.KeyDown (chars)
if chars (' ') then
mouseAngle := getMouseAngle (mousex - part (i).x, mousey - part (i).y) %%Help from compsci.ca
part (i).xvel += cosd (mouseAngle) * 2 %Help from http://compsci.ca/v3/viewtopic.php?t=17607
part (i).yvel += sind (mouseAngle) * 2 % help from http://compsci.ca/v3/viewtopic.php?t=17607
elsif chars (KEY_CTRL) then
mouseAngle := getMouseAngle (mousex - part (i).x, mousey - part (i).y) %%Help from compsci.ca
part (i).xvel += -cosd (mouseAngle) * 2 %Help from http://compsci.ca/v3/viewtopic.php?t=17607
part (i).yvel += -sind (mouseAngle) * 2 % help from http://compsci.ca/v3/viewtopic.php?t=17607
end if
if part (i).x = NULL & part (i).y = NULL then
%do nothing
else
if part (i).y > 0 then
part (i).yvel -= GRAV %gravity
end if
if part (i).y < 0 then
part (i).y := 0
part (i).yvel := -part (i).yvel * TRANSFER
end if
if part (i).y > maxy then
part (i).y := maxy
part (i).yvel := -part (i).yvel * TRANSFER
end if
if part (i).x >= maxx then
part (i).x := maxx - 1 %infinite walls
part (i).xvel := -part (i).xvel * TRANSFER %bounce off right wall
%part (i).on := false
end if
if part (i).x <= 0 then
part (i).x := 1 %infinite walls
part (i).xvel := -part (i).xvel * TRANSFER %bounce off left wall
%part (i).x := 0
end if
end if
part (i).xvel *= AIR
part (i).yvel *= AIR
part (i).prevx := part (i).x
part (i).prevy := part (i).y
part (i).x += round (part (i).xvel) %adding the x and y vel to the a and y position
part (i).y += round (part (i).yvel)
end for
end physics
proc gfx
drawfillbox (0, 0, maxx, maxy, BACKCOL) %background
for i : 1 .. upper (part)
drawline (part (i).prevx, part (i).prevy, part (i).x, part (i).y, part (i).col) %particle
end for
View.Update
end gfx
loop
getInput
physics
gfx
Time.DelaySinceLast (30)
end loop
Sponsor Sponsor
saltpro15
Posted: Mon Jan 26, 2009 10:32 am Post subject: RE:Particle Engine
with the +2 bits for writing this I overtake you once again lawson !
saltpro15
Posted: Mon Jan 26, 2009 10:33 am Post subject: RE:Particle Engine
oh btw that new effect looks a lot like Saad's prsyx game, it's cool
SNIPERDUDE
Posted: Mon Jan 26, 2009 7:16 pm Post subject: RE:Particle Engine
for an even cooler effect replace the "drawline" with "drawbox".
saltpro15
Posted: Wed Jan 28, 2009 11:26 am Post subject: RE:Particle Engine
ha i love this thing I actually haven't touched my xbox in hours, i've been playing with this instead
Michael516
Posted: Fri Feb 06, 2009 4:55 pm Post subject: RE:Particle Engine
These are awsome programs, my favourite is the one with the lines.
saltpro15
Posted: Fri Feb 06, 2009 5:37 pm Post subject: RE:Particle Engine
I like the drawbox, how did you make it so much faster than the last one?
SNIPERDUDE
Posted: Sun Feb 08, 2009 8:14 pm Post subject: RE:Particle Engine
Most likely a more efficient coding. Less loops, etc.