TF-SSD1322-ESP32C3 — Dfrobot Firebeetle2 Esp32S3 simulation

An interactive Dfrobot Firebeetle2 Esp32S3 circuit simulation you can run free in your browser on Velxio, by wsss.

Components

Sketch code

// ============================================================================
// DFRobot FireBeetle 2 ESP32-S3 + ILI9341 SPI LCD (LovyanGFX)
// 256×64 灰阶夜景恐龙游戏
// ============================================================================
#include "config.h"
#include "lgfx_config.h"
#include "state.h"
#include "game.h"
#include "ui.h"
#include "graphics.h"
#include <time.h>

// ============================================================================
// 全局对象
// ============================================================================
LGFX  tft;
uint16_t screenBuf[SCREEN_W * SCREEN_H];

// ============================================================================
// 全局状态
// ============================================================================
float moonXf = MOON_INIT_X;
int   moonX  = MOON_INIT_X;
int   moonY  = MOON_INIT_Y;
int   g_moonPhase = 4;

float    pay = 0.0f;
uint32_t coinCount = 0;
uint32_t lastCoinIndex = 0;
bool     g_timeValid = false;

bool coinActive = false;
int  coinX = SCREEN_W;
int  coinY = COIN_Y_LOW;
bool coinLifted = false;
bool coinJumpTriggered = false;

int      g_cactusPos = SCREEN_W;
int8_t   g_cactusNum = 1;
int      g_cactusX = SCREEN_W;
int      g_cactusW = 0;
int      g_cactusLen = 0;
const uint8_t* g_cactusBmp = nullptr;
bool     g_cactusJumped = false;
bool     g_cactusSmashed = false;
uint8_t  g_cactusSmashStep = 0;

uint8_t jump_flag = 0;
uint8_t g_jumpH = 0;
int8_t  g_jumpDir = 1;
int8_t  g_jumpBmp = -1;
int8_t  g_jumpFallIdx = 0;
bool    g_canDoubleJump = false;

CloudState g_clouds[CLOUD_MAX];
int        g_cloudSpawnTimer = 0;

const int8_t CACTUS_SMASH_TRAJ[CACTUS_SMASH_STEPS] = {
  3, 10, 18, 24, 28, 28, 24, 18, 10, 3, 0, -10, -24, -42, -64
};

// ============================================================================
// 月相计算
// ============================================================================
static int calcMoonPhase() {
  time_t now = time(nullptr);
  if (now < 1000000000) return 4;
  double jd = (double)now / 86400.0 + 2440587.5;
  double phase = fmod((jd - 2451550.1) / 29.530588853, 1.0);
  if (phase < 0) phase += 1.0;
  return (int)(phase * 8.0 + 0.5) % 8;
}

// ============================================================================
// setup
// ============================================================================
void setup() {
  Serial.begin(115200);
  delay(200);
  Serial.println("=== Dino Game Start ==="); 
  Serial.printf("Free heap: %d\n", ESP.getFreeHeap());

  ui_init();

  Serial.println("[TFT] init...");
  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);
  Serial.println("[TFT] OK");

  memset(screenBuf, 0, sizeof(screenBuf));

  randomSeed(esp_random());
  initMoonGlow();   // ★ 预生成月亮光晕 LUT
  initCloudCache();   // ★ 预生成云位图缓存
  initBgStars();           // ★ 背景星星
  initConstellations();    // ★ 星座
  game_init();

  Serial.println("Ready.");
}

// ============================================================================
// loop
// =

More projects by wsss