I am an advanced beginner in C++ and I tried to make a program with classes. Well.. this program drops "apples" from the sky and you have to catch them with a "basket". I want those "apples" to be in an array of objects but they keep getting the same coordinates. Here's part of the code:
const int appleAmount = 3; // I want to be able to change their amount SO this variable is needed
bool gameOver = false;
...
class Apple
{
private:
int x, y;
public:
Apple();
int getY() {return y;}
int getX() {return x;}
void Move()
{
if (y != height) //y == height is the ground, and y == 0 is the sky
y++; //makes the apple drop by one
else
{
y = 0; //when the apple hits the ground it gets back in to the sky
x = rand() % wight;
}
}
};
Apple::Apple()
{
x = rand() % wight;
/*
y = something that makes their y's different so they don't fall at the
same
*/
}
...
int main()
{
...
while(!gameOver){
...
Apple apple[appleAmount];
for (int i = 0; i < appleAmount; i++)
{
apple[i].Move(); //each apple moves every cycle
}
}
}
So... can anyone give me advise or tell me how it's done in a better way? Thanks!