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()

imaginator.gemini_api_key = "YOUR_GEMINI_API_KEY"

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

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()

imaginator.gemini_api_key = "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.7.tar.gz (10.7 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.7-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gen_adventure-0.1.7.tar.gz
  • Upload date:
  • Size: 10.7 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.7.tar.gz
Algorithm Hash digest
SHA256 aef8f7621fdb6229b0e6a252c8edc464cd314e2fde0479c868f69eb649133a1f
MD5 fc4dce643a0da5214d9573a3a0a84f52
BLAKE2b-256 672d7b8a91cb6ff047b845a5757bee53d484c5a5fed8572f16839dee5ce8f9ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gen_adventure-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 11.1 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 9eaf558545c1df114667b0b96a688c62abb5d2908819338d72370e8368d54571
MD5 2181bb45460d9130168741604f99986d
BLAKE2b-256 087233928de9c36b4e4e32f39380c17ca9bad14a0cf40000f01e8081baf6d4b9

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