🌐 US-Proxy
id="body-softwares" class="foundation-grid action-show controller-softwares engine-home">

KingMoth 🦋⚔️ — Your sweat is the power source

Frankenstein track. We stitched on-device computer vision, AR, a deterministic 2D fighting-game engine, server-authoritative netcode, a habit-learning game AI and generative-AI assets into one creature: an exergame where every verified squat becomes your Fighter's strength.

Inspiration

Most fitness apps reward you with streaks and badges, and most mobile fighting games reward you for grinding the game itself. We wanted to connect the two, so that the strength you build in real life becomes the strength of your Fighter. If you want a tougher Fighter in KingMoth, you do squats.

The moth's life cycle shaped the core idea. A caterpillar spends its life eating and storing energy. Then it transforms. Adult moths such as the atlas moth can't eat at all, so they live entirely on the energy they stored as caterpillars, and their whole adult life lasts only as long as that energy does. We loved the idea of a creature that is a living store of time and energy.

That became KingMoth's energy system. Your workouts are the caterpillar stage: every Rep builds energy, and an AR caterpillar grows on your camera feed as you train. In a fight, your Fighter lives on that stored energy. Every punch, kick and special spends it, and you can't refill it in the middle of a match. To get stronger, you have to go back and train.

The moth theme also gave us the look. Atlas, luna and death's-head moths have bold wing patterns and strong silhouettes, which suit fighting-game characters.

The Frankenstein: what we stitched together

These parts were never meant to share a body:

Body part Technology Its job
👁️ Eyes On-device computer vision: MediaPipe Pose Landmarker with a CameraX front-camera feed Counts only clean Reps from joint angles. The video never leaves the phone.
🐛 Skin Augmented reality: a SceneView 3D caterpillar .glb over the live camera A caterpillar that grows with the energy your Reps earn
🧠 Brain Adaptive game AI: an n-gram habit model plus simulation-based lookahead A computer opponent that learns how you fight during the match
❤️ Heart Deterministic lockstep engine: pure Kotlin, fixed 30 Hz, frame data Exactly the same fight on the phone and the server
🦴 Spine Server-authoritative netcode: Ktor WebSockets on Google Cloud Run Online and friend matches that can't be cheated
🩸 Blood Cloud data layer: PostgreSQL on Cloud SQL, Secret Manager, a least-privilege IAM account A workout ledger that is the single source of truth for your stats
🎨 Face Generative-AI asset pipeline: spec-precise prompts for sprite sheets, the icon, sound effects and music HD fighter animations, 23 sound effects and 3 music loops

What it does

Fitness first:

  • Camera-verified workouts with real-time form checks for ten exercises: push-ups, squats, planks, lunges, burpees and more.
  • A daily dashboard and goals for Reps and water. The app opens on fitness, not on the game.
  • Privacy by design. Pose tracking runs entirely on the device. Only Rep records go to the server.

Your sweat powers the game:

  • Stats from exercise. Leg exercises build health. Push-ups and burpees build attack. Planks and wall sits build armor. Every Rep adds energy.
  • Per-round energy. Your energy pool is split across the rounds, and every attack spends it. Run out and you have to train again.

A real fighting game:

  • Fighters and moves: four moth Fighters with signature specials, including real projectiles you can jump over.
  • Movement: dashes, diagonal jumps over the opponent, crouch-walking and blocking.
  • Modes: Practice against the AI, online ranked play with ratings, and friend matches through a 6-character code you share straight from the app.
  • Dynamic theming: the Fighter you pick during setup sets the colors and mascot across the whole app.
  • Atmosphere: fullscreen immersive mode, arcade-style selection screens, music for menus, fights and workouts, and sound effects for every hit, block and KO.

How we built it

A deterministic game engine (Kotlin Multiplatform-style core module)

  • Pure and deterministic: no clock reads and no random calls inside the engine. Seeds and time enter as parameters, so the same inputs always give the same fight.
  • Frame data: startup, active and recovery frames, high, mid and low hit levels, block reduction and armor.
  • Physics-light projectiles: each shot flies at its own speed, hits on arrival and can be dodged.
  • One codebase on client and server. The server runs the authoritative engine, re-derives every stat from the workout ledger, and rejects any stats a client sends. That is anti-cheat by architecture.

A game AI that adapts to you

  1. Behavioral modeling. An n-gram (Markov) model learns which move you tend to make after each move, separately for each distance band.
  2. Simulation-based lookahead. Several times a second the AI plays each of its options forward with the real engine against your most likely responses, then picks the best risk-reward trade.
  3. Human-likeness:
    • its reaction times vary for every attack
    • it sometimes makes a deliberate mistake
    • its risk-taking changes with how the fight is going
    • it avoids repeating the same plan

