How can I make my game 'shoot' bullets

I'm trying to make a space invader kind of game but I can't figure out how I can make it move and shoot. I'm also trying to do this without classes.

My character should be at the bottom and it should shoot out 'bullets' upward.

can you give a simple source code which can shoot out 'bullets' which I can use as a reference on how I should do it on my own codes?

Here's what I've done so far, just so I could give a bit of an insight.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  #include <iostream>
#include <conio.h>

using namespace 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 ();
          }
}
Last edited on
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.
Topic archived. No new replies allowed.