Imagine waiting 60 seconds for a game to load in 2025. That's how Galaxy Guardian started. Today, it loads in under 3 seconds. This is the story of how we used AI to build a space shooter, made critical mistakes, learned hard lessons, and emerged with a game that's both technically innovative and actually playable.


The Challenge

Galaxy Guardian is the 14th game in the InstantGames.top collection, and it represents something different: our first deep dive into AI-generated game assets. Built with React 19, TypeScript, and Vite, this classic vertical-scrolling space shooter combines retro arcade gameplay with cutting-edge AI technology.

But here's the thing about innovation: the first version is rarely the right version.

Project Quick Facts

  • Game Type: Vertical-scrolling space shooter (Galaga-style)
  • Tech Stack: React 19 + TypeScript + Vite
  • AI Tool: Gemini Nano Banana Pro
  • Development Time: 3 weeks (including the pivot)
  • Lines of Code: ~2,500

The AI-First Vision

Why AI-Generated Assets?

When we started Galaxy Guardian, we had three ambitious goals:

  1. Rapid prototyping: Build a complete game without hiring artists
  2. Technical showcase: Demonstrate what's possible with modern AI tools
  3. Unique experience: Give every player their own AI-generated visuals

Gemini Nano Banana Pro had just been released, and its image generation capabilities were impressive. Why not generate all our game assets—spaceships, enemies, backgrounds, explosions—on the fly?

"What if every player's game looked slightly different? What if the AI generated assets in real-time based on their preferences?"

— Initial project vision, November 2025

The Original Architecture

Our first version worked like this:

  1. Player visits the game page
  2. Frontend requests API key (from player or environment)
  3. Generate all game assets using Gemini AI
  4. Load assets into Canvas
  5. Start the game

On paper, it was elegant. In practice, it was a disaster.


The Reality Check

Performance Problems Exposed

The first time we tested the game with real users, the feedback was immediate and brutal:

  • Load time: 30-60 seconds on first play
  • API costs: $0.15-0.25 per gameplay session
  • Failure rate: 15% (network issues, API timeouts)
  • User retention: 60% bounced before game started

Sixty seconds is an eternity in web gaming. Players expect instant gratification. We were delivering delayed frustration.

Real-Time Generation Performance

Metric Target Reality Status
Load Time < 5s 30-60s ❌ 10x slower
API Cost/Play $0.00 $0.15-0.25 ❌ Unsustainable
Success Rate > 99% ~85% ❌ Too unreliable
Player Retention > 80% ~40% ❌ Massive bounce

The Cost Analysis

Let's do the math. If we got 1,000 players per month:

  • API calls: 1,000 × $0.20 = $200/month
  • With 40% retention, only 400 actually played
  • Effective cost per player: $0.50

For a free browser game with no monetization, this was a non-starter.


The Pivot: From Runtime to Build Time

The Insight That Changed Everything

During a code review, someone asked a simple question: "Why generate these assets every time? They don't actually change."

It hit us immediately. We didn't need runtime AI generation. We needed build-time AI generation.

"Move the AI generation from the player's browser to the developer's laptop. Generate once, use everywhere."

— The pivot moment

The New Architecture

We rebuilt the asset pipeline:

// generate-assets.js - Run once during development
import { GoogleGenAI } from '@google/genai';

const genAI = new GoogleGenAI(process.env.GEMINI_API_KEY);

async function generateGameAssets() {
  const assets = [
    {
      name: 'player-ship',
      prompt: 'Futuristic blue spaceship, top-down view, sleek design, game sprite'
    },
    {
      name: 'enemy-scout',
      prompt: 'Alien scout ship, red and menacing, top-down game sprite'
    },
    {
      name: 'enemy-fighter',
      prompt: 'Advanced alien fighter, purple energy weapons, game sprite'
    },
    {
      name: 'enemy-boss',
      prompt: 'Massive alien mothership, intimidating, final boss design'
    },
    {
      name: 'background',
      prompt: 'Deep space nebula, stars, cosmic dust, game background'
    }
  ];

  for (const asset of assets) {
    console.log(`Generating ${asset.name}...`);
    const result = await genAI.generateImage(asset.prompt);
    await saveImageToFile(result, `assets/${asset.name}.png`);
  }

  console.log('✅ All assets generated!');
}

generateGameAssets();

The New Workflow

  1. Development Phase:
    • Run npm run generate-assets once
    • AI generates all game graphics
    • Assets saved to assets/ folder
  2. Build Phase:
    • Vite bundles static assets
    • Optimizes and compresses images
    • Generates production bundle
  3. Runtime:
    • Player visits game
    • Loads pre-generated assets (instant!)
    • Starts playing immediately

