Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Basic Array question c++ Sdl

  • 05-01-2007 08:20PM
    #1
    Closed Accounts Posts: 311 ✭✭


    Hi my first function creates 900 particles and assigns them positions in x, y, and velocities in both as well
    it is called initparticles

    I then want to draw thos epositions onto the screen using a drawParticles function like this;
    void initParticles()
    {
    double pX[900];
    double pY[900];
    double vX[900];
    double vY[900];
    
    for (int i=1;i<900;i++)
    {
    pX[i]=dRand(300);
    pY[i]=dRand(300);
    vX[i]=1;
    vY[i]=1;
    }
    }
    
    void drawParticles(){
    for (int i=1;i<900;i++)
    {
    myCircle(pX[i],pY[i],10,0xff00ff);
    }}
    

    note the myCircle function works it produces a circle at the point x,y with radius 10 and the colour

    the dRand creates a random number between 1 and the max number i put into it 300 in this case.


    However my particles are constantly updating there position to new random ones, how do I get them to stay put?


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Surly in the first function, the arrays are local to that and won't exist when it finishes?
    Maybe you should create the arrays in the main and then use the functions, instead of creating them in the functions.

    Also arrays start at 0, not 1 :)

    Anyways i doubt that will answer anything for you but just something i noticed.


  • Closed Accounts Posts: 311 ✭✭Passport


    yes your right I fixed them, thanks.

    my question remains however.


  • Registered Users, Registered Users 2 Posts: 304 ✭✭PhantomBeaker


    So, you're drawing a number of circles with these functions. By the way, take note of what Webmonkey said about declaring the arrays outside of the function body, this will help you in the long term.

    How are you calling the functions? I.e. what's the program that calls those functions. Where do you call those functions? How do you call those functions? What do those functions do? Should you be calling them that way?

    Remember: functionsthat do your your initial setup should only be called once.

    Hope that helps,
    Aoife


Advertisement