+vmanes i have a code for the player, the code is how to control our player but i am confused on how to do for the asteroids.
here is the code for controlling our player:-
/* Declare Goto Function */
void gotoxy(int, int);
/* Init X and Y plus the Variables which hold
previous X and Y. */
int x, y, lastx, lasty;
/* Make a CHAR variable to get Key Input */
/* Main Function */
/* Give a value to all integer variables we declared */
x = 20; y = 30;
lastx = x; lasty = y;
/* start an Infinite Loop */
while(1 == 1)
/* Head to LastX and LastY and clear old O*/
/* Draw New O */
/* Get Input */
a = getch();
/* Remember Old X and Y */
lastx = x; lasty = y;
/* If Right Arrow is Pressed, X is increased */
if (a == 77) x = x + 1;
/* If Left Arrow is Pressed, X is decreased */
if (a == 75) x = x - 1;
/* Make GOTOXY function */
void gotoxy(int eex, int eey)
coord.X = eex;
coord.Y = eey;
now what i need is i want the asteroid to generate at y axis = 1 and x axis = random, and every second the y axis = -1, and 5 asteroids should be spawned every second.
I googled but found nothing related.
I am tring but unable to
(1) The "conio.h" header is old and often not even supported at all, and it is certainly not a standard header. Also, you are not using any functions from that header, so you should just remove that include.
(2) The "stdio.h" is not a standard C++ header, it's a C header. To include the C++ equivalent of that header, you need to do #include <cstdio>.
(3) If you are going to use standard functions (like printf() or rand()) with pre-pending them with std::, then you need to add using namespace std; at the beginning (after the include statements).
(4) You need to care more about indentation than that. Please indent your code correctly, for everyone's sake.
(5) The rand() function is from the cstdlib header, so you need to add #include <cstdlib>.
(6) The rand() function needs to be seeded to produce actual random numbers, otherwise, it will always produce the same sequence of numbers every time you run the program. You can seed it with the srand function, as in the reference example.
(7) The variable max_x_coord is undeclared. This should be either some number or constant that is the maximum value that you want x to have, because rand() % max_x_coord will generate a random number between 0 and max_x_coord, whatever you put there.