Project libraryVolume IV / Moto-trial

Game · Telegram Mini App

Gravity Nostalgy

The moto-trial from push-button phones — now in Telegram.

A remake of the 2004 J2ME game Gravity Defied as a Telegram Mini App. The original physics is rewritten from scratch and matches it bit for bit, the 30 classic tracks are kept untouched, and the server re-runs every record from its replay.

A run on the “Intro” track from the Easy group: the rider climbs the green “3D” ribbon of the track towards the checkered finish flag, the timer shows 0:07.42, with on-screen lean, brake and throttle buttons below.
01A run on “Intro” from the classic tracks, 100cc. Captured in a browser; the input is a solver-bot solution.
Role
Solo project: idea, product and game design; built with AI agents
Status
The playable version is open in any browser; the leaderboard, rewards and the bot work when the game is opened in Telegram
How it’s built
TypeScript and Vite with no framework, Canvas rendering; the server is Supabase: an Edge Function, PostgreSQL, pg_cron
Testing
584 automated tests: a bit-exact check against a golden trace of the original and 530 bot runs re-verified by the server check
140 tracks
10 new ones, 30 original and 100 from fan mods
4 bikes
100cc, 175cc, 220cc and 325cc with the original constants
16 bit-exact scenarios
4 bikes × 4 input sequences, up to 1540 steps
530 bot runs
every track finished on every bike it allows

01 / The idea

That very moto-trial — in Telegram.

Gravity Defied is a 2004 Codebrew Software game for push-button phones: a white screen, a green “3D” ribbon of track, a tiny rider and a timer in the corner. The idea: open the bot and be riding a second later, with the bike behaving exactly as it did then.

Physics 1:1

Nostalgia lives in the feel of the controls. The physics is rewritten in the same arithmetic and matches the original bit for bit.

The classics stay as they are

The 30 original tracks stay forever and unchanged — a tribute. New chapters only ever appear alongside them.

Fair competition

The physics is deterministic: the server re-runs every submitted ride and checks the time down to the step.

02 / How it works

The same bike, down to the last bit.

The original code served as a reference: the logic is rewritten in TypeScript from scratch, with clear names and no allocations in the physics step.

01

16.16 without BigInt

Multiplication and division reproduce the original’s 64-bit arithmetic on plain JavaScript numbers. A test checks them against a reference on 200,000 value pairs — 0 mismatches.

02

Checked against the original

The golden trace comes from the original physics, built separately only for the comparison. 16 scenarios, up to 1540 steps, with crashes and a breakdown: the coordinates of all 6 bodies match to the bit on every step.

03

Rendering “as on the phone”

1 physics unit is 4 pixels, on a 176–320 px screen. Smooth mode anti-aliases and interpolates; pixel mode draws lines pixel by pixel and scales up without smoothing.

04

A run is a replay

Each step records a mask of 4 keys, and repeats are compressed. Time is counted in steps of 20 game ms, so it does not depend on the frame rate. Ghosts are the same replays.

05

The server re-runs it

The check is built from the same source as the game. A run counts only if the finish lands exactly on the last step and the time matches.

06

A solver bot

It searches over inputs for a run that reaches the finish. 530 solutions prove that every track can be finished on every bike it allows; a test re-runs all of them.

Stack TypeScript · Vite · Canvas 2D · Telegram Mini Apps · Supabase (Edge Function, PostgreSQL, RLS, pg_cron) · Vitest · Vercel

03 / Product

140 tracks, stars and a track of the day.

Beginner · Classic · Community

Three track tabs

10 new training tracks, the 30 original tracks in the Easy, Medium and Pro groups, and 100 tracks from fan mods made in 2007–2012: 28 authors, 10 chapters, each track credited with its author and year.

100cc · 175cc · 220cc · 325cc

4 bikes

The original constants. On the classic tracks bikes unlock as in the original — by finishing groups; records are kept separately for each bike.

gold 3 · silver 2 · bronze 1

Medals and stars

Medals are awarded by time. A track counts its best medal across the bikes; the maximum is 420 stars. Plus 33 achievements.

every UTC day

Track of the day

One of the 30 original tracks and a bike, the same for everyone: the choice is computed from the day number. The day’s top 3 earn a reward; for now it is only a record on the server.

world · track · challenge

Leaderboards and ghosts

Overall standings by stars, the top 50 of every track, “Race the leader” against the leader’s ghost, and a challenge to a friend via a link to your run.

private chat only

The bot

Menu, track of the day, profile, top and reminders. In the morning the bot announces the new track of the day to those who allowed it.

04 / Screens

Captured from the live game.

The frames were captured on 21 October 2026 from the live version in a regular browser, outside Telegram, so they show no leaderboard places. The game’s interface is in Russian. The run on “Intro” is a solver-bot solution from the repository, typed in key by key, step by step. Any screenshot opens full size. Swipe sideways

