Logo

Glusoft

Render everything

It's time to draw everything on the screen and update the counters for the patterns.

window.clear();

window.draw(player);

sf::Transform transform;

sf::RenderStates states;
states.transform = transform;
states.texture = &tex;

window.draw(vertices, states);

frameRate.setString(std::to_string(1.0f / timeElapsed.asSeconds()));
window.draw(frameRate);

window.display();
counterTime = counterTime + timeElapsed.asMilliseconds();
counterTime2 = counterTime2 + timeElapsed.asMilliseconds();
counterTime3 = counterTime3 + timeElapsed.asMicroseconds();

After the main loop: delete the remaining bullets

When the user exit the loop we need to delete every bullets in the array:

for (size_t i = 0; i < totalBullets; i++) {
	if (bullets[i] != NULL) {
		delete(bullets[i]);
	}
}

Conclusion

More things need to be created to have a complete game, for example a life bar, collisions and more classes to structure the code (example: a resource manager).
For the collisions it's not too complicated in this case, we circle to circle collision.
You can check that with this function:

// Return true if two circles collides
bool CC(sf::Vector3f c1, sf::Vector3f c2) {
	return (c2.x - c1.x) * (c2.x - c1.x) + (c1.y - c2.y) * (c1.y - c2.y) < (c1.z + c2.z) * (c1.z + c2.z);
}
The parameters are too circle c1 and c2 where:
x = x-coordinate of the center of the circle 
y = y-coordinate of the center of the circle
z = radius of the circle

If you want to have rectangle collisions you can use this functions:
// Return true if two rectangles collides
bool AABB(sf::FloatRect b1, sf::FloatRect b2) {
	return (b2.left < b1.left + b1.width) && (b2.left + b2.width > b1.left) && 
	(b2.top < b1.top + b1.height) && (b2.top + b2.height > b1.top);
}

You can find a lot of articles about 2d collisions, for example: 2d collision detection

Download the project: BulletHell.zip (VS2015)

<-- Bullets patterns

Dark theme