Jump to content

  • Log In with Google      Sign In   
  • Create Account

C++. A loop for rendering array of blocks


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 iQuality   Members   -  Reputation: 101

Like
0Likes
Like

Posted 17 August 2012 - 08:31 PM

I`m using SDL\OpenGL in C++, and the task is to render an array of objects, that will move in column one after another, in the straight line.
So, my curret code:
I will skip all initialization, so that i need only the idea how to realise this
struct object
{
//Elements are used for x and y position of an object and its width and height
float x = 0;
float y = 200;
float width = 40;
float height = 40;
};
int const objects = 20;
object array[objects];
for ( int n = 0; n <= objects; n++)
{
array[n].x+=0.02; // current 'n' object will move for 0.02 pixels left
// but this loop moves all objects together, and i need to move them one after another
}

I have an idea, but it`s need to be improved
while( n <= objects)
{
array[n].x+=0.02;
if(array[n] == 41) // if current object is situated in 41 pixel, we will go to another object 'n+1'
n++;
}
The problem of this loop - when it goes to another object, the previous object stoppes, becouse we started to operate with another one.
Sorry, It`s rather complicated to introduce and my english isn`t so good, but if you have read and understand all of this, huge Thanks to you.
Will be waiting for some ideas.s.

Edited by iQuality, 17 August 2012 - 08:52 PM.


Sponsor:

#2 Goran Milovanovic   Members   -  Reputation: 1104

Like
0Likes
Like

Posted 17 August 2012 - 11:18 PM

that will move in column one after another


I think this part needs to be explained in a little more detail.

If you want to "see" anything move, you'll have to render your scene after every single displacement. Also, it might help to position your objects in different locations; Right now, they're all initialized to the exact same values, so x and y are set to 0 and 200, respectively.

+---------------------------------------------------------------------+

| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

#3 Servant of the Lord   Crossbones+   -  Reputation: 21073

Like
0Likes
Like

Posted 17 August 2012 - 11:38 PM

Are you wanting to move one object, and then a few seconds later, the next object? Are you wanting a delay/pause in time before each object moves?
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#4 iQuality   Members   -  Reputation: 101

Like
0Likes
Like

Posted 18 August 2012 - 06:57 AM

Are you wanting to move one object, and then a few seconds later, the next object? Are you wanting a delay/pause in time before each object moves?

Yes, your understand me correctly. But the problem of delay - it`s stoppes all the "game loop", it will just pause for a while all loop, at as a result it would do nothing except of changing the speed of movement.
I`ll explain it in code:

while( n <= objects)
{
array[n].x+=0.02;
SDL_Delay(2000) // the code stoppes for 2 seconds, so the iterations stops too. As a result the 'n = 0' object moves fo "0.02" pixels,
//then stoppes for 2 seconds, and after it another 'n = 1'object moves for "0.02" pixels and stoppes.
n++;
}


that will move in column one after another


I think this part needs to be explained in a little more detail.

If you want to "see" anything move, you'll have to render your scene after every single displacement. Also, it might help to position your objects in different locations; Right now, they're all initialized to the exact same values, so x and y are set to 0 and 200, respectively.


Yes, with rendering scenes all correct, the problem is with movement objects, like Goran Milovanovic says, I need a delay after all of my objects.
In another word, i`m making like simple "tower defence game", and i need to generate my enemies, that will move in column, without collision.

Edited by iQuality, 18 August 2012 - 06:58 AM.


#5 iQuality   Members   -  Reputation: 101

Like
0Likes
Like

Posted 18 August 2012 - 11:54 AM

The problem is solved... I use timer. Thanks for attention. The topic may be closed




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS