gamerogueish

package module
v0.0.0-...-0bb4155 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: GPL-3.0 Imports: 13 Imported by: 1

README

Gamerogueish

This is a sorta-kinda roguelike using the fantastic package https://github.com/BigJk/ramen, which is a simple console emulator written in go that can be used to create various ascii / text (roguelike) games.

Right now, the code is a really basic re-factor of the roguelike example that comes with Ramen, but I'll use it as a basis for various (at least to me) interesting experiments :)

alt text

alt text

alt text

alt text

Keybindings

  • ASDW - Move
  • Space - Attack
  • TAB - Toggle UI selection
  • Arrow Up / Down - Select UI element
  • Enter - Consume / Equip / Loot selected UI element
  • Backspace - Drop selected UI element
  • P - Add potion to inventory (for testing)
  • T - Add trap to inventory (for testing)

TODO

  • Creatures
    • [DONE] Basic movement (random)
      • Custom movement speed
    • [DONE] AI (basic)
      • Custom perception radius
      • Should recognize traps and see items
    • [DONE] Pathfinding
      • Optimize
    • [DONE] Traps should affect enemies (hacky)
      • Only enemies that are within player view are affected
    • [DONE] Randomized loot
    • Generate names
  • Documentation
  • Inventory
    • [DONE] Basic inventory
    • [DONE] Item add / remove
  • Items
    • [DONE] Basic items
    • [DONE] Item generation
    • [DONE] Consumable items
    • [DONE] Equippable items
    • [DONE] Enemy inventory
      • [DONE] Display items on dead enemies
      • [DONE] Looting of dead enemies
        • SELECTIVE looting of dead enemies
    • Item pickup / drop
      • [DONE] Item drop
        • Confirmation before dropping
      • [DONE] Item pickup
    • Item effects
    • [DONE] Item triggers
    • Notes / books
    • Hidden items
      • [DONE] Hidden traps
      • [DONE] Reveal hidden items on touch
      • Reveal hiddem items if we have high enough perception or a potion of perception
      • Hidden status should be per entity (player, enemy) so that enemies can also run into traps and avoid them when they know where they are
  • Combat
    • [DONE] Player death
    • Enemies should attack on each turn
  • Map generation
    • [DONE] Custom seed
    • [DONE] Custom world generator functions
    • [DONE] Creature placement
    • Item placement
    • [DONE] Dungeons
      • Neighbor rooms not centered (optionally)
      • Connections / doors not centered (optionally)
      • [DONE] Water puddles
        • Prevent water from blocking doors
      • [DONE] Columns
        • Improve symmetric distribution
      • [DONE] Traps
    • Caves
    • Overworld / outdoor
      • Allow for elevation in tiles
        • [DONE] Shade tiles based on elevation difference to player
          • [DONE] Player is always the baseline for shading
          • [DONE] Everything below player is shaded darker (to black)
          • [DONE] Everything above player is shaded lighter (to white)
          • [DONE] If a player changes elevation, the shading should change accordingly
      • Player / entity can only enter tiles with a max elevation difference of n
      • Multi dimensional map? (e.g. 3d)
  • FOV / 'Fog of war'
    • [DONE] Basic radius based FOV
    • Raycasting based FOV
    • Merge map and FOV?
  • Items / Entities rendering
    • Interface for items / entities in the world
  • UI
    • Add scenes / screens
      • Scene interface
        • Input handling
        • Rendering
        • [DONE] Add Close() method to scenes
          • [DONE] Clean up components when switching scenes
          • [DONE-ish]Remove all textboxes
      • Scenes
        • Character creation
        • Main menu
        • [DONE] Main game
        • [DONE] Game over
        • [DONE] Win (located exit)
    • Deduplicate UI code (items, enemies, etc)
    • Highlight active UI components
    • Move player info out of selectable UI
    • Dialog / conversation
      • Extend textbox
      • Add multiple choice dialog (actions)
    • Textbox
      • [DONE] De-dupe scene textbox code
      • [DONE] Add scene textbox
        • [DONE] Pagination
        • [DONE] Line break / paragraph support
        • Move to top level (so that it can be used in all scenes)
        • Make closing key configurable (and customize bottom text accordingly)
  • Gameplay
    • [DONE] Add win condition
    • Cutscenes / events / triggers
      • Trigger scenes through items (e.g. stairs, level exit)
        • [DONE] Level exit
        • [DONE] Trap
        • Text / message
      • Limit triggers to entity types (e.g. only player can trigger stairs)
    • Collects stats or score to show on win/lose

Interesting stuff

Documentation

Index

Constants

View Source
const (
	ItemWeapon = iota
	ItemPotion
	ItemArmor
	ItemHelmet
	ItemTrigger
	ItemTypeContainer
	ItemTypeDocument
	ItemTypeDecorative
	ItemTypeMax
)
View Source
const (
	DirNorth = 0
	DirEast  = 1
	DirSouth = 2
	DirWest  = 3
)

Cardinal directions.

View Source
const (
	CharWall   = '#'
	CharWater  = '~'
	CharFloor  = ' '
	CharTree   = 'T'
	CharShelf  = 'S'
	CharColumn = 'o'
)

Variables

View Source
var (
	EntityPlayer = &EntityType{
		Tile:        '@',
		Name:        "player",
		BaseHealth:  10,
		BaseAttack:  2,
		BaseDefense: 10,
		Equipment: []*ItemType{
			ItemTypeWeaponFishingRod,
			ItemTypeArmorPlate,
			ItemTypeHelmetSweatband,
			ItemTypePotion,
			ItemTypeNote,
		},
	}
	EntityGoblin = &EntityType{
		Tile:        'g',
		Name:        "goblin",
		Description: "A small goblin.",
		BaseHealth:  5,
		BaseAttack:  1,
		BaseDefense: 5,
		Equipment:   []*ItemType{ItemTypeWeaponAxe, ItemTypeArmorChain},
		OptionalEquipment: []*ItemType{
			ItemTypePotion,
			ItemTypeGoblinToe,
		},
	}
	EntityOrc = &EntityType{
		Tile:        'o',
		Name:        "orc",
		Description: "A big orc.",
		BaseHealth:  10,
		BaseAttack:  5,
		BaseDefense: 14,
		Equipment:   []*ItemType{ItemTypeWeaponSword, ItemTypeArmorLeather},
		OptionalEquipment: []*ItemType{
			ItemTypePotion,
		},
	}
	EntityTroll = &EntityType{
		Tile:        't',
		Name:        "troll",
		Description: "A huge troll.",
		BaseHealth:  15,
		BaseAttack:  7,
		BaseDefense: 15,
		Equipment:   []*ItemType{ItemTypeTrollPoop},
	}
)
View Source
var (
	RarityAbundant = &Rarity{
		Name:           "abundant",
		Probability:    25,
		IndicateRarity: false,
	}
	RarityCommon = &Rarity{
		Name:           "common",
		Probability:    45,
		IndicateRarity: false,
	}
	RarityAverage = &Rarity{
		Name:           "average",
		Probability:    65,
		IndicateRarity: false,
	}
	RarityUncommon = &Rarity{
		Name:           "uncommon",
		Probability:    80,
		IndicateRarity: true,
	}
	RarityRare = &Rarity{
		Name:           "rare",
		Probability:    93,
		IndicateRarity: true,
	}
	RarityExotic = &Rarity{
		Name:           "exotic",
		Probability:    99,
		IndicateRarity: true,
	}
	RarityLegendary = &Rarity{
		Name:           "legendary",
		Probability:    100,
		IndicateRarity: true,
	}
)
View Source
var (
	ItemSetWeapons = &ItemSet{
		Name: "weapons",
		Items: []*ItemType{
			ItemTypeWeaponFishingRod,
			ItemTypeWeaponSword,
			ItemTypeWeaponAxe,
		},
	}
	ItemSetArmor = &ItemSet{
		Name: "armor",
		Items: []*ItemType{
			ItemTypeArmorLeather,
			ItemTypeArmorChain,
			ItemTypeArmorPlate,
			ItemTypeHelmetSweatband,
		},
	}
	ItemSetPotions = &ItemSet{
		Name: "potions",
		Items: []*ItemType{
			ItemTypePotion,
			ItemTypeTrollPoop,
			ItemTypeGoblinToe,
		},
	}
	ItemSetChestLoot = &ItemSet{
		Name: "chest loot",
		Items: []*ItemType{
			ItemTypeWeaponFishingRod,
			ItemTypeWeaponSword,
			ItemTypeWeaponAxe,
			ItemTypePotion,
			ItemTypeArmorLeather,
			ItemTypeArmorChain,
			ItemTypeArmorPlate,
			ItemTypeHelmetSweatband,
			ItemTypeExit,
			ItemTypeTrap,
			ItemTypeNote,
		},
	}
	ItemSetBookLoot = &ItemSet{
		Name: "book loot",
		Items: []*ItemType{
			ItemTypeNote,
			ItemTypeLetter,
		},
	}
	ItemSetBookshelfLoot = &ItemSet{
		Name: "bookshelf loot",
		Items: []*ItemType{
			ItemTypeBook,
			ItemTypeNote,
			ItemTypeLetter,
			ItemTypeBook,
			ItemTypeBook,
			ItemTypeBook,
		},
	}
	ItemSetStationary = &ItemSet{
		Name: "stationary",
		Items: []*ItemType{
			ItemTypeBook,
			ItemTypeNote,
			ItemTypeLetter,
			ItemTypeQuill,
			ItemTypeInk,
			ItemTypeParchment,
			ItemTypeSealingWax,
		},
	}
	ItemSetBedLoot = &ItemSet{
		Name: "bed loot",
		Items: []*ItemType{
			ItemTypeBedSheet,
			ItemTypePillow,
			ItemTypeBlanket,
		},
	}
)
View Source
var (
	ItemTypeWeaponFishingRod = &ItemType{
		Tile:        'f',
		Name:        "Fishing Rod",
		Description: "Baelin's fishing rod.",
		Type:        ItemWeapon,
		Modifier:    20,
		Rarity:      RarityLegendary,
	}
	ItemTypeWeaponSword = &ItemType{
		Tile:        '/',
		Name:        "Sword",
		Description: "A sharp sword.",
		Type:        ItemWeapon,
		Rarity:      RarityUncommon,
	}
	ItemTypeWeaponAxe = &ItemType{
		Tile:        'P',
		Name:        "Axe",
		Description: "A sharp axe.",
		Type:        ItemWeapon,
		Modifier:    1,
		Rarity:      RarityUncommon,
	}
	ItemTypePotion = &ItemType{
		Tile:        'Ö',
		Name:        "Potion",
		Description: "A healing potion.",
		Type:        ItemPotion,
		Rarity:      RarityUncommon,
	}
	ItemTypeTrollPoop = &ItemType{
		Tile:        '8',
		Name:        "Troll Poop",
		Description: "... with sprinkles!",
		Type:        ItemPotion,
		Modifier:    10,
		Rarity:      RarityLegendary,
	}
	ItemTypeGoblinToe = &ItemType{
		Tile:        't',
		Name:        "Goblin Toe",
		Description: "It's a bit smelly. A popular snack on TikTok.",
		Type:        ItemPotion,
		Modifier:    -1,
		Rarity:      RarityRare,
	}
	ItemTypeArmorLeather = &ItemType{
		Tile:        'L',
		Name:        "Leather Armor",
		Description: "A leather armor.",
		Type:        ItemArmor,
		Rarity:      RarityUncommon,
	}
	ItemTypeArmorChain = &ItemType{
		Tile:        'C',
		Name:        "Chain Armor",
		Description: "A chain armor.",
		Type:        ItemArmor,
		Modifier:    2,
		Rarity:      RarityRare,
	}
	ItemTypeArmorPlate = &ItemType{
		Tile:        'P',
		Name:        "Plate Armor",
		Description: "A plate armor.",
		Type:        ItemArmor,
		Modifier:    4,
		Rarity:      RarityExotic,
	}
	ItemTypeHelmetSweatband = &ItemType{
		Tile:        'S',
		Name:        "Sweatband",
		Description: "A stylish sweatband.",
		Type:        ItemHelmet,
		Modifier:    1,
		Rarity:      RarityUncommon,
	}
	ItemTypeExit = &ItemType{
		Tile:        '>',
		Name:        "Exit",
		Description: "An exit.",
		Type:        ItemTrigger,
		OnTouch: func(g *Game, e *Entity, i *Item) {

			if e.EntityType == EntityPlayer {
				g.setViewMode(ViewModeSuccess)
			}
		},
	}
	ItemTypeTrap = &ItemType{
		Tile:        '^',
		Name:        "Trap",
		Description: "A trap.",
		Hidden:      true,
		Type:        ItemTrigger,
		OnTouch: func(g *Game, e *Entity, i *Item) {

			g.AddMessage(e.Name + " stepped on a trap!")
			e.Health -= 5

			i.Hidden = false

		},
	}
	ItemTypeNote = &ItemType{
		Tile:        'N',
		Name:        "Note",
		Description: "A note.",
		Type:        ItemTypeDocument,
		Rarity:      RarityRare,
		OnUse: func(g *Game, e *Entity, i *Item) {

			g.AddMessage("You read the note: \"You are a wizard, Harry!\"")
		},
	}
	ItemTypeLetter = &ItemType{
		Tile:        'L',
		Name:        "Letter",
		Description: "A letter.",
		Type:        ItemTypeDocument,
		Rarity:      RarityLegendary,
		OnUse: func(g *Game, e *Entity, i *Item) {

			g.AddMessage("You read the letter: \"Dear Mr. Bigglesworth!\"")
		},
	}
	ItemTypeBook = &ItemType{
		Tile:         'b',
		Name:         "Book",
		Description:  "A book.",
		Type:         ItemTypeDocument,
		Capacity:     1,
		Rarity:       RarityCommon,
		PossibleLoot: ItemSetBookLoot,
	}
	ItemTypeChest = &ItemType{
		Tile:         'c',
		Name:         "Chest",
		Description:  "A chest.",
		Type:         ItemTypeContainer,
		Capacity:     4,
		Movable:      false,
		PossibleLoot: ItemSetChestLoot,
	}
	ItemTypeBed = &ItemType{
		Tile:         'b',
		Name:         "Bed",
		Description:  "A bed.",
		Type:         ItemTypeContainer,
		Capacity:     2,
		Movable:      false,
		PossibleLoot: ItemSetBedLoot,
	}
	ItemTypeSideTable = &ItemType{
		Tile:        't',
		Name:        "Side Table",
		Description: "A side table.",
		Type:        ItemTypeContainer,
		Capacity:    1,
		Movable:     false,
	}
	ItemTypeAltar = &ItemType{
		Tile:        'a',
		Name:        "Altar",
		Description: "An altar.",
		Type:        ItemTypeContainer,
		Capacity:    1,
		Movable:     false,
	}
	ItemTypeDesk = &ItemType{
		Tile:         'd',
		Name:         "Desk",
		Description:  "A desk.",
		Type:         ItemTypeContainer,
		Capacity:     2,
		Movable:      false,
		PossibleLoot: ItemSetStationary,
	}
	ItemTypeBookshelf = &ItemType{
		Tile:         'b',
		Name:         "Book Shelf",
		Description:  "A book shelf.",
		Type:         ItemTypeContainer,
		Capacity:     4,
		Movable:      false,
		Rarity:       RarityCommon,
		PossibleLoot: ItemSetBookshelfLoot,
	}
	ItemTypeCandle = &ItemType{
		Tile:        'c',
		Name:        "Candle",
		Description: "A candle.",
		Type:        ItemTypeDecorative,
		Movable:     true,
	}
	ItemTypeQuill = &ItemType{
		Tile:        'q',
		Name:        "Quill",
		Description: "A quill.",
		Type:        ItemTypeDecorative,
		Rarity:      RarityUncommon,
		Movable:     true,
	}
	ItemTypeInk = &ItemType{
		Tile:        'i',
		Name:        "Ink",
		Description: "An ink.",
		Type:        ItemTypeDecorative,
		Rarity:      RarityUncommon,
		Movable:     true,
	}
	ItemTypeParchment = &ItemType{
		Tile:        'p',
		Name:        "Parchment",
		Description: "A parchment.",
		Type:        ItemTypeDecorative,
		Rarity:      RarityUncommon,
		Movable:     true,
	}
	ItemTypeSealingWax = &ItemType{
		Tile:        'w',
		Name:        "Sealing Wax",
		Description: "A sealing wax.",
		Type:        ItemTypeDecorative,
		Rarity:      RarityUncommon,
		Movable:     true,
	}
	ItemTypeEnvelope = &ItemType{
		Tile:         'e',
		Name:         "Envelope",
		Description:  "An envelope.",
		Type:         ItemTypeDecorative,
		Rarity:       RarityUncommon,
		Capacity:     1,
		Movable:      true,
		PossibleLoot: ItemSetBookLoot,
	}
	ItemTypeBedSheet = &ItemType{
		Tile:        's',
		Name:        "Bed Sheet",
		Description: "A bed sheet.",
		Type:        ItemTypeDecorative,
		Rarity:      RarityCommon,
		Movable:     true,
	}
	ItemTypePillow = &ItemType{
		Tile:        'p',
		Name:        "Pillow",
		Description: "A pillow.",
		Type:        ItemTypeDecorative,
		Rarity:      RarityUncommon,
		Movable:     true,
	}
	ItemTypeBlanket = &ItemType{
		Tile:        'b',
		Name:        "Blanket",
		Description: "A blanket.",
		Type:        ItemTypeDecorative,
		Rarity:      RarityCommon,
		Movable:     true,
	}
)
View Source
var (
	ObjectTypeDoor = &ObjectType{
		Tile:        '+',
		Name:        "door",
		Description: "A door.",
		Actions: []*Action{
			&Action{
				Name: "open",
				Func: func(o *Object) {
					fmt.Println("You open the door.")

				},
			},
			&Action{
				Name: "close",
				Func: func(o *Object) {
					fmt.Println("You close the door.")

				},
			},
		},
	}
	ObjectTypeChest = &ObjectType{
		Tile:        'c',
		Name:        "chest",
		Description: "A chest.",
		Actions: []*Action{
			&Action{
				Name: "open",
				Func: func(o *Object) {
					fmt.Println("You open the chest.")

				},
			},
			&Action{
				Name: "close",
				Func: func(o *Object) {
					fmt.Println("You close the chest.")

				},
			},
		},
	}
	ObjectTypeBookshelf = &ObjectType{
		Tile:        'b',
		Name:        "bookshelf",
		Description: "A bookshelf.",
		Actions: []*Action{
			&Action{
				Name: "browse",
				Func: func(o *Object) {
					fmt.Println("You browse the bookshelf.")

				},
			},
		},
	}
)
View Source
var (
	// RoomConfigBedroom is a bedroom.
	RoomConfigBedroom = &RoomConfig{
		Name: "bedroom",
		Condition: func(room *Room, w *World) bool {

			if len(room.Connections) != 1 || room.W < 2 || room.H < 2 || room.W > 10 || room.H > 10 {
				return false
			}
			return true
		},
		Placers: []*Placer{
			placerBed,
			placerDesk,
		},
	}
	// RoomConfigAltar is an altar room.
	RoomConfigAltar = &RoomConfig{
		Name:       "altar",
		HasColumns: true,
		Condition: func(room *Room, w *World) bool {

			if room.W < 10 && room.H < 10 {
				return false
			}
			log.Printf("Found altar room at %d,%d", room.X, room.Y)
			return true
		},
		Placers: []*Placer{
			placerAltar,
		},
	}
	// RoomConfigLibrary is a library.
	RoomConfigLibrary = &RoomConfig{
		Name:       "library",
		HasColumns: true,
		Condition: func(room *Room, w *World) bool {

			if room.W < 4 || room.H < 4 {
				return false
			}
			log.Printf("Found library at %d,%d", room.X, room.Y)
			return true
		},
		Placers: []*Placer{
			placerLibrary,
			placerDesk,
		},
	}
)
View Source
var MonsterEntities = []*EntityType{
	EntityGoblin,
	EntityOrc,
	EntityTroll,
}

