Documentation
¶
Index ¶
- Constants
- func ConnectExits(startDungeon *Dungeon, startLevel *Level, destinationDungeon *Dungeon, ...)
- func GetDiceRoll(num int) int
- func GetRandomBetween(low int, high int) int
- func GetRandomInt(num int) int
- func InitializeWorld(startingLevel Level)
- type AStar
- type Actionable
- type Character
- type Creature
- func (c *Creature) Approach()
- func (c *Creature) Avoid()
- func (c Creature) Draw()
- func (c Creature) GetPosition() Position
- func (c Creature) GetSpeed() int
- func (c *Creature) IsVisible() bool
- func (c Creature) Kind() string
- func (c Creature) Move(dx, dy int)
- func (c Creature) MoveTo(pos Position)
- func (c Creature) Name() string
- func (c *Creature) SetBehavior(b CreatureBehavior)
- func (c Creature) SetImage(img *firefly.Image)
- func (c Creature) SetSpeed(speed int)
- func (c *Creature) SetVisible(visible bool)
- func (c *Creature) Update()
- type CreatureBehavior
- type DebugAction
- type Dialog
- type Dungeon
- type FieldOfVision
- type Game
- func (g *Game) AddCreature(c Character)
- func (g *Game) CurrentDungeon() *Dungeon
- func (g *Game) CurrentLevel() *Level
- func (g *Game) GetCreatureByName(name string) Character
- func (g *Game) GetCreatureForTile(index int) Character
- func (g *Game) GetIndexFromXY(x int, y int) int
- func (g *Game) Layout(w, h int) (int, int)
- func (g *Game) LoadImage(name string) *firefly.Image
- func (g *Game) LoadImages(names ...string)
- func (g *Game) NextDungeon() *Dungeon
- func (g *Game) RemoveCreature(c Character)
- func (g *Game) Render()
- func (g *Game) SetActionSystem(a Actionable)
- func (g *Game) SetData(d GameData)
- func (g *Game) SetMap(m *GameMap)
- func (g *Game) SetPlayer(p Character)
- func (g *Game) ShowDialog(dlg *Dialog)
- func (g *Game) Update()
- type GameData
- type GameMap
- func NewGameMap(name string, dungeons []Dungeon, startDungeon string, startLevel string) *GameMap
- func NewGeneratedGameMap(name string, dungeonCount int, levelCount int, floors, walls string) *GameMap
- func NewSingleGameMapWithTerrain(floors, walls string) *GameMap
- func NewSingleLevelGameMap() *GameMap
- type Image
- type Level
- func (level *Level) Block(pos Position, block bool)
- func (level *Level) Draw()
- func (level *Level) Dump()
- func (level *Level) Generate()
- func (level *Level) GetEntrancePosition() Position
- func (level *Level) GetExitPosition() Position
- func (level *Level) GetIndexFromXY(x int, y int) int
- func (level *Level) GetRoom(x, y int) int
- func (level *Level) InBounds(x, y int) bool
- func (level *Level) IsOpaque(x, y int) bool
- func (level *Level) OpenLocation() Position
- func (level *Level) RandomLocation() (Position, bool)
- func (level *Level) SetEntrance(p *Portal, pos Position)
- func (level *Level) SetExit(p *Portal, pos Position)
- type MapTile
- type Player
- func (c Player) Draw()
- func (c Player) GetPosition() Position
- func (c Player) GetSpeed() int
- func (p *Player) IsVisible() bool
- func (c Player) Kind() string
- func (c Player) Move(dx, dy int)
- func (c Player) MoveTo(pos Position)
- func (c Player) Name() string
- func (c Player) SetImage(img *firefly.Image)
- func (c Player) SetSpeed(speed int)
- func (p *Player) SetVisible(visible bool)
- func (p *Player) Update()
- type Portal
- type Position
- type Rect
- type TileType
- type TurnState
Constants ¶
const ( BeforePlayerAction = iota PlayerTurn CreatureTurn GameOver )
Variables ¶
This section is empty.
Functions ¶
func ConnectExits ¶ added in v0.2.0
func ConnectExits(startDungeon *Dungeon, startLevel *Level, destinationDungeon *Dungeon, destinationLevel *Level)
ConnectExits connects the exits of two levels. Should only be called after both the startLevel and destinationLevel have been generated.
func GetDiceRoll ¶
GetDiceRoll returns an integer from 1 to the number
func GetRandomBetween ¶
Return a number between two numbers inclusive.
func GetRandomInt ¶
GetRandomInt returns an integer from 0 to the number - 1
func InitializeWorld ¶
func InitializeWorld(startingLevel Level)
InitializeWorld sets up the game world with the starting level.
Types ¶
type Actionable ¶
Actionable is an interface for actions that can be taken by characters.
type Character ¶
type Character interface {
Name() string
Kind() string
SetImage(img *firefly.Image)
GetSpeed() int
SetSpeed(speed int)
GetPosition() Position
Move(dx, dy int)
MoveTo(pos Position)
Draw()
Update()
IsVisible() bool
SetVisible(visible bool)
}
Character is the interface for all characters in the game.
type Creature ¶
type Creature struct {
CurrentBehavior CreatureBehavior
Visible bool
// contains filtered or unexported fields
}
Creature is the type for all creatures in the game.
func NewCreature ¶
NewCreature creates a new Creature and initializes the data
func (*Creature) Approach ¶
func (c *Creature) Approach()
Approach moves the creature towards the player.
func (Creature) GetPosition ¶
func (c Creature) GetPosition() Position
GetPosition returns the position of the character.
func (Creature) GetSpeed ¶
func (c Creature) GetSpeed() int
GetSpeed returns the speed of the character. Lower is faster.
func (Creature) Move ¶
func (c Creature) Move(dx, dy int)
Move moves the character by the given amount.
func (Creature) MoveTo ¶
func (c Creature) MoveTo(pos Position)
MoveTo moves the character to the given position.
func (*Creature) SetBehavior ¶
func (c *Creature) SetBehavior(b CreatureBehavior)
SetBehavior sets the behavior of the creature.
func (Creature) SetSpeed ¶
func (c Creature) SetSpeed(speed int)
SetSpeed sets the speed of the character. Lower is faster.
func (*Creature) SetVisible ¶
type CreatureBehavior ¶
type CreatureBehavior int
const ( CreatureIgnore CreatureBehavior = iota CreatureApproach CreatureAvoid )
type DebugAction ¶
type DebugAction struct {
}
func (*DebugAction) Action ¶
func (da *DebugAction) Action(sender Character, receiver Character)
type Dialog ¶
type Dialog struct {
Font *firefly.Font
FontColor firefly.Color
FillColor firefly.Color
Text1 string
Text2 string
NeedsConfirmation bool
Confirmed bool
Point firefly.Point
Size firefly.Size
// contains filtered or unexported fields
}
Dialog is a simple dialog box that can be displayed to the player.
type Dungeon ¶
Dungeon is a container for all the levels that make up a particular dungeon in the world.
func NewDungeon ¶ added in v0.2.0
NewDungeon creates a new Dungeon with the given name.
func (*Dungeon) CreateLevels ¶ added in v0.2.0
CreateLevels creates a number of empty levels in the dungeon.
type FieldOfVision ¶
type FieldOfVision struct {
// contains filtered or unexported fields
}
FieldOfVision represents an area that an entity can see, defined by the torch radius. The cos and sin tables are generated once on instantiation, so we don't have to build them each time we want to calculate visible distances.
func (*FieldOfVision) InitializeFOV ¶
func (f *FieldOfVision) InitializeFOV()
InitializeFOV generates the cos and sin tables, for 360 degrees, for use when raycasting to determine line of sight
func (*FieldOfVision) RayCast ¶
func (f *FieldOfVision) RayCast(playerX, playerY int, m *Level)
RayCast casts out rays each degree in a 360 circle from the player. If a ray passes over a floor (does not block sight) tile, keep going, up to the maximum torch radius (view radius) of the player. If the ray intersects a wall (blocks sight), stop, as the player will not be able to see past that. Every visible tile will get the Visible and Explored properties set to true.
func (*FieldOfVision) SetAllInvisible ¶
func (f *FieldOfVision) SetAllInvisible(m *Level)
Equal to the code that used to live in main's game:clearFOV() SetAllInvisible makes all tiles on the gamemap invisible to the player.
func (*FieldOfVision) SetTorchRadius ¶
func (f *FieldOfVision) SetTorchRadius(radius int)
SetTorchRadius sets the radius of the FOVs torch, or how far the entity can see
type Game ¶
type Game struct {
Debug bool
Map *GameMap
Data GameData
// TurnBased is a flag to determine if the game is turn based or real-time.
TurnBased bool
Turn TurnState
TurnCounter int
// Player and Creatures
Player Character
Creatures []Character
// Images that are cached for space efficiency. Used for tiles and creatures.
Images map[string]firefly.Image
// UseFOV is a flag to determine if the game should use Field of View.
UseFOV bool
// ActionSystem is the interface for the game to handle actions between characters.
ActionSystem Actionable
// DialogShowing is a flag to determine if a dialog is currently showing.
DialogShowing bool
// contains filtered or unexported fields
}
Game holds all data the entire game will need.
func (*Game) AddCreature ¶
AddCreature adds a creature to the game.
func (*Game) CurrentDungeon ¶ added in v0.2.0
CurrentDungeon returns the current Dungeon for game.
func (*Game) CurrentLevel ¶ added in v0.1.3
CurrentLevel returns the current level for game.
func (*Game) GetCreatureByName ¶
GetCreatureByName returns a creature by name.
func (*Game) GetCreatureForTile ¶
GetCreatureForTile returns the creature for the given tile index.
func (*Game) GetIndexFromXY ¶
GetIndexFromXY returns the index for the given x and y coordinates.
func (*Game) Layout ¶
Layout accepts an outside size, which is a window size on desktop, and returns the game's logical screen size.
func (*Game) LoadImage ¶
LoadImage loads a single image and caches it for later use. It returns a pointer to the image.
func (*Game) LoadImages ¶ added in v0.2.0
LoadImages loads a list of image and caches them for later use.
func (*Game) NextDungeon ¶ added in v0.2.0
NextDungeon returns the next Dungeon for game.
func (*Game) RemoveCreature ¶
RemoveCreature removes a creature from the game.
func (*Game) SetActionSystem ¶
func (g *Game) SetActionSystem(a Actionable)
SetActionSystem sets the action system for the game.
func (*Game) ShowDialog ¶
ShowDialog shows a dialog on the screen.
type GameData ¶
type GameData struct {
Cols int
Rows int
TileWidth int
TileHeight int
MinSize int
MaxSize int
MaxRooms int
FloorTypes string
WallTypes string
}
GameData holds the values for the size of elements within the game
func NewGameData ¶
NewGameData creates a fully populated GameData Struct.
func (*GameData) GameHeight ¶
GameHeight returns the height of the game in pixels.
type GameMap ¶
GameMap holds all the level and aggregate information for the entire world.
func NewGameMap ¶
NewGameMap creates a new set of maps for the entire game Using the predefined levels and dungeons.
func NewGeneratedGameMap ¶ added in v0.2.0
func NewGeneratedGameMap(name string, dungeonCount int, levelCount int, floors, walls string) *GameMap
NewGeneratedGameMap generated a new set of dungeons and levels for the entire game.
func NewSingleGameMapWithTerrain ¶ added in v0.2.0
NewSingleGameMapWithTerrain creates a single level generated game map.
func NewSingleLevelGameMap ¶ added in v0.2.0
func NewSingleLevelGameMap() *GameMap
NewSingleGameMap creates a single level generated game map.
func (*GameMap) NextDungeon ¶ added in v0.2.0
NextDungeon returns the next Dungeon in the list.
func (*GameMap) SetCurrentLevel ¶ added in v0.2.0
SetCurrentLevel sets the current Dungeon and Level in the game map.
type Level ¶
type Level struct {
Name string
Generated bool
Tiles []*MapTile
Rooms []Rect
FloorTypes string
WallTypes string
ViewRadius int
Entrance *Portal
Exit *Portal
}
Level holds the tile information for a complete dungeon level.
func (*Level) Generate ¶ added in v0.2.0
func (level *Level) Generate()
Generate creates a new Dungeon Level Map.
func (*Level) GetEntrancePosition ¶ added in v0.2.0
GetEntrancePosition returns the position of the entrance for this level.
func (*Level) GetExitPosition ¶ added in v0.2.0
GetExitPosition returns the position of the exit for this level.
func (*Level) GetIndexFromXY ¶
Tiles will be stored in one slice. We will use GetIndexFromXY to determine which tile to return. GetIndexFromXY gets the index of the map array from a given X,Y TILE coordinate. This coordinate is logical tiles, not pixels.
func (*Level) InBounds ¶
InBounds checks if the given x and y coordinates are within the level bounds.
func (*Level) IsOpaque ¶
IsOpaque checks if the given x and y coordinates are within the level bounds.
func (*Level) OpenLocation ¶ added in v0.1.3
OpenLocation returns an open location in the level. Used for "spawning".
func (*Level) RandomLocation ¶
RandomLocation returns a random location in the level.
func (*Level) SetEntrance ¶ added in v0.2.0
SetEntrance sets the entrance to the level.
type MapTile ¶
type MapTile struct {
PixelX int // Upper left corner of the tile
PixelY int
Blocked bool // tile should block the player or creatures?
Image *firefly.Image // image for this tile
Visible bool
Explored bool
TileType TileType
}
Each of the map tiles will be represented by one of these structures
type Player ¶
type Player struct {
ViewRadius int
// contains filtered or unexported fields
}
Player represents the player character in the game.
func (Player) GetPosition ¶
func (c Player) GetPosition() Position
GetPosition returns the position of the character.
func (Player) GetSpeed ¶
func (c Player) GetSpeed() int
GetSpeed returns the speed of the character. Lower is faster.
func (Player) MoveTo ¶
func (c Player) MoveTo(pos Position)
MoveTo moves the character to the given position.
func (Player) SetSpeed ¶
func (c Player) SetSpeed(speed int)
SetSpeed sets the speed of the character. Lower is faster.
func (*Player) SetVisible ¶
SetVisible is just here to fulfill Character interface.
type Portal ¶ added in v0.2.0
type Portal struct {
PortalType string
Visible bool
Image *firefly.Image
DungeonName string
DestinationName string
}
Portal is the type for all portals between levels in the game.
func (*Portal) Destination ¶ added in v0.2.0
Destination returns the Level this portal leads to.
type Position ¶
Position represents a position in 2D space.
func (*Position) GetManhattanDistance ¶
GetManhattanDistance returns the Manhattan distance between this position and another.
type Rect ¶
Rect represents a rectangle in 2D space.