Cloud-native backend

  • Containers and data: Ktor on Cloud Run, with a Cloud SQL Auth Proxy sidecar and Flyway migrations.
  • Secrets: stored in Secret Manager, read by a dedicated service account that can access only its own secrets. No secret is ever in the code or the app.
  • Gemini on the server: a Nutrition_Proxy for food search, so the API key never ships in the app.

Config as code

  • Balance in JSON: every balance value lives in validated JSON, including damage, energy costs, block percentages, AI behavior and goal ranges.
  • Fail-fast: startup stops with a clear error if any file is invalid.
  • No fallback defaults in the code.

🧪 How we used Kiro

Kiro was the operating table where this creature was stitched together.

  • Spec-driven development. The whole product began as a Kiro spec in .kiro/specs/kingmoth/, with requirements, a design with correctness properties, and a task plan. The engine, the stat converter and the server were built from it task by task.
  • Bugfix specs with a test-first loop. When play-testing showed that energy dropped to zero in round 2, Kiro's bugfix workflow (.kiro/specs/fight-energy-actions-fix/) worked in this order:
    1. It wrote bug-condition exploration tests that had to fail on the broken code, which proved the bug existed.
    2. It wrote preservation property tests that locked in the behavior that must not change.
    3. It implemented the fix and re-ran both sets of tests.
  • Steering docs as guardrails. Four steering files in .kiro/steering/ held Kiro to our architecture, coding style and tech stack throughout:
    • Fitness modules never depend on game modules.
    • The server is the authority.
    • The engine stays deterministic.
    • Balance lives in config files.
    • A real-implementations-only rule: no mocks, no fake data and no placeholders, ever.
  • Property-based testing. The steering docs require Kotest property tests with 100+ iterations, so the engine's rules are checked across thousands of random fights, not a few hand-picked cases.
  • Agentic sub-agents. Kiro split the work across parallel sub-agents, for example one mapping the codebase while another built the core engine fix, and one handling the protocol and server while another wired the touch and keyboard controls.
  • Simulation-driven vibe tuning. For game feel, we vibe-coded with Kiro in a tight loop: play on the phone, describe what felt wrong, and let Kiro reproduce it as a headless engine simulation before changing anything. That loop found three of the bugs below:
    • "blocking doesn't work" (the AI's special spam)
    • one-hit KOs (health was too low)
    • projectiles passing through you

Challenges we ran into

  • Energy at zero in round 2. One pool for the whole match let players spend everything in round 1. We split it into a share per round and added a clean exit when both Fighters are drained.
  • Blocking felt useless. The block worked, but the AI threw a guard-breaking special every second. Simulations showed a blocking player died in 5 seconds. With attack cooldowns, that player survives the full round.
  • The skull went through you. The special dealt damage instantly while the skull was only an animation. We turned projectiles into real objects in the engine that hit on arrival and can be dodged.
  • One-hit KOs. New players had about 8 health. We rescaled the conversion table about 10× for health and energy.
  • Making the AI fair but sharp. The lookahead search had to fit inside a 33 ms frame budget, and it needed its cooldowns, deliberate mistakes and reaction delays to feel human instead of perfect.

Accomplishments that we're proud of

  • One deterministic engine running on both the phone and the cloud, which makes online play cheat-proof by design.
  • A game AI that learns your habits inside a single match and plans ahead with the real game rules.
  • Private, camera-verified fitness. Your video never leaves the phone.
  • Friend matches by code, shared from a share button.
  • A real-implementations-only codebase, with no mocks and no placeholder art, enforced by Kiro steering.

What we learned

  • Spec-driven development pays off when you add features fast. The spec and steering kept a large codebase consistent over many iterations.
  • Balance is measurement. A ten-line headless simulation beat guessing every time.
  • Visual effects and game rules have to match. If it looks like a projectile, players expect it to stop when it hits them.
  • Purity is a superpower. A deterministic engine gave us server authority, replays and an AI that can look ahead.

What's next for KingMoth

  • Campaign mode: side-scrolling Stages against Enemy_Waves, powered by each day's workouts.
  • More activity: GPS run tracking, Health Connect steps and water, and food logging that uses the Gemini nutrition proxy and barcode scanning.
  • More moths: Cinder Cecropia and new Fighters, plus announcer voice lines.
  • AI difficulty levels and tournaments with a leaderboard screen.
  • Horizontal scaling: shared matchmaking state, so the server can run across instances.

Built with

kiro kotlin jetpack-compose android mediapipe camerax sceneview augmented-reality computer-vision ktor websockets google-cloud-run cloud-sql postgresql secret-manager gemini hilt room kotest property-based-testing game-ai

Built With

Share this project:

Updates

Submission history