Functions

func NewTextbox

func NewTextbox(con *console.Console, width, height int) *textBox

Types

type Action

type Action struct {
	Name string
	Func func(*Object)
}

type Connection

type Connection struct {
	X, Y int // position of the connection
	To   *Room
}

type Entity

type Entity struct {
	Name        string             // name of entity (might be different from EntityType.Name)
	*EntityType                    // type of entity
	Inventory                      // inventory component
	X           int                // x position in the world
	Y           int                // y position in the world
	Health      int                // health points
	Slots       [ItemTypeMax]*Item // Equipped items.
}

func NewEntity

func NewEntity(x, y int, e *EntityType) *Entity

NewEntity returns a new entity with the given position and tile.

func (*Entity) Attack

func (e *Entity) Attack(g *Game, target *Entity)

func (*Entity) AttackDamage

func (e *Entity) AttackDamage() int

func (*Entity) Consume

func (e *Entity) Consume(index int)

Consume consumes the item at the given inventory index.

func (*Entity) DefenseValue

func (e *Entity) DefenseValue() int

func (*Entity) Equip

func (e *Entity) Equip(index int)

Equip equips the item at the given inventory index.

func (*Entity) IsDead

func (e *Entity) IsDead() bool

func (*Entity) TakeDamage

func (e *Entity) TakeDamage(g *Game, damage int)

type EntityType

type EntityType struct {
	Tile              byte
	Name              string
	Description       string // TODO: Generate description to create variety.
	BaseHealth        int
	BaseAttack        int
	BaseDefense       int
	Equipment         []*ItemType
	OptionalEquipment []*ItemType // TODO: Change to item collections.
}

type FOV

type FOV struct {
	Seen   [][]bool // keeps track of tiles that we have seen and remember
	Radius int      // radius of the FOV
	*World          // world to compute the FOV for
}

FOV implements a field of view logic. TODO: Add raycasting or octants. See: http://journal.stuffwithstuff.com/2015/09/07/what-the-hero-sees/

func NewFOV

func NewFOV(w *World, r int) *FOV

NewFOV returns a new FOV struct.

func (*FOV) Clear

func (f *FOV) Clear()

Clear resets all tiles to unseen.

func (*FOV) Compute

func (f *FOV) Compute(x, y int)

Compute sets all tiles within the FOV radius to seen.

func (*FOV) IsInRadius

func (f *FOV) IsInRadius(x, y, x2, y2 int) bool

IsInRadius returns true if the given coordinates are within the FOV radius.

func (*FOV) Update

func (f *FOV) Update(x, y int)

Update clears the FOV and recomputes it for the given position.

type Game

type Game struct {
	Seed   int64 // seed for the world
	Width  int
	Height int
	*World // currently generated world
	*FOV   // currently generated FOV

	Messages []string // messages to display
	// contains filtered or unexported fields
}

