🚀 Inspiration
I asked myself a simple but wild question: “What if AI could design the game while I’m playing it?”
That thought became the seed for Space AI Invaders — an experimental arcade game where each level is dynamically generated by AI using the Perplexity Sonar API. The game evolves in real time: new mechanics, enemy behaviors, and features are created by the AI — not hardcoded by me.
It flips the game development model on its head. I don’t just playtest it — I co-create it with AI.
🎮 What It Does
Space AI Invaders is a 2D shooter game where the rules change dynamically with each level. And here’s the twist: those rules are written by AI in real time.
Every time I finish a level:
- A prompt is sent to Perplexity Sonar.
- The AI returns a fresh Python function that introduces a new mechanic.
- That function is validated, stored, and executed inside the game.
- I extract a short summary and display it to inform the player about the new feature.
The results are unpredictable and fun:
- Bosses that spawn clones
- Bullets that curve or split
- Shields, portals, or even reversed gravity
- Wild, AI-invented enemy patterns
Every run is a new game.
🏗️ How I Built It
I used the following stack:
- Python 3.12
- Pygame for the main game loop and rendering
- Perplexity Sonar API for generating real-time Python game logic
- importlib for dynamically loading new code
- Custom modules for handling code validation, function injection, and summary parsing
Each level:
- Calls
generate_function()to ask Sonar for new gameplay logic. - Writes the result into
real_time/dynamic.py. - Runs a validation step to ensure it’s safe and executable.
- Loads the new function using
importlib. - Displays the AI-generated summary to the player.
This process keeps evolving the game, level by level.
🧗 Challenges I Ran Into
- Syntax and Safety: Not every AI-generated function worked out of the box, so I had to build a mini validation system.
- Dynamic Imports: Injecting code during runtime without crashing the game took a lot of debugging.
- Balancing AI Creativity: Some levels were ridiculously hard or easy — I had to refine prompts carefully.
- Maintaining Game Stability: Integrating live code without breaking core mechanics was tricky but rewarding.
🏆 Accomplishments I’m Proud Of
- I created a game that writes itself as you play, using live AI-generated Python.
- Successfully integrated Perplexity Sonar into a Pygame loop for real-time code evolution.
- Built a stable and modular system for injecting new gameplay logic.
- Turned the AI into a real-time game designer — not just a tool.
📚 What I Learned
- AI-generated code can be dynamic, creative, and usable — with proper structure and safeguards.
- Prompt design deeply influences how fun and functional the AI logic becomes.
- Python's dynamic nature (especially
importliband runtime execution) can be harnessed for creative gameplay. - The Perplexity Sonar API is fast, smart, and fun to build with — perfect for a creative project like this.
🔮 What’s Next for Space AI Invaders
I’m just scratching the surface. Here’s what I want to build next:
- 🎙️ Voice Control: Let players talk to the game and change the rules via voice prompts.
- 🤖 Dynamic NPCs: AI-generated enemies and allies with unique personalities and backstories.
- 🌍 Multiplayer Mode: Co-op or versus worlds that evolve live, with each player shaping the gameplay.
- 🧱 Custom Themes: Let players set a theme (e.g., space pirates or underwater physics) and let AI re-skin mechanics.
🎉 Submission Note
This project is proudly submitted to two categories at the Perplexity Global Hackathon:
- Most Creative / Fun Project
- Best Deep Research Category
Leveraging Perplexity Sonar’s powerful deep reasoning and code generation, Space AI Invaders uniquely combines real-time AI creativity with rigorous logic validation to dynamically craft new, engaging game features. The AI doesn’t just write code—it thoughtfully analyzes gameplay mechanics, ensures flawless syntax, and continuously optimizes functionality, making each level truly innovative and playable. This seamless fusion of creative generation and deep technical reasoning exemplifies cutting-edge research in AI-driven game design, justifying its recognition as both the most creative project and a standout in deep research excellence.
Ultimately, I want to explore what happens when AI doesn’t just assist with game development — but becomes part of the experience itself.
Log in or sign up for Devpost to join the conversation.