Newer
Older
ESP32-RetroPlay / main / tasks / game / game_framework.h
#ifndef GAME_FRAMEWORK_H
#define GAME_FRAMEWORK_H

#include <stdbool.h>
#include "ssd1306.h" // For SSD1306_t
#include "freertos/queue.h" // For QueueHandle_t

// Define common OLED dimensions used by games and display task
#define OLED_WIDTH 128
#define OLED_HEIGHT 64

// Define the reserved area for the score and game play area
#define SCORE_DISPLAY_HEIGHT 16 // Height of the top area reserved for score/info
#define GAME_PLAY_AREA_START_Y SCORE_DISPLAY_HEIGHT // Y-coordinate where the game play area begins
#define GAME_PLAY_AREA_HEIGHT (OLED_HEIGHT - SCORE_DISPLAY_HEIGHT) // Height of the actual game play area

/**
 * @brief Generic interface for any game to be integrated into the framework.
 * Each game must implement these functions.
 */
typedef struct game_t {
    // Function to initialize the game state (e.g., reset scores, positions)
    void (*init_game)(void);
    // Function to handle input for the game (e.g., read from queue)
    void (*handle_input)(void);
    // Function to update the game state for one frame (e.g., physics, collisions)
    // Returns true if the game is over, false otherwise.
    bool (*update_game_state)(void);
    // Function to draw the current game state to the OLED buffer
    void (*draw_game)(SSD1306_t *dev);
    // Function to get the current score of the game
    int (*get_score)(void);
    // Function to check if the game is currently active (running)
    bool (*is_active)(void);
    // Function to set the active state of the game
    void (*set_active)(bool active);
    // Function to get the game's input queue handle (for button task to send to)
    QueueHandle_t (*get_input_queue)(void);
    // NEW: Function to set the input queue for the game
    void (*set_input_queue)(QueueHandle_t queue);
} game_t;

#endif // GAME_FRAMEWORK_H