func NewGame

func NewGame(gw GenWorld, width, height int, seed int64) (*Game, error)

Initializes a new game. NOTE: A seed of -1 will generate a random seed each time.

func (*Game) AddMessage

func (g *Game) AddMessage(msg string)

func (*Game) HandleInput

func (g *Game) HandleInput(timeElapsed float64) error

func (*Game) Start

func (g *Game) Start()

func (*Game) Update

func (g *Game) Update(screen *ebiten.Image, timeDelta float64) error

type GenWorld

type GenWorld func(width, height int, seed int64) *World

type Inventory

type Inventory struct {
	Items []*Item
}

Inventory represents a collection of items.

func (*Inventory) Add

func (i *Inventory) Add(item *Item)

Add the given item to the inventory.

func (*Inventory) Count

func (i *Inventory) Count() int

Count returns the number of items in the inventory.

func (*Inventory) GetItem

func (i *Inventory) GetItem(index int) *Item

GetItem returns the item with the given index.

func (*Inventory) Remove

func (i *Inventory) Remove(item *Item) *Item

Remove the given item from the inventory and return it.

func (*Inventory) RemoveItem

func (i *Inventory) RemoveItem(index int) *Item

RemoveItem removes the item with the given index from the inventory and returns it.

type Item

type Item struct {
	*ItemType
	Hidden   bool // indicates if the item is hidden
	Equipped bool // indicates if the item is equipped
	X        int  // x position in the world (if dropped)
	Y        int  // y position in the world (if dropped)
	Contains []*Item
}

