Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Particle Engine
Index -> Programming, Turing -> Turing Submissions
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
corriep




PostPosted: Sat Jan 24, 2009 6:46 pm   Post subject: RE:Particle Engine

Alright lawson, it's better than mine and faster, are you happy?
Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: Sat Jan 24, 2009 7:51 pm   Post subject: Re: Particle Engine

Quote:

Haha ok well if you make one make sure it is better than both of ours combined :p


pff of course, heck I'll just make Quake 3, i've got nothing better to do Very Happy[/quote]
zero-impact




PostPosted: Sat Jan 24, 2009 8:39 pm   Post subject: Re: Particle Engine

Quote:
Alright lawson, it's better than mine and faster, are you happy?


This wasn't about beating yours in any way.. well maybe just a little.. Wink
Yours is far more flexible then mine anyways Smile
SNIPERDUDE




PostPosted: Sun Jan 25, 2009 9:38 pm   Post subject: RE:Particle Engine

No problem man!

I think the visual effects for the engine was a cool twist, could easily liven up any game.

+20 bits
zero-impact




PostPosted: Sun Jan 25, 2009 9:50 pm   Post subject: Re: Particle Engine

Thanks Very Happy
saltpro15




PostPosted: Sun Jan 25, 2009 9:59 pm   Post subject: RE:Particle Engine

i still surpass you in bits lawson Razz
SNIPERDUDE




PostPosted: Sun Jan 25, 2009 10:13 pm   Post subject: RE:Particle Engine

Muhahaha!

+7 bits
zero-impact




PostPosted: Sun Jan 25, 2009 11:30 pm   Post subject: RE:Particle Engine

Bwhuahahahahaha
Thanks SNIPERDUDE Smile

I also found replacing the drawdot with drawline between the current x,y and prev x,y yielded quite neat results.

code:
%%particleSim%%
%Lawson Fulton%
%%%12/19/09%%%%

%Controls:
%Spacebar - attract
%Control - repulse
%Left/Right Mouse - Spawn particles

%Note: Change MAXPART for more or less particles
%      Change SPAWNRATE to change the speed the particles spawn at.

setscreen ("graphics:max;max;nobuttonbar;offscreenonly")

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
Sponsor
sponsor
saltpro15




PostPosted: 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




PostPosted: 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




PostPosted: Mon Jan 26, 2009 7:16 pm   Post subject: RE:Particle Engine

for an even cooler effect replace the "drawline" with "drawbox".
saltpro15




PostPosted: Wed Jan 28, 2009 11:26 am   Post subject: RE:Particle Engine

ha i love this thing Razz I actually haven't touched my xbox in hours, i've been playing with this instead Very Happy
Michael516




PostPosted: 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




PostPosted: 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




PostPosted: Sun Feb 08, 2009 8:14 pm   Post subject: RE:Particle Engine

Most likely a more efficient coding. Less loops, etc.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 30 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: