rpg

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 0 Imported by: 0

README

RPG ✨🕹️

Go Report Card Go Reference

Create text-based role-playing games with Go

Installation 📥

go get github.com/brittonhayes/rpg

Examples

Check the _examples directory for examples of how to use the library.

Characters 👥

Use rpg/character to create players, NPCs, and enemies in your game. Keep it simple or customize to your heart's content with character builder options.

Create a player

Create a simple character with some basic defaults.

player := character.New(
    character.WithName("Player 1"),
    character.WithRank(1),
)
Customize your character

Get a little more creative and build out the character how you want.

player := character.New(
    character.WithName("Player 1"),
    character.IsPlayer(),
    character.WithRank(1),
    character.WithHealth(stat.Full),
    character.WithAttacks(
        character.NewAttack("Smack", character.LightAttack, 8.00),
        character.NewAttack("Stomp", character.HeavyAttack, 20.00),
    ),
    character.WithCustomStats(
        map[string]*character.Stat{
            "Intelligence": character.NewStat(stat.Half),
            "Charm":        character.NewStat(stat.Low),
        },
    ),
)

Combat ⚔️

Make players and NPCs engage in combat with the player.Attack() method. Attacks will take into account health, armor, and attack damage.

Example Code
log := logger.NewLogger(os.Stderr)

// Create a player
player := character.New(
    character.WithName("Player 1"),
)

// Create an enemy
enemy := character.New(
    character.WithName("Enemy 1"),
    character.WithHealth(stat.Low),
    character.WithArmor(stat.Half),
)

// Attack the enemy
dialogue.Say(player, "Let's see how a heavy attack works")
player.Attack(enemy, player.Attacks.Heavy)

// Log the attack
log.Attack(player.Name, enemy.Name, player.Attacks.Heavy)
Preview

Combat

Dialogue 💬

Create conversations between players and handle their answers with the a custom answer handler function.

Example Code
player := character.New(
    character.WithName("Player"),
    character.IsPlayer(),
    character.WithColor(color.Cyan),
    character.WithRank(5),
    character.WithHealth(stat.Full),
)

enemy := character.New(
    character.WithName("Enemy"),
    character.WithRank(1),
    character.WithHealth(stat.Half),
)

npc := character.New(
    character.WithName("Steve"),
)

// Speak as a player
dialogue.Say(player, "...oh boy. uh. I should probably get out of here.")

// Speak as an NPC
dialogue.Say(enemy, "Yeah this is for sure a felony. I think that guy over there definitely saw you do it too.")

// Speak as an NPC that died in combat. This will be prepended with "[DEAD]".
enemy.Health = 0.00
dialogue.Say(enemy, "Welp. Now look what you did. I'm dead. You're absolutely gonna need a lawyer.")

dialogue.Say(player, "You... uh.. You know a good lawyer?")

// Ask a question to the player and handle their answer
// with a custom function
dialogue.Ask(npc, "Oh. Are you talking to me? (yes/no)", func(answer string) error {
    switch answer {
    case "yes":
        dialogue.Say(npc, "I feel like you probably shouldn't be asking me for legal advice.")
    case "no":
        dialogue.Say(npc, "Okay cool, I'm gonna back away into the forrest and let you sort all this out.")
    default:
        dialogue.Say(npc, "I have no idea what you want me to say right now. Can I leave?")
        return nil
    }

    return nil
})
Preview

Dialogue screenshot

Documentation

Overview

Package rpg is a library for creating text-based role-playing games with go

Installation

go get github.com/brittonhayes/rpg

Usage

Check the _examples directory for examples on how to use the library

Directories

Path Synopsis
_examples
Package character contains all player and npc logic This package is used to create new playable and non-playable characters in the game world and have them interact
Package character contains all player and npc logic This package is used to create new playable and non-playable characters in the game world and have them interact
Package game contains the game engine logic for configuring, starting, and stopping games
Package game contains the game engine logic for configuring, starting, and stopping games
internal
Package logger contains an event logger for rendering in-game events to the console
Package logger contains an event logger for rendering in-game events to the console
Package stat contains default values for in-game character and item stats
Package stat contains default values for in-game character and item stats

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL