Initial game launcher
This commit is contained in:
60
games/demo_game.cpp
Normal file
60
games/demo_game.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// ============================================================================
|
||||
// DEMO GAME IMPLEMENTATION
|
||||
// ============================================================================
|
||||
// Simple demo game to test the launcher
|
||||
|
||||
#include "demo_game.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
extern Font font_5x5_obj;
|
||||
|
||||
DemoGame::DemoGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui)
|
||||
: Game(width, height, renderer, gui), 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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
30
games/demo_game.h
Normal file
30
games/demo_game.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// ============================================================================
|
||||
// DEMO GAME HEADER
|
||||
// ============================================================================
|
||||
// Simple demo game to test the launcher
|
||||
|
||||
#ifndef DEMO_GAME_H
|
||||
#define DEMO_GAME_H
|
||||
|
||||
#include "game.h"
|
||||
|
||||
/**
|
||||
* @brief Demo Game - Simple test game for launcher
|
||||
*
|
||||
* Displays a welcome message and simple instructions.
|
||||
* Touch or press button to exit back to launcher.
|
||||
*/
|
||||
class DemoGame : public Game {
|
||||
public:
|
||||
DemoGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui);
|
||||
|
||||
void init() override;
|
||||
bool update(const InputEvent& event) override;
|
||||
void draw() override;
|
||||
|
||||
private:
|
||||
int tap_count;
|
||||
bool exit_requested;
|
||||
};
|
||||
|
||||
#endif // DEMO_GAME_H
|
||||
Reference in New Issue
Block a user