Files
basic1/lib/game_launcher.h
Adolfo Reyna e6e4eca188 Add Lua 5.4 scripting integration for dynamic game loading
- Integrated Lua 5.4 engine (32-bit mode for embedded ARM)
- Created LuaGame wrapper class implementing Game interface
- Added C++ bindings exposing renderer, game state, and input to Lua
- Implemented SD card loader for automatic .lua game discovery
- Updated GameLauncher to support std::function for lambda captures
- Made Game class members public for Lua bindings access
- Added example Lua games: counter, snake, bouncing ball
- Included comprehensive API documentation

Games can now be written as .lua text files on SD card and loaded
without recompilation. Build size: 747KB UF2, Lua VM uses ~50-80KB RAM.
2026-02-07 11:56:03 -05:00

106 lines
3.1 KiB
C++

// ============================================================================
// GAME LAUNCHER HEADER
// ============================================================================
// Menu system for selecting and launching games
#ifndef GAME_LAUNCHER_H
#define GAME_LAUNCHER_H
#include <stdint.h>
#include <vector>
#include <functional>
#include "input_event.h"
#include "game.h"
// Forward declarations
class LowLevelRenderer;
class LowLevelGUI;
class InputManager;
/**
* @brief Game entry in launcher menu
*/
struct GameEntry {
const char* name; // Display name
const char* description; // Short description
std::function<Game*(uint16_t, uint16_t, LowLevelRenderer*, LowLevelGUI*, InputManager*)> factory; // Factory function
};
/**
* @brief Game Launcher - Menu system for game selection
*
* Displays a list of available games and allows selection via:
* - Touch: Tap on game name
* - Buttons: KEY0 to navigate, KEY1 to select
*
* Returns the selected game instance for the main loop to run.
*/
class GameLauncher {
public:
/**
* @brief Construct GameLauncher
* @param width Display width in pixels
* @param height Display height in pixels
* @param renderer Pointer to low-level rendering interface
* @param gui Pointer to GUI drawing primitives
* @param input_manager Pointer to input manager for capability queries
*/
GameLauncher(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager);
/**
* @brief Register a game in the launcher
* @param name Game display name
* @param description Short description
* @param factory Function or lambda to create game instance
*/
void register_game(const char* name, const char* description,
std::function<Game*(uint16_t, uint16_t, LowLevelRenderer*, LowLevelGUI*, InputManager*)> factory);
/**
* @brief Draw the launcher menu
*/
void draw();
/**
* @brief Process input event in launcher
* @param event Input event from InputManager
* @return true if a game was selected (check get_selected_game())
*/
bool update(const InputEvent& event);
/**
* @brief Get the currently selected game instance
* @return Pointer to selected game, or nullptr if none selected
*/
Game* get_selected_game();
/**
* @brief Reset launcher to show menu again
*/
void reset();
/**
* @brief Check if a game is currently selected
* @return true if game selected, false if in menu
*/
bool is_game_selected() const { return selected_game != nullptr; }
private:
uint16_t width;
uint16_t height;
LowLevelRenderer* renderer;
LowLevelGUI* gui;
InputManager* input_manager;
std::vector<GameEntry> games;
int selected_index; // Currently highlighted game
Game* selected_game; // Currently running game (nullptr = in menu)
// Menu layout constants
static const int MENU_Y_START = 60;
static const int MENU_ITEM_HEIGHT = 40;
static const int MENU_PADDING = 10;
};
#endif // GAME_LAUNCHER_H