Immediate Benefits

  • Load time: 60s → 2-3s (95% improvement)
  • 💰 Runtime cost: $0.20/play → $0.00 (100% reduction)
  • 🎯 Reliability: 85% → 99.9% (network-independent)
  • 🎮 User experience: Instant play, no waiting

Game Architecture

Core Game Systems

With the asset pipeline solved, we could focus on making the game fun. Galaxy Guardian features:

1. Canvas Rendering Engine

// GameCanvas.tsx - Core rendering loop
const GameCanvas: React.FC = () => {
  const canvasRef = useRef<HTMLCanvasElement>(null);

  useEffect(() => {
    const canvas = canvasRef.current;
    if (!canvas) return;

    const ctx = canvas.getContext('2d')!;
    let animationId: number;

    const gameLoop = () => {
      // Clear canvas
      ctx.clearRect(0, 0, canvas.width, canvas.height);

      // Update game state
      updatePlayer();
      updateEnemies();
      updateBullets();
      checkCollisions();

      // Render everything
      renderBackground(ctx);
      renderPlayer(ctx);
      renderEnemies(ctx);
      renderBullets(ctx);
      renderUI(ctx);

      // Next frame
      animationId = requestAnimationFrame(gameLoop);
    };

    gameLoop();

    return () => cancelAnimationFrame(animationId);
  }, []);

  return <canvas ref={canvasRef} width={800} height={600} />;
};

2. Weapon Upgrade System (7 Levels)

  • Level 1: Single shot (starter weapon)
  • Level 2: Dual shot (parallel bullets)
  • Level 3: Triple spread (wide coverage)
  • Level 4: Rapid fire (2x fire rate)
  • Level 5: Plasma cannon (piercing shots)
  • Level 6: Missile system (homing projectiles)
  • Level 7: Ultimate weapon (screen-clearing laser)

3. Progressive Difficulty System

// Difficulty scaling logic
const calculateDifficulty = (wave: number) => {
  return {
    enemySpeed: 2 + (wave * 0.3),
    enemyHealth: 1 + Math.floor(wave / 3),
    spawnRate: Math.max(500 - (wave * 30), 200),
    enemyCount: 3 + Math.floor(wave / 2),
    bossEvery: 5 waves
  };
};

4. Boss Battle System

Every 5 waves, players face a boss enemy with:

  • 10x health of regular enemies
  • Unique attack patterns
  • Multiple phases
  • Screen-filling sprite
  • Epic music transition

React + TypeScript Architecture

We chose React for its component-based architecture and excellent TypeScript support:

galaxy-guardian/
├── App.tsx                    # Main game orchestrator
├── components/
│   ├── GameCanvas.tsx         # Core rendering engine
│   ├── MainMenu.tsx           # Start screen
│   ├── GameOver.tsx           # End screen with stats
│   └── HUD.tsx                # Score, lives, weapon level
├── services/
│   ├── assetLoader.ts         # Static asset management
│   ├── audioService.ts        # Sound effects & music
│   ├── collisionDetection.ts # Physics engine
│   └── particleSystem.ts     # Explosions & effects
├── types.ts                   # TypeScript definitions
└── assets/                    # Pre-generated AI images
    ├── player-ship.png
    ├── enemy-scout.png
    ├── enemy-fighter.png
    ├── enemy-boss.png
    └── background.png
                    

The Results

Performance Comparison

Metric Real-Time AI Pre-Generated Improvement
Initial Load Time 30-60s 2-3s ⬇️ 95%
Time to Interactive 60-90s 3-4s ⬇️ 95%
API Cost per Play $0.15-0.25 $0.00 ⬇️ 100%
Success Rate ~85% ~99.9% ⬆️ 17%
Player Retention ~40% ~85% ⬆️ 113%
Bundle Size ~200KB ~850KB ⬆️ 325%

What We Gained

  1. Instant Playability: Game loads in 2-3 seconds, meeting modern web standards
  2. Zero Runtime Costs: No API calls during gameplay = sustainable at scale
  3. Reliability: No network dependencies = consistent experience
  4. Better UX: 85% player retention vs. 40% before
  5. AI Benefits Retained: Still using AI-generated graphics, just smarter

What We Traded

The pivot wasn't without trade-offs:

  • Unique Visuals: Lost the "every game looks different" feature
  • Bundle Size: Increased from 200KB to 850KB (still acceptable)
  • Dynamic Generation: Can't generate new assets on user request

