#include <iostream>
#include <conio.h>
usingnamespace std;
bool off;
int x,y;
int height = 20;
int width = 20;
enum eDirecton { STOP = 0, LEFT, RIGHT, UP, DOWN}; // direction
eDirecton dir;
void start ()
{
off = false;
x = width / 2;
y = height / 2;
}
void graphics () // shows the graphics on the screen of the game
{
system ("cls"); // clears the screen so that the map will not stack on top of each other
for (int i = 0; i<width +2; i++) // top cover
{
cout << "1";
}
cout << endl;
for ( int j = 0 ; j < height; j++)
{
cout << "2";
for ( int k = 0; k < width ; k++)
{
if (j == y && k == x)
{
cout << "O";
}
else
cout << " "; // fills in the middle
}
cout << "3";
cout << endl;
}
for (int i = 0; i<width +2; i++) // bottom cover
{
cout << "4";
}
}
void Input() // how the program knows which key to input and what direction it will go
{
if (_kbhit())
{
switch (_getch())
{
case'a':
dir = LEFT;
break;
case'd':
dir = RIGHT;
break;
case'w':
dir = UP;
break;
case's':
dir = DOWN;
break;
case'x':
off = true;
break;
}
}
}
void system ()
{
switch (dir)
{
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y--;
break;
case DOWN:
y++;
break;
default:
break;
}
}
int main ()
{
start(); // in order to enable the while loops the "start" function must be called on
while (!off) //constantly refreshes the program
{
graphics ();
void system ();
void input ();
}
}
Well you already have an x,y for the player, so you need a way to dynamically create new entities(bullets) with their own x,y's. You could create a struct with x and y members, then add a new one to a vector whenever the 'fire' key is pressed, and remove them when they collide with something.