Files
basic1/games/demo_game.cpp

66 lines
2.0 KiB
C++

// ============================================================================
// DEMO GAME IMPLEMENTATION
// ============================================================================
// Simple demo game to test the launcher
#include "demo_game.h"
#include "input_manager.h"
#include <stdio.h>
#include <string.h>
extern Font font_5x5_obj;
DemoGame::DemoGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager)
: Game(width, height, renderer, gui, input_manager), tap_count(0), exit_requested(false) {
}
void DemoGame::init() {
tap_count = 0;
exit_requested = false;
}
bool DemoGame::update(const InputEvent& event) {
bool needs_refresh = false;
if (event.type == INPUT_TOUCH_DOWN || event.type == INPUT_BUTTON_0 || event.type == INPUT_BUTTON_1) {
tap_count++;
needs_refresh = true;
// After 3 taps, signal to exit
if (tap_count >= 3) {
exit_requested = true;
}
}
return needs_refresh;
}
void DemoGame::draw() {
// Draw main window
gui->draw_new_window(10, 10, width - 20, height - 20, "Demo Game");
renderer->set_font(&font_5x5_obj);
// Draw centered message
int y = height / 2 - 40;
renderer->draw_string(width/2 - 60, y, "Demo Game!", true);
renderer->draw_string(width/2 - 80, y + 20, "This is a placeholder", true);
// Show tap count
char count_text[40];
snprintf(count_text, sizeof(count_text), "Taps: %d", tap_count);
renderer->draw_string(width/2 - 40, y + 50, count_text, true);
// Instructions
if (tap_count < 3) {
if (input_manager->has_buttons()) {
renderer->draw_string(width/2 - 80, y + 80, "Tap or press 3 times", true);
} else {
renderer->draw_string(width/2 - 80, y + 80, "Tap 3 times to exit", true);
}
} else {
renderer->draw_string(width/2 - 70, y + 80, "Exiting to menu...", true);
}
}