ESP32 OLED Chrome Dino Game
Introduction
A simple dino running game where the player jumps over obstacles.
Game Code
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define BTN_JUMP 18
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int dino_y = 50, dino_dy = 0;
int obstacle_x = 128;
void setup() {
pinMode(BTN_JUMP, INPUT_PULLUP);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
void loop() {
display.clearDisplay();
// Draw dino
display.fillRect(10, dino_y, 10, 10, WHITE);
// Draw obstacle
display.fillRect(obstacle_x, 50, 10, 10, WHITE);
// Move obstacle
obstacle_x -= 3;
if (obstacle_x < 0) obstacle_x = SCREEN_WIDTH;
// Dino jump
if (digitalRead(BTN_JUMP) == LOW && dino_y == 50) dino_dy = -5;
dino_y += dino_dy;
if (dino_y < 30) dino_dy = 3;
if (dino_y >= 50) dino_y = 50;
display.display();
delay(50);
Conclusion
This game demonstrates how to use ESP32 and an OLED display for interactive graphics and
gameplay. You can enhance it by adding more features like scoring, sound effects, and difficulty
levels.