ST7789LCD_DinoCoin — 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)
// ============================================================================
#include <WiFi.h>
#include <time.h>

#include "config.h"
#include "lgfx_config.h"
#include "state.h"
#include "game.h"
#include "ui.h"
#include "graphics.h"

LGFX tft;
static uint16_t* g_frameBuf = nullptr;
uint16_t* screenBuf = nullptr;

int   g_sunX = SCREEN_W / 2, g_sunY = GROUND_Y - 100;
int   g_moonX = SCREEN_W / 2, g_moonY = GROUND_Y - 100;
bool  g_isDay = true;
float g_lightLx = 0.0f, g_lightLy = -1.0f;

float g_mountainOffset = 0.0f, g_forestOffset = 0.0f;
int   g_moonPhase = 4;

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

bool coinActive = false;
int  coinX = SCREEN_W, coinY = COIN_Y_LOW;
bool coinLifted = false, coinJumpTriggered = false;
float coinSpin = 0.0f;

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

bool  jumpActive = false;
float jumpYf = 0.0f;
float jumpVy = 0.0f;
float jumpGravity = 0.0f;
float jumpTime = 0.0f;
float jumpMaxTime = 0.0f;
uint8_t g_jumpH = 0;

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, -3, -7, -12, -15
};

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;
}

static void updateCelestialBody() {
  static unsigned long lastSec = 0;
  if (millis() - lastSec < 1000 && lastSec != 0) return;
  lastSec = millis();

  struct tm ti;
  int totalSec = 0;
  if (getLocalTime(&ti)) totalSec = ti.tm_hour * 3600 + ti.tm_min * 60 + ti.tm_sec;
  else totalSec = MANUAL_HOUR * 3600 + MANUAL_MIN * 60 + MANUAL_SEC;

  g_isDay = (totalSec >= 21600 && totalSec < 64800);

  if (g_isDay) {
    float t = (float)(totalSec - 21600) / 43200.0f;
    g_sunX = (int)(t * SCREEN_W);
    g_sunY = GROUND_Y - (int)(sinf(t * PI) * (GROUND_Y - 40));
  } else {
    int nightSec = (totalSec >= 64800) ? (totalSec - 64800) : (totalSec + 86400 - 64800);
    float t = (float)nightSec / 43200.0f;
    g_moonX = (int)(t * SCREEN_W);
    g_moonY = GROUND_Y - (int)(sinf(t * PI) * (GROUND_Y - 40));
  }

  float cx = SCREEN_W / 2.0f, cy = SCREEN_H / 2.0f;
  float lx = (g_isDay ? g_sunX : g_moonX) - cx;
  float ly = (g_isDay ? g_sunY : g_moonY) - cy;
  float len = sqrtf(lx * lx + ly * ly);
  if (len > 0.1f) {
    g_lightLx = lx / len;
    g_lightLy = ly / len;
  } else {
    g_lightLx = 0.0f;
    g_lightLy = -1.0f;
  }

  static unsigned long lastMoonCalc =

More projects by wsss