But here's the thing: none of our players actually wanted those features. They wanted to play a fun game immediately. We were optimizing for novelty when we should have been optimizing for fun.


Lessons Learned

1. Know When to Use AI

"Just because you can use AI doesn't mean you should use it at runtime."

AI is a powerful tool, but it's not always the right tool for every moment. Real-time generation makes sense for:

  • User-specific content (personalized messages, recommendations)
  • Truly unique outputs (art generation tools, character creators)
  • When speed isn't critical (background tasks, asynchronous generation)

But for standard game assets that don't change? Pre-generate during development.

2. User Experience Trumps Technology

Our first version was technically impressive but practically unusable. We learned:

  • ✅ Fast load times > cutting-edge features
  • ✅ Reliable gameplay > dynamic generation
  • ✅ Fun experience > technical showcase

Players don't care about your tech stack. They care about having fun within 5 seconds of clicking "Play".

3. Build-Time vs. Runtime Decisions Matter

This pivot taught us to ask for every feature: "Does this need to happen at runtime, or can we move it to build time?"

Feature Runtime Build Time Best Choice
Game assets Slow, expensive Fast, free Build Time
User preferences Necessary Impossible Runtime
Game logic Required N/A Runtime
Asset optimization Slow Fast Build Time

4. Fail Fast, Pivot Faster

We could have spent months optimizing the real-time generation approach. Instead:

  • Week 1: Built initial version
  • Week 2: Tested with users, identified problems
  • Week 3: Pivoted to new architecture
  • Week 4: Shipped production version

Total development time: 3 weeks. If we'd been stubborn about our original vision, we'd still be optimizing the wrong thing.

5. AI as a Development Tool, Not a Runtime Feature

The most valuable lesson: AI can accelerate game development without being part of the game runtime.

We still get all the benefits of AI:

  • ✅ No need for professional artists
  • ✅ Rapid iteration on visual styles
  • ✅ Quick prototyping of new enemies/assets
  • ✅ Consistent art direction from AI prompts

But players get a fast, reliable game. Best of both worlds.


Future Improvements

Now that the core game is solid, we're exploring:

1. Multiple AI-Generated Theme Packs

  • Generate 3-5 complete art styles during development
  • Let players choose their preferred aesthetic
  • Example themes: Retro pixel art, Modern realistic, Abstract neon, etc.

2. Player-Customizable Ships (Optional)

  • Allow players to generate their own ship design
  • Process: Enter prompt → Wait 10s → Get custom ship
  • One-time generation, saved to localStorage

3. Procedural Level Generation

  • Use AI to generate unique enemy formations
  • Pre-generate 50+ patterns during build
  • Randomize selection at runtime (no generation lag)

4. AI-Assisted Game Balancing

  • Use AI to analyze player data
  • Suggest difficulty tweaks during development
  • Generate optimal difficulty curves

Conclusion

Galaxy Guardian became the 14th game in the InstantGames.top collection, and it taught us more than any game before it. Not just about AI or game development, but about the importance of putting players first.

Key Takeaways

  1. AI is a tool, not magic: Use it where it provides real value
  2. Speed matters: 2 seconds feels instant, 60 seconds feels broken
  3. Build-time > Runtime: Generate once, use forever
  4. Listen to users: They want fun, not features
  5. Pivot quickly: Don't fall in love with your first idea

The game that ships is better than the perfect game that doesn't. Galaxy Guardian isn't revolutionary—it's a solid arcade shooter with AI-generated art. But it loads fast, plays well, and costs nothing to operate at scale.

That's a win.


Try Galaxy Guardian

Experience the final result yourself. No 60-second wait, we promise.

Play Now →

Explore the Code

Want to see how it's built? Check out the source code and asset generation scripts.

View on GitHub →

Technical Specifications

Tech Stack

  • Frontend: React 19.2.1
  • Language: TypeScript 5.8.2
  • Build Tool: Vite 6.2.0
  • AI Tool: Gemini Nano Banana Pro
  • Rendering: HTML5 Canvas 2D

Performance Metrics

  • Bundle Size: 850KB (gzipped: ~280KB)
  • Load Time: 2-3 seconds (4G connection)
  • Frame Rate: 60 FPS (locked)
  • Memory Usage: ~45MB average

Browser Support

  • ✅ Chrome/Edge 90+
  • ✅ Firefox 88+
  • ✅ Safari 14+
  • ✅ Mobile browsers (iOS/Android)

Asset Generation

  • Total Assets: 5 core images
  • Generation Time: ~2 minutes total
  • Cost: ~$0.05 (one-time)
  • Image Format: PNG (optimized)