Skip to main content

Generate and play AI-powered interactive adventures.

Project description

Gen-Adventure

Generate and play AI-powered interactive adventures with Python, Pygame, and Google Gemini.

Gen-Adventure allows you to:

  • Create interactive branching stories using Google's Gemini models.
  • Play generated stories through a graphical interface built with Pygame.
  • Load stories from local JSON files or remote URLs.
  • Explore built-in example adventures.

Features

  • AI-powered story generation using Gemini.
  • Interactive branching adventures.
  • Pygame graphical interface.
  • Local and remote story support.
  • JSON-based story format.
  • Built-in example stories.

Installation

pip install gen-adventure

Requirements

  • Python 3.11+
  • Google Gemini API Key

Playing an Adventure

Load a local JSON story:

from gen_adventure import Adventure

game = Adventure("my_story.json")
game.start()

Load a story hosted online:

from gen_adventure import Adventure

game = Adventure(
    "https://example.com/my_story.json"
)

game.start()

Built-in Example Stories

Gen-Adventure includes several example stories hosted in the project's repository.

from gen_adventure import Adventure, StoryExamples

examples = StoryExamples()

game = Adventure(examples.fantasy)
game.start()

Available examples:

  • fantasy
  • hacker
  • formatura
  • love_story

Generating Stories with Gemini

Create a story and save it as a JSON file:

from gen_adventure import StoryImaginator

imaginator = StoryImaginator("YOUR_GEMINI_API_KEY")

imaginator.imagine(
    "A cyberpunk hacker fighting an evil corporation",
    "cyberpunk_story.json"
)

Standard Gemini model is 'gemini-2.5-flash', but you can change into another model you prefer. Changing Gemini model:

from gen_adventure import StoryImaginator

imaginator = StoryImaginator("YOUR_GEMINI_API_KEY")
imaginator.model = "gemini-3.5-flash"

The generated file can then be loaded into the game:

from gen_adventure import Adventure

game = Adventure("cyberpunk_story.json")
game.start()

Story Format

Stories are stored as JSON files.

Example:

{
    "pages": [
        {
            "id": 1,
            "text": "You wake up in a mysterious forest.",
            "options": [
                {
                    "text": "Follow the path",
                    "target": 2
                },
                {
                    "text": "Enter the cave",
                    "target": 3
                }
            ]
        }
    ]
}

Each page contains:

Field Description
id Page identifier
text Story content
options Available choices

Each option contains:

Field Description
text Text displayed to the player
target Destination page

Customizing Colors

You can customize the interface colors:

from gen_adventure import Adventure

game = Adventure("story.json")

game.text_color = (255, 255, 255)
game.background_color = (25, 25, 25)
game.button_background_color = (50, 50, 50)

game.start()

Example Workflow

Generate a story:

from gen_adventure import StoryImaginator

imaginator = StoryImaginator("YOUR_GEMINI_API_KEY")

imaginator.imagine(
    "A medieval knight searching for a lost kingdom",
    "kingdom.json"
)

Play the generated adventure:

from gen_adventure import Adventure

game = Adventure("kingdom.json")
game.start()

Project Structure

gen_adventure/
├── adventure.py
├── pages.py
├── story_imaginator.py
└── __init__.py

Dependencies

  • pygame
  • google-genai
  • requests

License

This project is licensed under the MIT License.

See the LICENSE file for details.


Author

Johnny Matos

GitHub: https://github.com/DS-Johnny

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gen_adventure-0.1.8.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gen_adventure-0.1.8-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file gen_adventure-0.1.8.tar.gz.

File metadata

  • Download URL: gen_adventure-0.1.8.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for gen_adventure-0.1.8.tar.gz
Algorithm Hash digest
SHA256 a34ee3cced3019a9cd63049b20fd8c447ed2cec6a4cb4d239a7ac44ff900e7c9
MD5 e635b6c717c6ce2a21c689e8f34aae60
BLAKE2b-256 b4fcd01491ffd9ce9ce310960484b39833c252549759f60eb9e57ab014bd3be0

See more details on using hashes here.

File details

Details for the file gen_adventure-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: gen_adventure-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for gen_adventure-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 cb25060dfc9f0372d1ea523f6fe839f3f4594ce419bac4757770c663f8a53ad7
MD5 d697c2035f40a0bd1d8aaef8e7338402
BLAKE2b-256 67f2d6ffccea2b9020d2aa5bff8f79276de80d5f223dafd71253190feb9cbcf6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page