Item represents an item in the game.

func (Item) Consumable

func (i Item) Consumable() bool

Consumable returns true if the item can be consumed.

func (Item) Equippable

func (i Item) Equippable() bool

Equippable returns true if the item can be equipped.

func (Item) FullName

func (i Item) FullName() string

FullName returns the full name of the item including the modifier.

func (Item) String

func (i Item) String() string

String returns the name of the item.

type ItemSet

type ItemSet struct {
	Name  string
	Items []*ItemType
}

func (*ItemSet) Generate

func (is *ItemSet) Generate() *Item

func (*ItemSet) GenerateN

func (is *ItemSet) GenerateN(n int) []*Item

type ItemType

type ItemType struct {
	Tile         byte
	Name         string
	Description  string
	Type         int
	Modifier     int
	Hidden       bool // indicates if the item is hidden by default
	Movable      bool // indicates if the item can be moved / picked up
	Rarity       *Rarity
	Capacity     int      // indicates the maximum number of items this item can contain
	PossibleLoot *ItemSet // TODO: Allow multiple sets.
	// TODO: Add variants with different rarity.
	// Variants     []*ItemType
	// TODO: Make this a map of event types to functions.
	OnTouch func(*Game, *Entity, *Item) // Trigger function called when item is used.
	OnUse   func(*Game, *Entity, *Item) // Trigger function called when item is used.

}

ItemType represents a type of item.

func (ItemType) Generate

func (i ItemType) Generate() *Item

Generate returns a new item of the given type.

func (ItemType) New

func (i ItemType) New() *Item

New returns a new item of the given type.

type Node

type Node struct {
	Parent *Node
	X, Y   int
}

Node represents a node in the pathfinder.

type Object

type Object struct {
	*ObjectType
	Contains []*Item
}