The result screen for the “Intro” track on 100cc: time 0:08.46 with a silver medal, “New record!”, medal thresholds 0:08.30, 0:11.00 and 0:16.60, two of three stars for the track, the “First finish” achievement, and buttons for next, retry, the track leaderboard and the track list.
02Finish: time, medal, thresholds and the track’s stars.
The same moment of the run in pixel graphics: a 176-pixel logical screen, large pixels on the rider and the track, the finish flag, timer 0:07.42.
03The same moment in pixel mode, 176 px screen.
The Classic tab: the 100cc bike is selected and the others are locked; the Easy group lists Intro, Shorty, Slope, Crackle and more, with Intro finished in 0:08.46, silver and two of three stars; the Medium group below.
04Classic: the Easy, Medium and Pro groups as in the original.
The Community tab: a note that these are player tracks from the Gravity Defied mod archive, each with its author and year; the first chapter is locked until Easy is finished; every track shows its author and year, for example 3X1 by d1gger17, 2007.
05Community: every track credited with author and year.
The rider profile: 1 of 140 tracks finished, 2 of 420 stars, 1 of 4 bikes, 1 run, 0 crashes, 0:08.46 of riding time; leaderboard places appear when the game is opened in Telegram.
06Profile: tracks, stars, bikes and stats.
05 / Analysis

The run, the decisions and the market — from the documents.

Business analysis artefacts reconstructed from the repository’s code and documentation (last commit: 28 September 2026). Steps and numbers are checked against the files; paths are in the captions and the “As text” blocks.

  1. 5.1From a run to the leaderboard
  2. 5.2Decision log
  3. 5.3Market research

5.1 · Process in lanes

From a run to the leaderboard

The lanes run top to bottom: client, server, database, the client again and a separate leaderboard request. The time is never taken on trust: the server receives only the step-by-step input and re-runs the ride with the same physics.

  • start
  • step
  • decision
  • result
  • separate request
Diagram: from a run to the leaderboardClient: the player picks a track and rides; a crash restarts the run; at the finish the replay, medal and stars are saved on the device. If the game is opened in Telegram, the client sends the replay with a signature. The server checks the signature, re-runs the ride and counts it only if the finish lands on the last step and the time matches. The database saves the record if it is faster and computes the world place and the place of the day; the client shows them on the result screen. The overall standings by stars are a separate request.CLIENT · GAMESERVER · GD-APIDATABASE · POSTGRESQLCLIENTDATABASEThe player picks a track and a bikeThe run66.7 physics steps per second; eachstep records a 4-key input maskFinish?no: crash → restart, replay from zeroyesReplay, medal and starsinput is RLE-compressed; time is countedin steps of 20 game ms; the record andmedal are saved on the device at onceOpened in Telegram?no → the record stays on the deviceyes → submit: replay + signed initDataCheck the Telegram signatureinitData, HMAC-SHA256 with the bot token,at most a day old; no signature — 401Re-run the ride: verifyRunphysics built from the same source asthe game; the physics version matches;at most 60,000 stepsFinish exactly on the last stepand the time matches?no → “not counted”, with a reasonyesSave if fastergd_record — time and replaygd_daily_run — if it is the trackand bike of the dayCompute the placein the world — from gd_record; of theday — from gd_daily_runResult screen:world place and place of the daySEPARATE: LEADERBOARD BUTTONOverall standings by starsgd_overall: gold 3, silver 2,bronze 1 star per track; the bestmedal across the bikes counts;medal thresholds come from the game
Fig. 5.1

The diagram is simplified: resending after a lost connection, uploading records at sign-in and the message to a challenger are described in “As text”.

Source: src/game/session.ts:71–115 · src/main.ts:278–325 · src/server/core.ts:44–77 · server/gd-api/index.ts:149–222, 273–288 · server/gd-api/verify.js:25

As text 10 steps

Paths are relative to the gravity_nostalgy repository root.

  1. The player picks a track and a bike. The physics runs at a fixed step at the original’s pace — 66.7 steps per second. src/engine/loop.ts:6–48 · src/main.ts:379–390
  2. On every step the replay records a mask of 4 keys (throttle, brake, lean back and forward) and compresses repeats (RLE). The timer starts when the front wheel crosses the start flag. src/game/session.ts:71–98 · src/game/replay.ts
  3. If the head touches the track or the bike “folds”, it is a crash: a restart from the beginning, and the replay is reset. src/game/session.ts:53–59, 79–85, 108–115
  4. Finish: time is counted in steps of 20 game ms; a finish in the middle of a step takes off 10 ms, as in the original. The record, medal and stars are saved on the device at once. src/game/session.ts:100–106 · src/main.ts:278–301 · src/game/format.ts:12–27
  5. Outside Telegram that is the end: the leaderboard needs the game to be opened in Telegram. In Telegram the client sends submit: the track, the bike, the replay and the signed initData. Without a connection the run is queued and sent later. src/main.ts:178–190, 306–325 · src/platform/api.ts:105–113
  6. The server checks the initData signature (HMAC-SHA256 with the bot token, at most a day old) and creates or updates the player. Without a signature submit is refused with 401. server/gd-api/index.ts:149–175, 452–457 · server/gd-api/verify.js:25
  7. verifyRun re-runs the ride with physics from the same source (core.js is built from src/) and counts it only if the finish lands exactly on the last input step and the time matches. src/server/core.ts:44–77
  8. If the time beats the previous one, gd_record stores the time and the replay — the source of the “ghosts” later on. If it is the track and bike of the day, the same goes into gd_daily_run. server/gd-api/index.ts:192–216, 273–288
  9. The reply: the world place on this track and bike, and the place of the day. If the run answered a challenge and beat the challenger’s time, the bot messages the challenger. server/gd-api/index.ts:185–190, 217–236
  10. The leaderboard is a separate overall request: the SQL function gd_overall sums the stars (gold 3, silver 2, bronze 1 per track; the best medal across the bikes). Ties go to more original tracks, then to a lower total time. The medal thresholds are passed in from the game code. server/gd-api/index.ts:69–71 · src/game/levels/campaign.ts:304–311 · docs/SERVER.md

