breakout/include/Game.h

122 lines
1.9 KiB
C++

#pragma once
#include <vector>
#include <Util.h>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <imgui-SFML.h>
#include <imgui.h>
struct Ball
{
Ball(sf::Vector2f position_in, sf::Vector2f vel_in);
sf::Vector2f pos;
sf::Vector2f velocity;
sf::Vector2f previousPos{};
bool alive{true};
bool collided{false};
};
struct Brick
{
Brick(sf::Vector2f position_in);
sf::Vector2f pos;
bool alive{true};
};
struct Player
{
Player() = default;
Player(sf::Vector2f position_in);
sf::Vector2f pos{};
sf::Vector2f previousPos{};
int score{};
int lives{3};
int mult{1};
bool left{false};
bool right{false};
};
class Game
{
public:
Game();
void run();
void runNoImgui();
private:
void imgui();
void render();
void input();
void collision();
void movement();
void updateEntities();
void checkEndGame();
void checkBallCollision();
void resetGame();
bool parseConfigFile();
void setupLevel();
void soundSystem();
void scoreSystem();
private:
sf::Clock clock;
sf::RenderWindow window;
sf::Font font;
sf::Text lives;
sf::Text score;
sf::Text currentMult;
sf::SoundBuffer collideSoundBuffer;
sf::SoundBuffer brickBreakSoundBuffer;
sf::SoundBuffer failSoundBuffer;
sf::Sound collideSound;
sf::Sound brickBreakSound;
sf::Sound failSound;
Player player;
std::vector<Ball> balls;
std::vector<Brick> bricks;
std::vector<Brick> specialBricks;
std::vector<sf::Vector2f> ballsToAdd;
sf::CircleShape tempCircle;
sf::RectangleShape tempRect;
// mostly used for imgui
sf::Vector2f brickSize{};
sf::Vector2f playerSize{};
sf::Vector2f playerStartPos{};
sf::Vector2f brickHalfSize{};
sf::Vector2f playerHalfSize{};
int totalSpecialBricks{};
int totalBricks{};
int framerate{};
float playerSpeed{};
float ballRadius{};
float ballMaxSpeed{};
Color ballColor{};
Color brickColor{};
Color playerColor{};
Color specialBrickColor{};
static constexpr unsigned int numPhysicsUpdates{4};
};