Object represents an object in the game.

type ObjectType

type ObjectType struct {
	Tile        byte
	Name        string
	Description string
	Size        int
	Capacity    int
	Actions     []*Action
}

ObjectType represents the type of an object. TODO: Unify with items? A sword might have a hidden compartment... A book might contain a letter A shelf might contain various things... A bed might contain a hidden dagger.

func (*ObjectType) New

func (t *ObjectType) New() *Object

NewObject returns a new object of the given type.

type Pathfinder

type Pathfinder struct {
	// contains filtered or unexported fields
}

Pathfinder represents a pathfinder.

func NewPathfinder

func NewPathfinder(w *World, x, y, tx, ty int) *Pathfinder

NewPathfinder creates a new pathfinder.

func (*Pathfinder) FindPath

func (p *Pathfinder) FindPath() []*Node

FindPath finds a path from the start to the end. NOTE: Poor man's A*. TODO: Use heuristics to prioritize the search to nodes that are closer to the end node.

type Placer

type Placer struct {
	Chance   int
	Func     func(*Room, *World) bool
	ItemType *ItemType
	Children []*Placer // Possible accompanying placers.
}

type Rarity

type Rarity struct {
	Name           string // Name of this rarity
	Probability    int    // Probability of this rarity (the higher the more rare)
	IndicateRarity bool   // Indicate rarity in item name
}

Rarity represents the rarity of an item.

func (*Rarity) Roll

func (r *Rarity) Roll() bool

Roll returns true if the item should be generated.

type Room

type Room struct {
	X, Y          int     // top left corner
	W, H          int     // width and height
	E             int     // elevation
	RoundedCorner [4]bool // rounded corners
	Connections   []*Connection
}

Room represents a room in the world. TODO: Store connecting rooms

func (*Room) Connect

func (r *Room) Connect(to *Room, x, y int)

Connect connects the given room to the given room.

func (*Room) Contains

func (r *Room) Contains(x, y int) bool

Contains returns true if the given position is inside the room.

func (*Room) NextToDoor

func (r *Room) NextToDoor(x, y int) bool

NextToDoor returns true if the given position is next to a door.

func (*Room) Overlaps

func (r *Room) Overlaps(rooms []*Room) bool

Overlaps returns true if the given room overlaps with any of the rooms in the list.

func (*Room) RandAlongWall

func (r *Room) RandAlongWall() (x, y int)

RandAlongWall returns a random position along the wall of the room.

func (*Room) Size

func (r *Room) Size() int

Size returns the size of the room in square tiles.

type RoomConfig

type RoomConfig struct {
	Name       string                   // Name of the room type.
	HasColumns bool                     // Indicates if the room has columns.
	HasPuddle  bool                     // Indicates if the room has a puddle.
	Condition  func(*Room, *World) bool // Condition to check if the room can be placed.
	Placers    []*Placer
}

RoomConfig represents a (furnishing) generator configuration for a room type. TODO: Allow for random attributes like, columns, puddles, shape, etc.

func (*RoomConfig) Apply

func (rc *RoomConfig) Apply(room *Room, w *World)

Apply applies the room config to the given room.

type Scene

type Scene interface {
	console.Component
	Close() error
}

type SceneCharacterCreation

type SceneCharacterCreation struct {
	*Game
	*console.ComponentBase
	// contains filtered or unexported fields
}

func NewSceneCharacterCreation

func NewSceneCharacterCreation(rootView *console.Console, world *Game) *SceneCharacterCreation

func (*SceneCharacterCreation) Close

func (g *SceneCharacterCreation) Close() error

func (*SceneCharacterCreation) Draw

func (s *SceneCharacterCreation) Draw(con *console.Console, timeElapsed float64)

func (*SceneCharacterCreation) FocusOnClick

func (s *SceneCharacterCreation) FocusOnClick() bool

func (*SceneCharacterCreation) NewTextbox

func (s *SceneCharacterCreation) NewTextbox(con *console.Console)

func (*SceneCharacterCreation) Update

func (s *SceneCharacterCreation) Update(con *console.Console, timeElapsed float64) bool

type SceneDeath

type SceneDeath struct {
	*Game
	*console.ComponentBase
	// contains filtered or unexported fields
}

func NewSceneDeath

func NewSceneDeath(rootView *console.Console, world *Game) *SceneDeath

func (*SceneDeath) Close

func (g *SceneDeath) Close() error

func (*SceneDeath) Draw