Not drawn

  • On sign-in through Telegram the client requests the profile, merges records with the local ones (keeping the best) and uploads those the server lacks. src/main.ts:124–190 · docs/SERVER.md
  • Track of the day results: the SQL function gd_finalize_daily gives the top 3 of each past day a record in gd_reward with the status earned; it is called lazily, at most once a minute. server/gd-api/index.ts:296–302 · docs/SERVER.md

5.2 · Decision log

Problem → decision → why

Six decisions that the project memo says must not be revisited without the owner. The wording is shortened; the reasons come from the same documents.

  1. Problem

    Nostalgia rests on the feel of the controls: a player will notice a different bike at once.

    Decision

    Bit-exact original physicsFixed-point 16.16 and the original order of operations; any physics change must pass the comparison test.

    Why

    That very bike — plus determinism: the same input gives the same time on any device, so the server can re-check any record.

  2. Problem

    The name, sprites and 30 original tracks belong to Codebrew Software.

    Decision

    The classics stay forever and unchangedNew chapters only alongside them. Nothing is sold on the classic tracks; monetisation and prizes only on the project’s own tracks.

    Why

    A tribute to the classics — and the project’s main legal risk: the rights stand even if the game has not been sold for years.

  3. Problem

    The design doc listed five leaderboard schemes: per track, stars, a weekly cup, a chat leaderboard, tournaments.

    Decision

    World standings by starsThe chat leaderboard is removed. Gold is 3 stars, silver 2, bronze 1; a track counts its best medal across the bikes.

    Why

    Stars fold all tracks and bikes into one number. Per-track tables remain; the server remembers which chat a game was launched from, but the game does not show it.

  4. Problem

    The bot needs a channel to bring players back.

    Decision

    The bot talks only in private chatMenu, track of the day, profile, top and reminders; the bot does not work in groups.

    Why

    The bot can write first only to those who pressed /start or allowed it in the game. The morning track-of-the-day message goes only to them, at most once a day.

  5. Problem

    The day’s top 3 earn a reward — what should it turn into?

    Decision

    No own token and no play-to-earnRewards accumulate as a server record with the status “earned”; exchange is “later”, for now it is only a record.

    Why

    Hamster Kombat, Notcoin, Catizen and Blum saw their tokens fall 75–95% and their audiences 85–95% after the airdrop. Status and cosmetics are safer, legally too.

  6. Problem

    Stars once diverged: “I have 18, the leaderboard says 5” — the medal thresholds in the game and on the server differed.

    Decision

    Add new things seamlesslyPlayers’ progress, records and stars do not change. Changes to physics, tracks or medals ship only with a server core rebuilt from the same source.

    Why

    The game and the leaderboard count stars by the same thresholds, and old records stay valid.

Source: CLAUDE.md, “Owner decisions” 1–6 and “Server deployment” · docs/GDD.md §1, §2, §9 · docs/GROWTH.md §0 · docs/SERVER.md

5.3 · Research

The Telegram mini-game market

Before the growth plan the project gathered open data on Telegram mini-games and the genre. These are market benchmarks from other people’s sources, not results of Gravity Nostalgy.

Research · open sources, September 2026
15–20% / 8–10%
mini-app retention on day 1 and day 7; for mobile games “good” is D1 ≈ 27%ad network data
up to 5%
paying users with an ARPPU of $40–60 — an upper boundPlayDeck, App2Top interview
−75…95%
token prices of Hamster Kombat, Notcoin, Catizen, Blum after the airdrop; audiences −85…95%Bankless Times, CCN
not found
Gravity Defied in Telegram: the niche is freesearch within the research

What went into the plan: no “energy” or attempt limits, no own token; paid promotion only after D1 ≥ 20% and D7 ≥ 8%. D1 and D7 retention is already computed by the SQL function gd_stats; there are no player numbers on this page.

Source: docs/GROWTH.md §0–2 and §6, with the list of sources at the end of the file; docs/SERVER.md (gd_stats)

Based on the repository’s code and documentation (last commit: 28 September 2026); tests run on 21 October 2026: 584 of 584 passing. The diagram is simplified; the full version is in the “As text” block.

The classic tracks are open in a regular browser — no Telegram needed.

Play in the browser Open in Telegram