Skip to content

An immersive AI-powered text adventure game that combines the storytelling prowess of Google's Gemini 2.0 Flash with the visual creativity of Cloudflare's AI image generation.

License

Notifications You must be signed in to change notification settings

Khushal-Me/Simulated-Souls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Simulated Souls ๐ŸŽญ

An immersive AI-powered text adventure game that combines the storytelling prowess of Google's Gemini 2.0 Flash with the visual creativity of Cloudflare's AI image generation. Every choice you make shapes both the narrative and the accompanying artwork in real-time.

โœจ Features

  • ๐ŸŽช Dynamic Storytelling: Powered by Gemini 2.0 Flash for rich, contextual narratives
  • ๐ŸŽจ Real-time Image Generation: Cloudflare's stable-diffusion-xl-lightning creates stunning visuals for every scene
  • โšก Lightning-fast Responses: Optimized for quick story progression and image generation
  • ๐ŸŽฎ Interactive Gameplay: Your actions directly influence the story direction
  • ๐Ÿ“ฑ Responsive Design: Beautiful UI that works on desktop and mobile
  • ๐Ÿ”„ Seamless Experience: Smooth transitions between story beats with visual feedback

๐Ÿ› ๏ธ Tech Stack

  • Frontend: React 19 + TypeScript + Tailwind CSS
  • Build Tool: Vite with ES modules
  • AI Services:
  • Google Gemini 2.0 Flash (text generation)
  • Cloudflare Workers AI (image generation)
  • Backend: Express.js proxy server for CORS handling
  • Styling: Tailwind CSS with custom gradients and animations

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have:

  • Node.js (version 16 or higher)
  • npm or yarn package manager
  • Google Gemini API Key (free tier available)
  • Cloudflare API Key and Account ID

๐Ÿš€ Quick Start

1. Clone and Install

git clone https://github.com/Khushal-Me/Simulated-Souls
cd Simulated-Souls
npm install

2. Set Up API Keys

Create a .env.local file in the root directory:

# Google Gemini API Key (for storytelling)
GEMINI_API_KEY=your_gemini_api_key_here

# Cloudflare API Key (for image generation)
CLOUDFLARE_API_KEY=your_cloudflare_global_api_key_here

3. Configure Cloudflare Account

Update your Cloudflare Account ID in proxy-server/server.js:

const ACCOUNT_ID = 'your_cloudflare_account_id_here';

4. Install Proxy Server Dependencies

cd proxy-server
npm install
cd ..

5. Run the Application

Terminal 1 - Start the proxy server:

node proxy-server/server.js

Terminal 2 - Start the main application:

npm run dev

6. Play the Game

Open your browser and navigate to http://localhost:5173

7. Demo

Demo.mp4

๐Ÿ”‘ Getting Your API Keys

๐Ÿ“š Gemini API Key

  1. Visit Google AI Studio
  2. Sign in with your Google account
  3. Click "Create API Key"
  4. Copy the generated key to your .env.local file

โ˜๏ธ Cloudflare API Key & Account ID

  1. Log in to Cloudflare Dashboard
  2. Go to "My Profile" โ†’ "API Tokens"
  3. Scroll to "Global API Key" and click "View"
  4. Copy the key to your .env.local file
  5. Find your Account ID in the right sidebar of any domain dashboard
  6. Update the ACCOUNT_ID in proxy-server/server.js

๐Ÿ—๏ธ Project Structure

gemini-adventure-weaver/
โ”œโ”€โ”€ ๐Ÿ“ components/ # React components
โ”‚ โ”œโ”€โ”€ ErrorMessage.tsx # Error display component
โ”‚ โ””โ”€โ”€ LoadingSpinner.tsx # Loading animation component
โ”œโ”€โ”€ ๐Ÿ“ proxy-server/ # Express.js CORS proxy
โ”‚ โ”œโ”€โ”€ server.js # Proxy server for Cloudflare API
โ”‚ โ””โ”€โ”€ package.json # Proxy dependencies
โ”œโ”€โ”€ ๐Ÿ“ services/ # API service layer
โ”‚ โ””โ”€โ”€ geminiService.ts # Gemini & Cloudflare integrations
โ”œโ”€โ”€ App.tsx # Main application component
โ”œโ”€โ”€ index.tsx # Application entry point
โ”œโ”€โ”€ types.ts # TypeScript type definitions
โ”œโ”€โ”€ vite.config.ts # Vite configuration
โ””โ”€โ”€ .env.local # Environment variables (create this)

๐ŸŽฎ How to Play

  1. Start: Click "Begin Your Adventure" to initialize your story
  2. Read: Enjoy the AI-generated scene description and accompanying artwork
  3. Act: Type your action in the input field (e.g., "open the door", "talk to the wizard")
  4. Watch: See how your choices influence both the story and generated images
  5. Continue: Keep making choices to weave your unique adventure
  6. Restart: Use the "Restart Adventure" button to begin a new story

โš™๏ธ Configuration

๐Ÿ“– Story Configuration

Customize the storytelling behavior by modifying the SYSTEM_INSTRUCTION in services/geminiService.ts.

๐Ÿ”ง Troubleshooting

Common Issues

๐Ÿšซ CORS Errors

๐Ÿ”‘ API Authentication

  • Verify your .env.local file exists and contains valid API keys
  • Check the proxy server status at http://localhost:3001/api/status
  • Ensure your Cloudflare account has Workers AI enabled

๐Ÿ–ผ๏ธ Image Generation Failures

  • Verify your Cloudflare Account ID is correct
  • Check your Cloudflare API quota and billing status
  • Ensure you're using the Global API Key, not a scoped token

๐ŸŒ Network Issues

  • Make sure ports 3001 and 5173 are available
  • Check your firewall settings
  • Verify internet connectivity for API calls

Debug Commands

Check proxy server status:

curl http://localhost:3001/api/status

Test image generation:

curl -X POST http://localhost:3001/api/generate-image \
-H "Content-Type: application/json" \
-d '{"prompt": "a magical forest"}'

๐Ÿš€ Deployment

Development

npm run dev # Start development server

Production Build

npm run build # Build for production
npm run preview # Preview production build

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ“ž Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section
  2. Review the Cloudflare setup guide
  3. Open an issue on GitHub
  4. Check API status pages for service outages

About

An immersive AI-powered text adventure game that combines the storytelling prowess of Google's Gemini 2.0 Flash with the visual creativity of Cloudflare's AI image generation.

Topics

Resources

License

Stars

Watchers

Forks