func (s *SceneDeath) Draw(con *console.Console, timeElapsed float64)

func (*SceneDeath) FocusOnClick

func (s *SceneDeath) FocusOnClick() bool

func (*SceneDeath) Update

func (s *SceneDeath) Update(con *console.Console, timeElapsed float64) bool

type SceneMap

type SceneMap struct {
	*Game
	*console.ComponentBase
	// contains filtered or unexported fields
}

func NewSceneMap

func NewSceneMap(rootView *console.Console, world *Game) *SceneMap

func (*SceneMap) Close

func (g *SceneMap) Close() error

func (*SceneMap) Draw

func (g *SceneMap) Draw(con *console.Console, timeElapsed float64)

func (*SceneMap) FocusOnClick

func (g *SceneMap) FocusOnClick() bool

func (*SceneMap) Update

func (g *SceneMap) Update(con *console.Console, timeElapsed float64) bool

type SceneSuccess

type SceneSuccess struct {
	*console.ComponentBase
	*Game
	// contains filtered or unexported fields
}

func NewSceneSuccess

func NewSceneSuccess(rootView *console.Console, world *Game) *SceneSuccess

func (*SceneSuccess) Close

func (g *SceneSuccess) Close() error

func (*SceneSuccess) Draw

func (g *SceneSuccess) Draw(con *console.Console, timeElapsed float64)

func (*SceneSuccess) FocusOnClick

func (s *SceneSuccess) FocusOnClick() bool

func (*SceneSuccess) Update

func (g *SceneSuccess) Update(con *console.Console, timeElapsed float64) bool

type UIif

type UIif interface {
	Draw()
	Select()      // Select selects the current UI element.
	HandleInput() // HandleInput handles input for the current UI element.
}

type ViewMode

type ViewMode int
const (
	ViewModeMap ViewMode = iota
	ViewModeCharacterCreation
	ViewModeDeath
	ViewModeSuccess
	ViewModeMax
)

type World

type World struct {
	Cells     [][]rune    // 2D array of world cells
	Elevation [][]int     // 2D array of elevation values
	Objects   [][]*Object // 2D array of objects like furniture, chests, doors (TODO: Move this to cells)
	Width     int         // width of the world in cells
	Height    int         // height of the world in cells
	Entities  []*Entity   // entities in the world (creatures)
	Items     []*Item     // items in the world
}

World represents a game world.

func GenWorldBigBox

func GenWorldBigBox(width, height int, seed int64) *World

GenWorldBigBox generates a big box world.

func GenWorldSimpleDungeon

func GenWorldSimpleDungeon(width, height int, seed int64) *World

GenWorldSimpleDungeon generates a simple random-walk-ish dungeon. - A starting room is placed in the center of the world. - Rooms are then placed in random directions neighboring a randomly selectd room. - Rooms are not placed if they would overlap with an existing room.

func NewWorld

func NewWorld(width, height int) *World

NewWorld returns a new world with the given width and height.

func (*World) AddRoomColumns

func (w *World) AddRoomColumns(room *Room)

AddRoomColumns adds columns to the given room.

func (*World) AddRoomFountain

func (w *World) AddRoomFountain(room *Room)

AddRoomFountain adds a fountain to the given room.

func (*World) AddRoomFurnishings

func (w *World) AddRoomFurnishings(room *Room)

AddRoomFurnishings adds furnishings to the given room.

func (*World) AddRoomPuddle

func (w *World) AddRoomPuddle(room *Room)

AddRoomPuddle adds a puddle of water to the given room.

func (*World) CanMoveTo

func (w *World) CanMoveTo(x, y int) bool

CanMoveTo checks if a tile is solid and if it is not occupied by an entity.

func (*World) CarveRoom

func (w *World) CarveRoom(room *Room)

CarveRoom sets all tiles occupied by the room to ' '.

func (*World) Fill

func (w *World) Fill(c rune)

Fill all cells with the given tile.

func (*World) InBounds

func (w *World) InBounds(x, y int) bool

InBounds returns true if the given position is within the world bounds.

func (*World) IsEmpty

func (w *World) IsEmpty(x int, y int) bool

IsEmtpy checks if a tile is empty (tile content is a space ' ' character and there is no object there).

func (*World) IsSolid

func (w *World) IsSolid(x int, y int) bool

IsSolid checks if a tile is solid (tile content is not a space ' ' character).

func (*World) NextToWall

func (w *World) NextToWall(x, y int) bool

NextToWall returns true if the given position is next to a wall.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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