Computer Science Canada

finishing my cheap explosion

Author:  Schaef [ Wed Feb 04, 2004 7:02 am ]
Post subject:  finishing my cheap explosion

hey, this is what i have so far:



code:
View.Set ("graphics:640;480, nobuttonbar")
colorback(16)
cls
var exint, eyint : int
randomize
var ex : array 1 .. 100 of int
var ey : array 1 .. 100 of int
for exn : 1 .. 100
    ex (exn) := 300
    ey (exn) := 250
end for
% EXPLOSION----------------------------------------------------------------------------------
    for exn : 1 .. 100
        randint (exint, -3, 3)
        randint (eyint, -3, 3)
        for expl : 1 .. 50
            drawfilloval (ex (exn), ey (exn), 2, 2, 40)
            delay (5)
            drawfilloval (ex (exn), ey (exn), 2, 2, 16)
            ex (exn) := ex (exn) + exint
ey (exn) := ey (exn) + eyint
 
        end for
    end for




Any ideas on how i could use processes or something in to get all of my circles to go out at the same time??

Author:  Mazer [ Wed Feb 04, 2004 12:10 pm ]
Post subject: 

OK, don't use processes, you don't really need them in this case. You just need to have an array of explosion particles and draw them all during the loop.
Here's my modified version of your code:
code:

View.Set ("graphics:640;480, nobuttonbar,offscreenonly") %offscreenonly gets rid of the flickering
colorback (16)
cls
var ex, ey, exvel, eyvel : array 1 .. 100 of int % array of (x,y) and velocities

for i : 1 .. 100
    ex (i) := maxx div 2
    ey (i) := maxy div 2
    exvel (i) := Rand.Int (-10, 10)
    eyvel (i) := Rand.Int (-10, 10)
end for

loop
    for i : 1 .. 100
        if ex (i) < 0 or ex (i) > maxx or ey (i) < 0 or ey (i) > maxy then % check if it went offscreen
            ex (i) := maxx div 2
            ey (i) := maxy div 2
            exvel (i) := Rand.Int (-10, 10)
            eyvel (i) := Rand.Int (-10, 10)
        end if
        ex (i) += exvel (i)
        ey (i) += eyvel (i)

        drawfilloval (ex (i), ey (i), 3, 3, 12)
    end for
    View.Update
    delay (20)
    cls
end loop

Author:  Schaef [ Wed Feb 04, 2004 4:10 pm ]
Post subject: 

ok thx a lot.. how do i stop the explosion after a while though b/c i need to run other things in my program

Author:  Schaef [ Wed Feb 04, 2004 4:19 pm ]
Post subject: 

oh sry! i didnt even notice that it was in a loop... neways thanks for the help.

Author:  Schaef [ Wed Feb 04, 2004 4:51 pm ]
Post subject: 

now how could i change that so that after a few seconds a few of the dots will continue to go off the screen and no more come out of the middle?

Author:  Delos [ Wed Feb 04, 2004 5:40 pm ]
Post subject: 

code:

if ex (i) < 0 or ex (i) > maxx or ey (i) < 0 or ey (i) > maxy then % check if it went offscreen
            ex (i) := maxx div 2
            ey (i) := maxy div 2
            exvel (i) := Rand.Int (-10, 10)
            eyvel (i) := Rand.Int (-10, 10)
        end if


In the code above...just take it all out!
That way you never reset any of the dots!

Author:  Schaef [ Fri Feb 06, 2004 6:04 pm ]
Post subject: 

here is the final code that i created for my explosion:

code:
View.Set ("graphics:640;480, nobuttonbar,offscreenonly")
colorback (16)
cls
var ex, ey, exint, eyint : array 1 .. 800 of int
for scndexpl : 1 .. 5
    for i : 1 .. 800
        ex (i) := 270
        ey (i) := 200
        exint (i) := Rand.Int (-20, 10)
        eyint (i) := Rand.Int (-20, 10)
    end for
end for
%VELOCITY DROP----------------------------------------------------------------
for decreasing velocity : 20 .. 0
    for explosion : 1 .. 1
        for i : 1 .. 800
            if ex (i) < 0 or ex (i) > maxx or ey (i) < 0 or ey (i) > maxy then
                ex (i) := 250
                ey (i) := 200
                randint (exint (i), -velocity, velocity)
                randint (eyint (i), -velocity, velocity)
            end if
            ex (i) := ex (i) + exint (i)
            ey (i) := ey (i) + eyint (i)
            drawdot (ex (i), ey (i), 12)
     
               drawfillbox (250, 190, 253,200,16)
        end for
        View.Update
 
        if explosion < 3 then
            cls
        end if
    end for
end for

%-----------------------------------------------------------------------------
for explosion : 1 .. 300
    for i : 1 .. 800
        if ex (i) < 0 or ex (i) > maxx or ey (i) < 0 or ey (i) > maxy then
            ex (i) := 250
            ey (i) := 200
            randint (exint (i), -0, 0)
            randint (eyint (i), -0, 0)
        end if
        ex (i) := ex (i) + exint (i)
        ey (i) := ey (i) + eyint (i)
        drawdot (ex (i), ey (i), 12)
   
        if explosion > 30 then
      drawfillbox (250, 190, 280,200,16)
      end if
    end for
    View.Update
 
    if explosion < 300 then
        cls
    end if
end for

Author:  Delos [ Sat Feb 07, 2004 4:59 pm ]
Post subject: 

Interesting...to say the least.

Try slowing the explosion down a tad. Put a couple delays here and there (reference them with a global variable, so ppl on different computers can run it at their own pace...Turing problem...hehehe).

But really, this is a huuuuuge improvement from your other, umm, twenty odd tries.

Keep it up! Claping

Author:  santabruzer [ Sat Feb 07, 2004 5:20 pm ]
Post subject: 

dude.. procedure it and use records, instead of 4 arrays.. well at least i find it easier.. so w/e...

Author:  Schaef [ Sat Feb 07, 2004 7:39 pm ]
Post subject: 

i didnt know how to use arrays b4 so that is why it is an improvement from my other tries.. lol


: