#ifndef BREAKOUT_H
#define BREAKOUT_H
#pragma once
#include "breakout_types.h"
#include <vector>
#include <string>
#include "Paddle/Paddle.h"
#include "Ball/Ball.h"
#include "Brick/Brick.h"
#include "PowerUp/PowerUp.h"
#include "GameResourceManager/GameResourceManager.h"
* @brief Core game states
*/
enum class GameState {
PLAYING,
PAUSED,
GAME_OVER,
};
* @class Game
* @brief Encapsulates all game states, objects, and core logic.
*
* Creates and initializes a game session in the constructor,
* and automatically cleans up all resources in the destructor.
*/
class Game {
public:
* @brief Construct a new Game instance.
* @param parent Pointer to the parent LVGL object (screen/container).
*/
Game(lv_obj_t* parent);
* @brief Destroy the Game instance and release all resources.
*/
~Game();
* @brief Pointer to the UI container for the game area.
* Exposed for access by GameResourceManager during map loading.
*/
lv_obj_t* m_game_area;
* @brief Dynamic array holding all brick objects.
* Exposed for access by GameResourceManager during map loading.
*/
std::vector<Brick*> m_bricks;
private:
lv_obj_t* m_parent_screen;
GameState m_state;
lv_timer_t* m_game_timer;
Rect m_gameBounds;
Paddle* m_paddle;
GameResourceManager* m_resourceManager;
int m_currentLevel;
std::vector<PowerUp*> m_powerUps;
int m_totalHpReduced = 0;
std::vector<Ball*> m_balls;
lv_obj_t* m_canvas;
private:
void init();
void trigger_game_over();
void trigger_next_level();
bool checkBallBrickCollision(const Ball* ball, const Brick* brick);
bool checkBallPaddleCollision(const Ball* ball, const Paddle* paddle);
bool checkPowerUpPaddleCollision(const PowerUp* pu, const Paddle* paddle);
void handleBallBrickCollision(Ball* ball);
void handleBallPaddleCollision(Ball* ball);
Ball* getMainBall();
Ball* getFreeBall(float radius);
void activatePowerUp(PowerUp::Type type);
static void game_timer_cb(lv_timer_t* timer);
static void touch_area_event_cb(lv_event_t* e);
static void restart_button_event_cb(lv_event_t* e);
static void next_level_button_event_cb(lv_event_t* e);
};
* @brief Start or restart the ball game.
*
* This is the only external entry point to start/restart the game.
*/
void ballgame_start();
#endif