running version of Runner Game with FlipDot-Emu and GameController

This commit is contained in:
Marcel Walter
2025-10-04 21:02:39 +02:00
parent 869769dfc4
commit 4ad8e72a11
11 changed files with 972 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <Arduino.h>
#include <Adafruit_GFX.h>
class FlipDotDrv
{
private:
static constexpr uint8_t templateFrameStart {0x02};
static constexpr uint8_t templateFrameAddressByte1 {'1'};
static constexpr uint8_t templateFrameAddressByte2 {'0'};
uint8_t FrameResolution[2] {};
uint8_t *FrameData {nullptr};
static constexpr uint8_t templateFrameEnd {0x03};
uint8_t FrameCrc[2] {};
uint32_t width;
uint32_t height;
uint8_t address;
uint8_t *buffer {nullptr};
uint16_t FrameDataLength;
uint16_t bufferLength;
public:
FlipDotDrv(uint8_t width, uint8_t height, uint8_t address);
~FlipDotDrv();
void sendRaw(const uint8_t* bmp, uint16_t length);
void sendCanvas(const GFXcanvas1 * canv);
};
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include <Arduino.h>
class GameRect {
private:
int16_t x;
int16_t y;
int16_t w;
int16_t h;
public:
GameRect(int16_t x = 0, int16_t y = 0, int16_t w = 0, int16_t h = 0)
: x(x), y(y), w(w), h(h) {}
// Getter
int16_t getX() const { return x; }
int16_t getY() const { return y; }
int16_t getWidth() const { return w; }
int16_t getHeight() const { return h; }
// Setter
void setX(int16_t nx) { x = nx; }
void setY(int16_t ny) { y = ny; }
void setWidth(int16_t nw) { w = nw; }
void setHeight(int16_t nh) { h = nh; }
void set(int16_t nx, int16_t ny, int16_t nw, int16_t nh) {
x = nx; y = ny; w = nw; h = nh;
}
// Kollisionserkennung (wie pygame.Rect.colliderect)
bool collideRect(const GameRect& other) const {
return !(x + w <= other.x || // links von other
x >= other.x + other.w || // rechts von other
y + h <= other.y || // über other
y >= other.y + other.h); // unter other
}
// Punkt-in-Rechteck Test
bool contains(int16_t px, int16_t py) const {
return (px >= x && px < x + w && py >= y && py < y + h);
}
};
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <Arduino.h>
class ITrigger
{
public:
ITrigger(/* args */) = default;
~ITrigger() = default;
virtual void printText(String text) = 0;
virtual void printOpen() = 0;
virtual void printClose() = 0;
};
+39
View File
@@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include <Arduino.h>
#include <UniversalTelegramBot.h>
#include <WiFiClientSecure.h>
#include "ITrigger.h"
class Telegram
{
private:
static const char *BOT_TOKEN;
static const unsigned long BOT_MTBS; // mean time between scan messages
unsigned long bot_lasttime; // last time messages' scan has been done
ITrigger &trigger;
WiFiClientSecure &secured_client;
UniversalTelegramBot bot;
void handleNewMessages(int numNewMessages);
public:
Telegram(WiFiClientSecure &sec_client, ITrigger &trig);
~Telegram();
void init();
void cyclic(unsigned long now);
};