breakout/include/Game.h

101 lines
1.7 KiB
C++

#pragma once
#include <vector>
#include <Util.h>
#include <Random.h>
#include <SFML/Graphics.hpp>
#include <imgui-SFML.h>
#include <imgui.h>
struct Ball
{
Ball(sf::Vector2f position_in, sf::Vector2f vel_in);
sf::Vector2f pos;
sf::Vector2f previousPos{};
sf::Vector2f velocity;
bool alive{true};
};
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{};
float score{};
int lives{3};
bool left{false};
bool right{false};
};
class Game
{
public:
Game();
void run();
private:
void imgui();
void render();
void input();
void collision();
void movement();
void updateEntities();
void checkEndGame();
void checkBallCollision();
private:
sf::Clock clock;
sf::RenderWindow window;
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{50, 10};
sf::Vector2f playerSize{500, 10};
sf::Vector2f playerStartPos{700,700};
sf::Vector2f brickHalfSize{brickSize / 2.f};
sf::Vector2f playerHalfSize{playerSize / 2.f};
int rowSize{8};
int columnSize{5};
int totalSpecialBricks{3};
int totalBricks{rowSize * columnSize};
unsigned int frameRate{60};
float playerSpeed{10};
float ballRadius{5.0f};
float ballMaxSpeed{10};
Color ballColor{sf::Color::Red};
Color brickColor{sf::Color::White};
Color playerColor{sf::Color::White};
Color specialBrickColor{sf::Color::Blue};
bool windowCollasped{false};
static constexpr unsigned int numPhysicsUpdates{4};
};