feat: add Pocket Dungeon game prototype
Main / Build (BookPlayer) (push) Has been cancelled
Main / Build (Brainfuck) (push) Has been cancelled
Main / Build (Breakout) (push) Has been cancelled
Main / Build (Calculator) (push) Has been cancelled
Main / Build (Diceware) (push) Has been cancelled
Main / Build (EpubReader) (push) Has been cancelled
Main / Build (GPIO) (push) Has been cancelled
Main / Build (GraphicsDemo) (push) Has been cancelled
Main / Build (HelloWorld) (push) Has been cancelled
Main / Build (M5UnitTest) (push) Has been cancelled
Main / Build (Magic8Ball) (push) Has been cancelled
Main / Build (MediaKeys) (push) Has been cancelled
Main / Build (MystifyDemo) (push) Has been cancelled
Main / Build (SerialConsole) (push) Has been cancelled
Main / Build (Snake) (push) Has been cancelled
Main / Build (TamaTac) (push) Has been cancelled
Main / Build (TodoList) (push) Has been cancelled
Main / Build (TwoEleven) (push) Has been cancelled
Main / Bundle (push) Has been cancelled

This commit is contained in:
aeroreyna
2026-07-16 22:31:55 -04:00
parent 214287193e
commit d976595879
23 changed files with 862 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
#include "GameKitDraw.h"
namespace GameKit {
lv_obj_t* makePanel(lv_obj_t* parent, lv_color_t color, uint8_t radius) {
lv_obj_t* obj = lv_obj_create(parent);
lv_obj_set_style_bg_color(obj, color, LV_PART_MAIN);
lv_obj_set_style_border_width(obj, 0, LV_PART_MAIN);
lv_obj_set_style_radius(obj, radius, LV_PART_MAIN);
lv_obj_set_style_pad_all(obj, 0, LV_PART_MAIN);
lv_obj_remove_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
return obj;
}
lv_obj_t* makeCell(lv_obj_t* parent, uint16_t size, lv_color_t color, uint8_t radius) {
lv_obj_t* obj = makePanel(parent, color, radius);
lv_obj_set_size(obj, size, size);
return obj;
}
lv_obj_t* makeLabel(lv_obj_t* parent, const char* text, lv_color_t color) {
lv_obj_t* label = lv_label_create(parent);
lv_label_set_text(label, text);
lv_obj_set_style_text_color(label, color, LV_PART_MAIN);
return label;
}
void setCell(lv_obj_t* obj, int x, int y, uint16_t cellPx) {
lv_obj_set_pos(obj, x * cellPx, y * cellPx);
}
} // namespace GameKit
+16
View File
@@ -0,0 +1,16 @@
#include "GameKitGrid.h"
namespace GameKit {
lv_point_t gridToPx(const GridSpec& grid, GridPos pos) {
return lv_point_t {
static_cast<lv_coord_t>(grid.originX + pos.x * grid.cellPx),
static_cast<lv_coord_t>(grid.originY + pos.y * grid.cellPx)
};
}
bool gridContains(const GridSpec& grid, GridPos pos) {
return pos.x >= 0 && pos.y >= 0 && pos.x < grid.cols && pos.y < grid.rows;
}
} // namespace GameKit
+84
View File
@@ -0,0 +1,84 @@
#include "GameKitInput.h"
#include <tt_lvgl_keyboard.h>
namespace GameKit {
InputKind keyToInput(uint32_t key) {
switch (key) {
case LV_KEY_UP: return InputKind::Up;
case LV_KEY_DOWN: return InputKind::Down;
case LV_KEY_LEFT: return InputKind::Left;
case LV_KEY_RIGHT: return InputKind::Right;
case LV_KEY_ENTER: return InputKind::Confirm;
case LV_KEY_ESC: return InputKind::Cancel;
default: break;
}
if (key == 'w' || key == 'W') return InputKind::Up;
if (key == 's' || key == 'S') return InputKind::Down;
if (key == 'a' || key == 'A') return InputKind::Left;
if (key == 'd' || key == 'D') return InputKind::Right;
if (key == 'q' || key == 'Q') return InputKind::Cancel;
return InputKind::Unknown;
}
InputKind gestureToInput(lv_dir_t dir) {
if (dir & LV_DIR_TOP) return InputKind::Up;
if (dir & LV_DIR_BOTTOM) return InputKind::Down;
if (dir & LV_DIR_LEFT) return InputKind::Left;
if (dir & LV_DIR_RIGHT) return InputKind::Right;
return InputKind::Unknown;
}
InputKind pointToQuadrant(lv_obj_t* obj, lv_point_t point) {
const lv_coord_t w = lv_obj_get_width(obj);
const lv_coord_t h = lv_obj_get_height(obj);
const lv_coord_t cx = w / 2;
const lv_coord_t cy = h / 2;
const lv_coord_t dx = point.x - cx;
const lv_coord_t dy = point.y - cy;
if (LV_ABS(dx) > LV_ABS(dy)) return dx < 0 ? InputKind::Left : InputKind::Right;
return dy < 0 ? InputKind::Up : InputKind::Down;
}
static void inputEvent(lv_event_t* e) {
auto* scene = static_cast<Scene*>(lv_event_get_user_data(e));
if (scene == nullptr) return;
InputEvent input;
const lv_event_code_t code = lv_event_get_code(e);
lv_obj_t* target = lv_event_get_target_obj(e);
if (code == LV_EVENT_KEY) {
input.kind = keyToInput(lv_event_get_key(e));
} else if (code == LV_EVENT_GESTURE) {
input.kind = gestureToInput(lv_indev_get_gesture_dir(lv_indev_active()));
} else if (code == LV_EVENT_CLICKED) {
lv_indev_t* indev = lv_indev_active();
if (indev) {
lv_indev_get_point(indev, &input.point);
lv_area_t coords;
lv_obj_get_coords(target, &coords);
input.point.x -= coords.x1;
input.point.y -= coords.y1;
input.kind = pointToQuadrant(target, input.point);
} else {
input.kind = InputKind::Confirm;
}
}
if (input.kind != InputKind::Unknown) scene->onInput(input);
}
void attachInput(lv_obj_t* target, Scene* scene) {
lv_obj_add_flag(target, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_event_cb(target, inputEvent, LV_EVENT_KEY, scene);
lv_obj_add_event_cb(target, inputEvent, LV_EVENT_GESTURE, scene);
lv_obj_add_event_cb(target, inputEvent, LV_EVENT_CLICKED, scene);
if (tt_lvgl_hardware_keyboard_is_available()) {
lv_group_t* group = lv_group_get_default();
if (group) {
lv_group_add_obj(group, target);
lv_group_focus_obj(target);
lv_group_set_editing(group, true);
}
}
}
} // namespace GameKit
+38
View File
@@ -0,0 +1,38 @@
#include "GameKitLoop.h"
namespace GameKit {
Loop::~Loop() { stop(); }
bool Loop::start(uint32_t tickMs, Scene* targetScene) {
stop();
if (targetScene == nullptr || tickMs == 0) return false;
scene = targetScene;
periodMs = tickMs;
lastTickMs = lv_tick_get();
timer = lv_timer_create(onTimer, tickMs, this);
return timer != nullptr;
}
void Loop::stop() {
if (timer != nullptr) {
lv_timer_delete(timer);
timer = nullptr;
}
scene = nullptr;
periodMs = 0;
lastTickMs = 0;
}
void Loop::onTimer(lv_timer_t* timer) {
auto* loop = static_cast<Loop*>(lv_timer_get_user_data(timer));
if (loop == nullptr || loop->scene == nullptr) return;
const uint32_t now = lv_tick_get();
uint32_t dt = loop->periodMs;
if (loop->lastTickMs != 0) dt = now - loop->lastTickMs;
loop->lastTickMs = now;
loop->scene->onTick(Tick { dt, now });
loop->scene->render();
}
} // namespace GameKit