Create the window

Later we will use Pi to convert degree to radian:

const double Pi = 3.14159265358979323846;

const size_t winW = 1366;
const size_t winH = 768;

sf::RenderWindow window(sf::VideoMode(winW, winH), "BulletHell");

Loading of textures

// Create an array to hold the bullets
const size_t maxBullets = 3000;
const size_t totalBullets = 16 * maxBullets;

Bullet* bullets[totalBullets];
for (size_t i = 0; i < totalBullets; i++) {
	bullets[i] = NULL;

// Use a vertex array for the rendering of the bullets
sf::VertexArray vertices(sf::Quads, 4 * totalBullets);

// Load the texture of the bullets
sf::Texture tex;

// Load the texture of the player
sf::Texture playerTex;

// Create the sprite for the player
sf::Sprite player(playerTex);
player.setPosition(winW / 2, winH - player.getTextureRect().height);
double velPlayer = 0.1;

// Create variables for the bullets patterns
double counterTime = 0;
double counterTime2 = 0;
double counterTime3 = 0;

double counterWave = 0;
double counterWave2 = 0;
double counterWave3 = 0;

double bulletTime = 0.1;
double bulletTime2 = 40;
double bulletTime3 = 100;

size_t numBullet = 0;
size_t numBullet2 = 0;
size_t numBullet3 = 0;

// Load font for the framerate
sf::Font font;

// Create the sprite to diplay the framerate
sf::Text frameRate;
frameRate.setPosition(10, 10);

double r = 20; // radius of the circle

What is a vertex array? What do we use that instead of sprites?
vertex array = array of vertices

We use a vertex array to have an efficient way of drawing multiple shape because with using sprite we will loop through the array of bullets and draw each bullet separately. If you have something like hundred of draw calls drawing each sprite separately is not a big deal. But with thousand of draw calls the framerate will drop drastically and the game will be unplayable.

The solution is to put every sprite in one vertex array and with one draw call we can draw the vertex array. The only condition to do that is to use only one texture per vertex array (that's why we have every bullet on one picture).

If you want to learn more about how the vertex array work you can read the official tutorial.

<-- Main class Bullet --- Event loop -->

Dark theme