Skip to content

RezixDev/llm-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ AI-Powered RPG Game

A modern React-based RPG game featuring AI-driven NPCs and enemies powered by local LLM integration. Experience dynamic conversations, intelligent combat dialogue, and an immersive fantasy world where every character has personality!

Game Screenshot

โœจ Features

๐Ÿค– AI-Powered Characters

  • Smart NPCs: Talk to merchants and wizards with dynamic, context-aware conversations
  • Intelligent Enemies: Every enemy has unique personality and speaks during combat
  • Dynamic Dialogue: Characters remember your level, gold, and inventory
  • Local LLM Integration: Uses LM Studio for offline AI conversations

โš”๏ธ Combat System

  • Turn-based Combat: Strategic fighting with attack and flee options
  • Enemy Personalities: Fight sarcastic goblins, philosophical skeletons, and dim-witted trolls
  • Dynamic Battle Dialogue: Enemies taunt, react to damage, and give final words
  • Experience & Leveling: Gain XP and level up to become stronger

๐Ÿ’ฐ Economy & Trading

  • Gold Currency: Earn gold from defeating enemies
  • Merchant Trading: Sell items using natural language ("sell Magic Sword")
  • Inventory System: Collect and manage various items
  • Item Values: Different items have different worth

๐Ÿ—บ๏ธ Game World

  • Canvas-based Graphics: Smooth 2D pixel-art style gameplay
  • Multiple NPCs: Merchant, Wizard, and more to discover
  • Diverse Enemies: 4 unique enemy types with distinct personalities
  • Treasure Hunting: Find valuable items scattered across the world
  • Interactive Environment: Rich world with grid-based movement

๐ŸŽฏ Game Characters

๐Ÿ‘ฅ NPCs

  • ๐Ÿ›’ Merchant: Friendly trader who buys and sells items using AI conversation
  • ๐Ÿ”ฎ Wizard: Mystical sage offering wisdom and lore about the world

๐Ÿ‘น Enemies

  • ๐Ÿ—ก๏ธ Snarky Goblin: Sarcastic and cowardly, loves to taunt players
  • โš”๏ธ Brutal Orc: Aggressive warrior with intimidating battle cries
  • ๐Ÿ’€ Melancholy Skeleton: Sad, philosophical undead questioning existence
  • ๐Ÿ”๏ธ Dim-witted Troll: Simple-minded but surprisingly wise giant

๐Ÿ•น๏ธ Controls

Key Action
WASD / Arrow Keys Move player
Space Talk to NPCs (triggers AI conversation)
F Fight nearby enemies
E Collect treasure chests
I Toggle inventory
1 Attack (during combat)
2 Flee (during combat)

๐Ÿ› ๏ธ Installation & Setup

Prerequisites

  • Node.js 16+ and npm/yarn
  • LM Studio running locally
  • A compatible language model (we recommend Llama 3.2)

