Documentation ¶
Overview ¶
Package tcod provides a wrapper around the libtcod C library. Libtcod is a roguelike making toolkit. It provides utilities for emulating an ascii art console. It also offers toolkits for common roguelike operations, like bsp trees, line-of-sight, and pathfinding calculations.
Prerequisites ¶
This library requires you to have the libtcod C library already installed on your system, as it depends on being able to link the -ltcod library.
Minimal Program
package main import ( "log" "github.com/Joakker/tcod-go" "github.com/Joakker/tcod-go/tinput" ) const ( Width = 80 Height = 50 Title = "The Adventures of Go" ) func main() { // Initialize the game window, also known as the root console root, err := tcod.InitRoot(Width, Height, Title, false, tcod.RenderSDL2) // Check if we actually have a window, otherwise present the // error to the user and exit with code 1 if err != nil { log.Fatal(err) } // This struct lets us survey window events input := tinput.Input{} // Continue while the user hasn't requested the window to close for !tcod.WindowClosed() { // First check for user input input.Check() // Then wipe clean the game window root.Clear() // Paint a frame around the window, with a specified title // at the top root.PrintFrame(0, 0, 80, 50, true, Title) // Finally, present the changes to the user tcod.Flush() } }
Index ¶
- Variables
- func CreditsEmbed(x, y int, alpha bool) bool
- func CreditsReset()
- func CreditsScreen()
- func Flush()
- func Fullscreen() bool
- func GetFade() byte
- func MouseFocus() bool
- func SetFade(fade byte, color Color)
- func SetFullscreen(f bool)
- func SetTitle(title string)
- func WindowActive() bool
- func WindowClosed() bool
- type Alignment
- type BgFlag
- type Color
- type Console
- func (c Console) Blit(x, y, w, h int, target Console, x2, y2 int, bgAlpha, fgAlpha float32)
- func (c Console) Clear()
- func (c Console) Delete()
- func (c Console) GetAlign() Alignment
- func (c Console) GetBgFlag() BgFlag
- func (c Console) GetChar(x, y int) byte
- func (c Console) GetCharBg(x, y int) Color
- func (c Console) GetCharFg(x, y int) Color
- func (c Console) GetDefaultBg() Color
- func (c Console) GetDefaultFg() Color
- func (c *Console) GetH() int
- func (c *Console) GetW() int
- func (c Console) HLine(x, y, l int, flag BgFlag)
- func (c *Console) LoadASC(filename string) bool
- func (c Console) Print(x, y int, format string, values ...interface{})
- func (c Console) PrintEx(x, y int, flag BgFlag, alignment Alignment, format string, ...)
- func (c Console) PrintFrame(x, y, w, h int, clear bool, format string, values ...interface{})
- func (c Console) PrintRect(x, y, w, h int, format string, values ...interface{})
- func (c Console) PutChar(x, y int, b byte, flag BgFlag)
- func (c Console) SaveASC(filename string) bool
- func (c Console) SetAlign(align Alignment)
- func (c Console) SetBgFlag(flag BgFlag)
- func (c Console) SetCellBg(x, y int, color Color, flag BgFlag)
- func (c Console) SetCellFg(x, y int, color Color)
- func (c Console) SetChar(x, y int, b byte)
- func (c Console) SetDefaultBg(bg Color)
- func (c Console) SetDefaultFg(fg Color)
- func (c Console) SetKeyColor(color Color)
- func (c Console) VLine(x, y, l int, flag BgFlag)
- type Renderer
Constants ¶
This section is empty.
Variables ¶
var ( // Black color Black = Color{R: 0x14, G: 0x0c, B: 0x1c} // Purple color Purple = Color{R: 0x44, G: 0x24, B: 0x34} // Blue color Blue = Color{R: 0x30, G: 0x34, B: 0x6d} // Grey color Grey = Color{R: 0x4e, G: 0x4a, B: 0x4e} // Brown color Brown = Color{R: 0x85, G: 0x4c, B: 0x30} // Green color Green = Color{R: 0x34, G: 0x65, B: 0x24} // Red color Red = Color{R: 0xd0, G: 0x46, B: 0x48} // Orange color Orange = Color{R: 0xd2, G: 0x7d, B: 0x2c} // Pink color Pink = Color{R: 0xd2, G: 0xaa, B: 0x99} // Cyan color Cyan = Color{R: 0x6d, G: 0xc2, B: 0xca} // Yellow color Yellow = Color{R: 0xda, G: 0xd4, B: 0x5e} // White color White = Color{R: 0xde, G: 0xee, B: 0xd6} // LightGrey color LightGrey = Color{R: 0x85, G: 0x95, B: 0xa1} // LightGreen color LightGreen = Color{R: 0x6d, G: 0xaa, B: 0x2c} // LightCyan color LightCyan = Color{R: 0x75, G: 0x71, B: 0x61} // LightBlue color LightBlue = Color{R: 0x59, G: 0x7d, B: 0xce} )
var ( // CharHLine is char wall HLine CharHLine byte = C.TCOD_CHAR_HLINE // CharVLine is char wall VLine CharVLine byte = C.TCOD_CHAR_VLINE // CharNE is char wall NE CharNE byte = C.TCOD_CHAR_NE // CharNW is char wall NW CharNW byte = C.TCOD_CHAR_NW // CharSE is char wall SE CharSE byte = C.TCOD_CHAR_SE // CharSW is char wall SW CharSW byte = C.TCOD_CHAR_SW // CharTeeW is char wall TeeW CharTeeW byte = C.TCOD_CHAR_TEEW // CharTeeE is char wall TeeE CharTeeE byte = C.TCOD_CHAR_TEEE // CharTeeN is char wall TeeN CharTeeN byte = C.TCOD_CHAR_TEEN // CharTeeS is char wall TeeS CharTeeS byte = C.TCOD_CHAR_TEES // CharDHLine is char double wall HLine CharDHLine byte = C.TCOD_CHAR_DHLINE // CharDVLine is char double wall VLine CharDVLine byte = C.TCOD_CHAR_DVLINE // CharDNE is char double wall NE CharDNE byte = C.TCOD_CHAR_DNE // CharDNW is char double wall NW CharDNW byte = C.TCOD_CHAR_DNW // CharDSE is char double wall SE CharDSE byte = C.TCOD_CHAR_DSE // CharDSW is char double wall SW CharDSW byte = C.TCOD_CHAR_DSW // CharDTeeW is char double wall TeeW CharDTeeW byte = C.TCOD_CHAR_DTEEW // CharDTeeE is char double wall TeeE CharDTeeE byte = C.TCOD_CHAR_DTEEE // CharDTeeN is char double wall TeeN CharDTeeN byte = C.TCOD_CHAR_DTEEN // CharDTeeS is char double wall TeeS CharDTeeS byte = C.TCOD_CHAR_DTEES // CharCheckBoxSet is char CheckBox Set CharCheckBoxSet byte = C.TCOD_CHAR_CHECKBOX_SET // CharCheckBoxUnset is char CheckBox Unset CharCheckBoxUnset byte = C.TCOD_CHAR_CHECKBOX_UNSET // CharRadioSet is char Radio Set CharRadioSet byte = C.TCOD_CHAR_RADIO_SET // CharRadioUnset is char Radio Unset CharRadioUnset byte = C.TCOD_CHAR_RADIO_UNSET // CharSubpNW char subpixel NW CharSubpNW byte = C.TCOD_CHAR_SUBP_NW // CharSubpNE char subpixel NE CharSubpNE byte = C.TCOD_CHAR_SUBP_NE // CharSubpSW char subpixel SW CharSubpSW byte = C.TCOD_CHAR_SUBP_SW // CharSubpSE char subpixel SE CharSubpSE byte = C.TCOD_CHAR_SUBP_SE // CharSubpDiag char subpixel Diag CharSubpDiag byte = C.TCOD_CHAR_SUBP_DIAG // CharSubpN char subpixel N CharSubpN byte = C.TCOD_CHAR_SUBP_N // CharSubpE char subpixel E CharSubpE byte = C.TCOD_CHAR_SUBP_E // CharBlock1 char block 1 CharBlock1 byte = C.TCOD_CHAR_BLOCK1 // CharBlock2 char block 2 CharBlock2 byte = C.TCOD_CHAR_BLOCK2 // CharBlock3 char block 3 CharBlock3 byte = C.TCOD_CHAR_BLOCK3 // CharArrowN char arrow N CharArrowN byte = C.TCOD_CHAR_ARROW_N // CharArrowE char arrow E CharArrowE byte = C.TCOD_CHAR_ARROW_E // CharArrowS char arrow S CharArrowS byte = C.TCOD_CHAR_ARROW_S // CharArrowW char arrow W CharArrowW byte = C.TCOD_CHAR_ARROW_W // CharArrowNTN is char arrow no tail N CharArrowNTN byte = C.TCOD_CHAR_ARROW2_N // CharArrowNTE is char arrow no tail E CharArrowNTE byte = C.TCOD_CHAR_ARROW2_E // CharArrowNTS is char arrow no tail S CharArrowNTS byte = C.TCOD_CHAR_ARROW2_S // CharArrowNTW is char arrow no tail W CharArrowNTW byte = C.TCOD_CHAR_ARROW2_W // CharCross is char Cross CharCross byte = C.TCOD_CHAR_CROSS // CharHeart is char Heart CharHeart byte = C.TCOD_CHAR_HEART // CharDiamond is char Diamond CharDiamond byte = C.TCOD_CHAR_DIAMOND // CharClub is char Club CharClub byte = C.TCOD_CHAR_CLUB // CharSpade is char Spade CharSpade byte = C.TCOD_CHAR_SPADE // CharMale is char Male CharMale byte = C.TCOD_CHAR_MALE // CharFemale is char Female CharFemale byte = C.TCOD_CHAR_FEMALE // CharLight is char Light CharLight byte = C.TCOD_CHAR_LIGHT // CharPilcrow is char Pilcrow CharPilcrow byte = C.TCOD_CHAR_PILCROW // CharSection is char Section CharSection byte = C.TCOD_CHAR_SECTION // CharPound is char Pound CharPound byte = C.TCOD_CHAR_POUND // CharMultiplication is char Multiplication CharMultiplication byte = C.TCOD_CHAR_MULTIPLICATION // CharFunction is char Function CharFunction byte = C.TCOD_CHAR_FUNCTION // CharReserved is char Reserved CharReserved byte = C.TCOD_CHAR_RESERVED // CharHalf is char Half CharHalf byte = C.TCOD_CHAR_HALF // CharCent is char Cent CharCent byte = C.TCOD_CHAR_CENT // CharYen is char Yen CharYen byte = C.TCOD_CHAR_YEN // CharCurrency is char Currency CharCurrency byte = C.TCOD_CHAR_CURRENCY // CharDivision is char Division CharDivision byte = C.TCOD_CHAR_DIVISION // CharGrade is char Grade CharGrade byte = C.TCOD_CHAR_GRADE // CharUmlaut is char Umlaut CharUmlaut byte = C.TCOD_CHAR_UMLAUT // CharPow1 Char Pow 1 CharPow1 byte = C.TCOD_CHAR_POW1 // CharPow2 Char Pow 2 CharPow2 byte = C.TCOD_CHAR_POW2 // CharPow3 Char Pow 3 CharPow3 byte = C.TCOD_CHAR_POW3 // CharDArrowH Char DArrowH CharDArrowH byte = C.TCOD_CHAR_DARROW_H // CharDArrowV Char DArrowV CharDArrowV byte = C.TCOD_CHAR_DARROW_V // CharSmilie is char Smilie - CharSmilie byte = C.TCOD_CHAR_SMILIE // CharBullet is char Bullet - CharBullet byte = C.TCOD_CHAR_BULLET // CharSmilieInv is char Smilie Inv CharSmilieInv byte = C.TCOD_CHAR_SMILIE_INV // CharBulletInv is char Bullet Inv CharBulletInv byte = C.TCOD_CHAR_BULLET_INV // CharNote Char Note CharNote byte = C.TCOD_CHAR_NOTE // CharNoteDouble Char NoteDouble CharNoteDouble byte = C.TCOD_CHAR_NOTE_DOUBLE // CharOneQuarter Char OneQuarter CharOneQuarter byte = C.TCOD_CHAR_ONE_QUARTER // CharBulletSquare Char BulletSquare CharBulletSquare byte = C.TCOD_CHAR_BULLET_SQUARE )
Functions ¶
func CreditsEmbed ¶
CreditsEmbed renders the message in CreditsScreen, but instead of taking the entire screen, it will be presented at the specified coordinates, and the alpha argument determines whether it should be drawn transparently, i.e., not overwriting existing images at that position. Similar to Print, the alignment of the root console will determine if the coordinates are the center of the image or one of it's corners. The function should be called over multiple frames, as every time, it renders the next frame in the animation. For example:
endCredits := false for !tcod.WindowClosed() { if !endCredits { endCredits = tcod.CreditsEmbed(25, 25, true) } }
The function will return false while the animation is not finished.
func CreditsScreen ¶
func CreditsScreen()
CreditsScreen presents an animated screen with a message of the form "Powered by libtcod x.y.z". It halts the progression of the program, so it's best to call it as a splash screen right after the window has been created, rather than in the game loop. Any key press will interrupt the spash screen and give control back to the program.
root, err := tcod.InitRoot(80, 50, "The Adventures of Go", false, tcod.RenderSDL2) if err != nil { log.Fatal(err) } // The program will stop here until the animation is finished or the user // presses a key tcod.CreditsScreen() for !tcod.WindowClosed() { // Game Loop goes here }
func Fullscreen ¶
func Fullscreen() bool
Fullscreen returns true if the game window is in fullscreen mode
func GetFade ¶ added in v0.2.0
func GetFade() byte
GetFade returns the fading strength of the game window
func MouseFocus ¶
func MouseFocus() bool
MouseFocus returns true if the mouse is within the game window
func SetFade ¶ added in v0.2.0
SetFade sets the fading strength and color of the game window. A fade of 0 means the screen is filled, while a fade of 255 means no fading effect. You can make a fading animation easily by doing something like this
for i := byte(0); i < 255; i-- { tcod.SetFade(fade, tcod.Black) tcod.Flush() }
This way, the screen will quickly fade to black. The fading parameters are persistent, so once you call them, they stay like that until you change them again.
func SetFullscreen ¶
func SetFullscreen(f bool)
SetFullscreen makes the game window enter or exit fullscreen mode
func SetTitle ¶
func SetTitle(title string)
SetTitle sets the window title to the specified argument
func WindowActive ¶
func WindowActive() bool
WindowActive returns true if the game window is currently active
func WindowClosed ¶
func WindowClosed() bool
WindowClosed returns true if the game window has been closed
Types ¶
type Alignment ¶ added in v0.1.2
type Alignment int
Alignment enum
var ( // AlignCenter makes everything align at the center AlignCenter Alignment = C.TCOD_CENTER // AlignLeft makes everything align to the left AlignLeft Alignment = C.TCOD_LEFT // AlignRight makes everything align to the right AlignRight Alignment = C.TCOD_RIGHT )
type BgFlag ¶
type BgFlag int
BgFlag enum
var ( // BgNone no changes BgNone BgFlag = C.TCOD_BKGND_NONE // BgSet replaces the cell's background color with the default BgSet BgFlag = C.TCOD_BKGND_SET // BgMultiply multiplies the current background color with the default BgMultiply BgFlag = C.TCOD_BKGND_MULTIPLY // BgLighten makes the background the lightest between the old and current BgLighten BgFlag = C.TCOD_BKGND_LIGHTEN // BgDarken makes the background the darkest between the old and current BgDarken BgFlag = C.TCOD_BKGND_DARKEN // BgScreen makes the background the inverse of Multiply BgScreen BgFlag = C.TCOD_BKGND_SCREEN // BgAdd adds the current and old background colors BgAdd BgFlag = C.TCOD_BKGND_ADD // BgBurn apply a burn effect BgBurn BgFlag = C.TCOD_BKGND_BURN // BgOverlay overlays both colors BgOverlay BgFlag = C.TCOD_BKGND_OVERLAY // BgDefault default background BgDefault BgFlag = C.TCOD_BKGND_DEFAULT )
type Color ¶
type Color struct {
R, G, B byte
}
Color represents a colour
func GetFadeColor ¶ added in v0.2.0
func GetFadeColor() Color
GetFadeColor returns the fading color of the game window
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
Console is a wrapper around the C struct of the same name.
func InitRoot ¶
InitRoot initializes the game window, also known as the root console. It creates a console that is w tiles wide and h tiles high, with the given window title and using the specified renderer, and in fullscreen if so desired. The newly created window will make use of the default font image, bundled with this library in binary form, if no image has been selected explicitly by calling SetFontImage before calling this function.
func NewConsole ¶
NewConsole creates a console of size w by h cells
func NewConsoleASC ¶
NewConsoleASC creates a console from the .asc image specified by filename
func (Console) Blit ¶
Blit renders the console's contents to the target, within the specified coordinates. For example:
c := tcod.NewConsole(100, 100) c.Blit(0, 0, 10, 10, root, 5, 5, 5.0f, 5.0f)
renders the contents of c in the coordinates from (0, 0) to (10, 10), to the root console starting from coordinates (5, 5), using the specified background and foreground alpha.
func (Console) Clear ¶
func (c Console) Clear()
Clear wipes out all cells in the console, leaving it completely clean
func (Console) Delete ¶
func (c Console) Delete()
Delete deletes the console from memory. In most cases you shouldn't have to worry about calling this method, as the Go garbage collector would take care of it. It only works with consoles created by the NewConsole function, not with the root one.
func (Console) GetCharBg ¶ added in v0.2.0
GetCharBg returns the background color at a specific coordinate
func (Console) GetCharFg ¶ added in v0.2.0
GetCharFg returns the foreground color at a specific coordinate
func (Console) GetDefaultBg ¶ added in v0.2.0
GetDefaultBg returns the default background colour of a console
func (Console) GetDefaultFg ¶ added in v0.2.0
GetDefaultFg returns the default foreground colour of a console
func (Console) HLine ¶ added in v0.1.2
HLine renders a horizontal line starting at (x, y) and extending leftward for l cells
func (*Console) LoadASC ¶
LoadASC loads a .asc ascii art file specified by filename, and writes the contents to the console, returning true if the operation was successful. Files with the .asc extension are created by the Ascii Paint program. For exaple, suppose you have a foo.asc file, so if you want to load them onto a console, simply call
c := tcod.NewConsole(40, 40) c.LoadASC("foo.asc")
and the file contents will be rendered to that console. Of course, you still have to blit the console onto the root one to see it.
func (Console) Print ¶
Print renders the given text to the console, using the cell at position (x, y) as a starting point. The console's alignment will tell whether to use it as the center of the text, or one of it's ends. You can use Go style escape sequences in the format parameter to have them formatted like in fmt.Sprintf. This means, however, that you are currently unable to format in Char* constants, as Sprintf won't render them as their binary values, but instead will put a space in it's place.
func (Console) PrintEx ¶ added in v0.2.0
func (c Console) PrintEx(x, y int, flag BgFlag, alignment Alignment, format string, values ...interface{})
PrintEx renders the given text to the console, using the specified background flag and alignment. You can use Go style escape sequences in the format parameter to have them formatted like in fmt.Sprintf. This means, however, that you are currently unable to format in Char* constants, as Sprintf won't render them as their binary values, but instead will put a space in it's place.
func (Console) PrintFrame ¶
PrintFrame prints a frame to the console. The frame has a space above to print the string specified by title. The argument clear tells whether the region within the frame should be cleared out or left alone. You can use Go style escape sequences in the format parameter to have them formatted like in fmt.Sprintf. This means, however, that you are currently unable to format in Char* constants, as Sprintf won't render them as their binary values, but instead will put a space in it's place.
func (Console) PrintRect ¶ added in v0.2.0
PrintRect renders a string to the console within the given bounds, that is, with autowrap. You can use Go style escape sequences in the format parameter to have them formatted like in fmt.Sprintf. This means, however, that you are currently unable to format in Char* constants, as Sprintf won't render them as their binary values, but instead will put a space in it's place.
func (Console) PutChar ¶ added in v0.1.2
PutChar sets the character of a cell and it's background flag
func (Console) SaveASC ¶
SaveASC creates an Ascii Paint file from the current contents of the console, and saves them to the specified filename, returning true if the operation was successful.
func (Console) SetCellBg ¶ added in v0.1.2
SetCellBg sets the background colour and flag at the given coordinates
func (Console) SetCellFg ¶ added in v0.1.2
SetCellFg sets the foreground colour at the given coordinates
func (Console) SetChar ¶ added in v0.1.2
SetChar renders a single character to the given coordinates
func (Console) SetDefaultBg ¶
SetDefaultBg sets which color a console's background should have by default. For example:
c := tcod.NewConsole(10, 10) c.SetDefaultBg(tcod.Sky)
makes the created Console to use the Sky color as its background instead of the default black.
func (Console) SetDefaultFg ¶
SetDefaultFg sets which color a console's foreground should have by default, similar to SetDefaultBg. For example:
c := tcod.NewConsole(10, 10) c.SetDefaultFg(tcod.Gold)
makes the created console to use the Gold color as it's foreground instead of the default white.
func (Console) SetKeyColor ¶
SetKeyColor sets which color should be treated as transparent when blitting it onto another console. For example:
c := tcod.NewConsole(10, 10) c.SetKeyColor(tcod.Magenta)
will tell the program that it should treat any cell with Magenta background as transparent when blitting it to another console. The foreground remmains untouched.
type Renderer ¶
type Renderer int
Renderer enum
var ( // RenderSDL renderer RenderSDL Renderer = C.TCOD_RENDERER_SDL // RenderSDL2 renderer RenderSDL2 Renderer = C.TCOD_RENDERER_SDL2 // RenderOpenGL renderer RenderOpenGL Renderer = C.TCOD_RENDERER_OPENGL // RenderOpenGL2 renderer RenderOpenGL2 Renderer = C.TCOD_RENDERER_OPENGL2 )
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package assets is generated by github.com/omeid/go-resources
|
Package assets is generated by github.com/omeid/go-resources |
examples
|
|
simple
Package main defines a simple roguelike
|
Package main defines a simple roguelike |
Package tinput provides utilities to monitor user input on windows created by the tcod package
|
Package tinput provides utilities to monitor user input on windows created by the tcod package |
Package tmap defines utility functions to work with maps
|
Package tmap defines utility functions to work with maps |
Package tsys offers system interfaces for games created using the tcod package.
|
Package tsys offers system interfaces for games created using the tcod package. |