Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 17 Aug 2012
Offline Last Active Aug 18 2012 11:53 AM

Topics I've Started

C++. A loop for rendering array of blocks

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)
if(array[n] == 41) // if current object is situated in 41 pixel, we will go to another object 'n+1'
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.