Quick Start

  1. Clone the repository

  2. Install dependencies

    pnpm install
    # or
    npm install
  3. Set up LM Studio

    • Download and install LM Studio
    • Load a compatible model
    • Start the local server (usually runs on http://localhost:1234)
  4. Configure environment

    # Create .env.local file
    VITE_LLM_API_URL=
    VITE_LLM_MODEL=
  5. Start the game

    pnpm start
    # or
    npm start
  6. Play! ๐ŸŽฎ Open http://localhost:5173/ and start your adventure!

๐Ÿ—๏ธ Project Structure

src/
โ”œโ”€โ”€ components/
โ”‚   โ””โ”€โ”€ GameCanvas.tsx          # Main game component
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ enemies.ts              # Enemy definitions & personalities
โ”‚   โ”œโ”€โ”€ npcs.ts                 # NPC configurations
โ”‚   โ”œโ”€โ”€ treasures.ts            # Treasure chest locations
โ”‚   โ””โ”€โ”€ itemPrices.ts           # Merchant pricing
โ”œโ”€โ”€ services/
โ”‚   โ””โ”€โ”€ llmService.ts           # AI/LLM communication service
โ”œโ”€โ”€ types/
โ”‚   โ””โ”€โ”€ GameTypes.ts            # TypeScript interfaces
โ”œโ”€โ”€ utils/
โ”‚   โ””โ”€โ”€ gameUtils.ts            # Game utility functions
โ””โ”€โ”€ App.tsx                     # Root application

๐ŸŽฎ Gameplay Guide

Getting Started

  1. Move around using WASD or arrow keys
  2. Approach NPCs (green/purple squares) and press Space to talk
  3. Find treasure chests (gold squares) and press E to collect
  4. Fight enemies (red squares) by pressing F when nearby

Combat Tips

  • Wait for enemies to finish talking before attacking
  • Level up by defeating enemies to deal more damage
  • Flee if your health gets too low
  • Each enemy has unique personality - learn their patterns!

Trading with the Merchant

  • Collect valuable items from treasure chests
  • Talk to the Merchant and say things like:
    • "sell Magic Sword"
    • "I want to trade my Ancient Rune"
    • "buy my Silver Ring"

Items & Values

Item Value Effect
Magic Sword 100 gold Valuable weapon
Ancient Rune 75 gold Mystical artifact
Silver Ring 50 gold Precious jewelry
Health Potion 25 gold Restores 50 HP

๐Ÿ”ง Customization

Adding New Enemies

Edit src/data/enemies.ts:

{
  id: "newenemy1",
  name: "Cunning Fox",
  personality: "clever and mischievous",
  battleCries: ["Too slow!", "Catch me if you can!"],
  // ... other properties
}

Adding New NPCs

Edit src/data/npcs.ts:

{
  id: "blacksmith",
  name: "Blacksmith",
  type: "crafter",
  dialogue: ["Need weapons forged?", "My hammer never rests!"],
  // ... other properties
}

Changing AI Model

Update your .env.local:

VITE_LLM_MODEL=your-preferred-model-name

๐Ÿค Contributing

We welcome contributions! Here are ways you can help:

  • ๐Ÿ› Bug Reports: Found a bug? Open an issue!
  • ๐Ÿ’ก Feature Ideas: Suggest new gameplay mechanics
  • ๐ŸŽจ Art & Design: Improve graphics and UI
  • ๐Ÿง  AI Improvements: Enhance character personalities
  • ๐Ÿ“ Documentation: Help improve guides and docs

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and test thoroughly
  4. Commit: git commit -m 'Add amazing feature'
  5. Push: git push origin feature/amazing-feature
  6. Open a Pull Request

๐ŸŽฏ Roadmap

Version 2.0 Features

  • Quest System: Dynamic quests generated by AI
  • More NPCs: Blacksmith, Innkeeper, Guards
  • Magic System: Spells and magical abilities
  • Multiple Areas: Dungeons, forests, towns
  • Save/Load: Persistent game progress
  • Sound Effects: Audio feedback for actions
  • Multiplayer: Online co-op gameplay

AI Enhancements

  • Memory System: NPCs remember past conversations
  • Dynamic Events: AI-generated random events
  • Procedural Quests: AI creates unique missions
  • Emotional States: Characters with changing moods

๐Ÿ“‹ Requirements

System Requirements

  • OS: Windows, macOS, or Linux
  • RAM: 4GB minimum (8GB recommended for LM Studio)
  • Storage: 2GB for game + model storage space
  • GPU: Optional but recommended for faster AI inference

Browser Support

  • Chrome 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+

๐Ÿ› Troubleshooting

Common Issues

๐Ÿ”ด "NPC seems distracted" message

  • Check if LM Studio is running
  • Verify the API URL in .env.local
  • Ensure the model is loaded in LM Studio

๐Ÿ”ด Game won't start

  • Run npm install to update dependencies
  • Check console for error messages
  • Verify Node.js version (16+)

๐Ÿ”ด Combat not working

  • Wait for enemy dialogue to finish
  • Try refreshing the page
  • Check browser console for errors

๐Ÿ™ Acknowledgments

  • LM Studio for providing excellent local LLM infrastructure
  • React team for the amazing framework
  • Canvas API for smooth 2D graphics
  • Open Source Community for inspiration and tools

โญ Star this repo if you enjoyed the game! It helps others discover this project.

๐ŸŽฎ Happy Gaming! May your adventures be epic and your conversations intelligent!

About

RPG Game using locally run LLM Model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages