More cubes

I have Cube class , wich contains 3 functions , int (w ich could be constructor btw doesnt matter at the moment I guess) , draw and collide.

In my int main I have called all of this functions and it all works just fine.
But what if I want 2 cubes and I dont want to make Cube2 class , but I want to call the same class and same functions to do this job with maybe different x/y

how am I gooing to do this? declare class cube as a vectore? would really use some help .Also I will include my class Cube code so you can maybe edit it to explain me better.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Cube_Class
		{
		public:
			
				{}

		void InitCube(Cube &cube, int n)
		{	
			cube.x = 250 + n;
			cube.y = HEIGHT -90;
			cube.ID = CUBE;		
		}		
		void DrawCube(Cube cube, ALLEGRO_BITMAP *box)
		{
			al_draw_bitmap(box, cube.x + n, cube.y, 0);
		}
		void CollideCube(Cube cube, Player &mario, bool& isonground, bool& fall, bool& jump, bool &bound)
		{		
			fall = true;
			isonground = false;

			if(mario.y == (HEIGHT - mario.by) || (mario.y == (cube.y - mario.by) && ( mario.x + mario.bx > cube.x && mario.x < cube.x + cube.bx )))
			{
				isonground = true;
			}
			//Collisision====================================================================================================================
			if(mario.y + mario.by > cube.y +2 && mario.y < cube.y + cube.by )
			{
				if(mario.x + mario.bx > cube.x && mario.x < cube.x)	
					mario.x = cube.x - mario.bx;

				if(mario.x + mario.bx > cube.x + cube.bx && mario.x < cube.x + cube.bx)
					mario.x = cube.x + cube.bx;
			}
		
			if( mario.x + mario.bx > cube.x && mario.x < cube.x + cube.bx )
			{
				if(mario.y + mario.by > cube.y && mario.y < cube.y )
				{
					mario.y = cube.y - mario.by;
					isonground = true;
				}

				if(mario.y == cube.y + cube.by)	
				{					
					jump = false,
					fall = true;
				}
			}				
	}	
		};
Last edited on
Your "Cube class" looks like "class Cube_Class" and by its contents you could have used "namespace Cube_Class" instead. Your code does use type "Cube" though, probably "struct Cube".

A type is just a type. One can instantiate as many variables of that type as necessary (sans the Singletons).
I am not shure I understand you, how do you mean?
You can declare an array or a vector of cubes the same way you would do it for any other type:
1
2
Cube MyArray[2];
std::vector<Cube> MyVector;
Topic archived. No new replies allowed.