Hello!
I am trying to do my first C++ console game based on objects. I have been working in GM(Game Maker) until recently so I have quite good idea about what classes are for and what are instances.
On the other hand: now, with no Interface like GM has, I have problem declaring them. See, in GM you create objects clicking one button, write what they are supposed to do every tick (called Step). And then you just place them in a room and you can play the game.
Now I have tried to do something that works similliar to that. I have created class Object, that has children - class Ball, class Monster, class Brick..; I'd have another class called Comp, that would take care of everything those classes can't + class Drawer, that the classes can use to write out their variables in the console.
So, every class under Object class has it's X and Y. And let's say the balls should fall. So that every step they execute the piece of code: Y++;
I have clear idea how to do that with one ball.
1 2 3 4 5 6
|
Comp::Comp() {
Ball objBall;
}
Comp::Step() {
objBall.Y++;
}
|
Now what if I want to have 2 balls. What if I want to have thousands of balls.
I've searched for the solution online and I have tried my own solution and I ended up on two things.
1.
I have tried to create an array of classes or class pointers and neither of them works. You know, I'd use them to run the Step event of every array member - every instance; Like this:
1 2 3 4 5
|
Ball Instance[1];
Ball Instance[2];
for (i=1; i<3; i+=1) {
Instance[i].Step();
}
|
Errors:
lines: Ball Instance[1]; and Ball Instance[2];
"missing ';' before identifier"
"missing type specifier - int assumed"
2.
Passing a class name throught function. So that I don't have to create Creating function for each class.
InstanceCreate(int X, int Y, class Obj);
that and
1 2 3 4
|
void InstanceCreate(int X, int Y, class Obj) {
Obj Instance[1];
Instance[1].X=X;
}
|
Errors:
line: InstanceCreate(int X, int Y, class Obj);
"incomplete type is not allowed"
Obviously, my approach is entirely off. Could you please push me slightly the right way or send me link to a tutorial regarding this problem?
Thank you for your help. :)