tcod

package module
v0.4.1-0...-b6f638d Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 6 Imported by: 0

README

tcod-go

PkgGoDev Go Report Card Build Status codecov

forthebadge

tcod-go is a wrapper of the libtcod library to the Go language.

Installation

  • You must have the libtcod library already installed. This can be done by following the instructions in that repo.
  • You must also have the SDL2 development files installed. You can get them from your package manager or directly from the website, but if you are compiling libtcod from source, you should already have them.
  • Finally, you also need pkg-config to find the above packages.

Assuming you have the go executable in your PATH and you have set up the GOPATH environment variable, simply run:

go get -v "github.com/Joakker/tcod-go"

and go should do everything else for you.

Unlike the C library, this binding provides a default font image, so you don't need to provide your own.

Minimal Program

Copy this into your text editor of choice and go run it

package main

import (
    "log"

    "github.com/Joakker/tcod-go"
    "github.com/Joakker/tcod-go/tinput"
)

func main() {
    root, err := tcod.InitRoot(80, 50, "The adventures of Go", false, tcod.RenderSDL2)

    if err != nil {
        log.Fatal(err)
    }

    i := tinput.NewInput()

    for !tcod.WindowClosed() {
        i.Check()
        root.Clear()
            root.PrintFrame(0, 0, 80, 50, false, "The adventures of Go")
        tcod.Flush()
    }
}

You should get something more or less like this:

example

In the future there should be a complete tutorial in this repo's wiki.

Contributing

Pull requests are not only welcome but encouraged. I started working on this project very recently, so there is still a lot to be done, and even more I may be overlooking.

License

See here

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

Constants

This section is empty.

Variables

View Source
var (
	// CharSmiley is Char 0x263A
	CharSmiley rune = 0x263A
	// CharSmileyInv is Char 0x263B
	CharSmileyInv rune = 0x263B
	// CharHeart is Char 0x2665
	CharHeart rune = 0x2665
	// CharDiamond is Char 0x2666
	CharDiamond rune = 0x2666
	// CharClub is Char 0x2663
	CharClub rune = 0x2663
	// CharSpade is Char 0x2660
	CharSpade rune = 0x2660
	// CharBullet is Char 0x2022
	CharBullet rune = 0x2022
	// CharBulletActive is Char 0x25D8
	CharBulletActive rune = 0x25D8
	// CharBulletInv is Char 0x25CB
	CharBulletInv rune = 0x25CB
	// CharBulletInvActive is Char 0x25D9
	CharBulletInvActive rune = 0x25D9
	// CharMale is Char 0x2642
	CharMale rune = 0x2642
	// CharFemale is Char 0x2640
	CharFemale rune = 0x2640
	// CharNote is Char 0x266A
	CharNote rune = 0x266A
	// CharDoubleNote is Char 0x266B
	CharDoubleNote rune = 0x266B
	// CharStar is Char 0x263C
	CharStar rune = 0x263C
	// CharTriangleArrowR is Char 0x25BA
	CharTriangleArrowR rune = 0x25BA
	// CharTriangleArrowL is Char 0x25C4
	CharTriangleArrowL rune = 0x25C4
	// CharDoubleArrowV is Char 0x2195
	CharDoubleArrowV rune = 0x2195
	// CharDoubleExclamation is Char 0x203C
	CharDoubleExclamation rune = 0x203C
	// CharPilcrow is Char 0x00B6
	CharPilcrow rune = 0x00B6
	// CharLamp is Char 0x00A7
	CharLamp rune = 0x00A7
	// CharUnderBlock is Char 0x25AC
	CharUnderBlock rune = 0x25AC
	// CharDoubleArrowVertUnderscore is Char 0x21A8
	CharDoubleArrowVertUnderscore rune = 0x21A8
	// CharArrowUp is Char 0x2191
	CharArrowUp rune = 0x2191
	// CharArrowDown is Char 0x2193
	CharArrowDown rune = 0x2193
	// CharArrowRight is Char 0x2192
	CharArrowRight rune = 0x2192
	// CharArrowLeft is Char 0x2190
	CharArrowLeft rune = 0x2190
	// CharRightAngle is Char 0x221F
	CharRightAngle rune = 0x221F
	// CharDoubleArrowH is Char 0x2194
	CharDoubleArrowH rune = 0x2194
	// CharTriangleArrowU is Char 0x25B2
	CharTriangleArrowU rune = 0x25B2
	// CharTriangleArrowD is Char 0x25BC
	CharTriangleArrowD rune = 0x25BC
	// CharHouse is Char 0x2302
	CharHouse rune = 0x2302
	// CharUpperCedilla UpperCedilla
	CharUpperCedilla rune = 128
	// CharULowermlaut ULowermlaut
	CharULowermlaut rune = 129
	// CharELowerAcute ELowerAcute
	CharELowerAcute rune = 130
	// CharALowerCaret ALowerCaret
	CharALowerCaret rune = 131
	// CharALowerUmlaut ALowerUmlaut
	CharALowerUmlaut rune = 132
	// CharALowerGrave ALowerGrave
	CharALowerGrave rune = 133
	// CharALowerCircle ALowerCircle
	CharALowerCircle rune = 134
	// CharLowerCedilla LowerCedilla
	CharLowerCedilla rune = 135
	// CharELowerCaret ELowerCaret
	CharELowerCaret rune = 136
	// CharELowerUmlaut ELowerUmlaut
	CharELowerUmlaut rune = 137
	// CharELowerGrave ELowerGrave
	CharELowerGrave rune = 138
	// CharILowerUmlaut ILowerUmlaut
	CharILowerUmlaut rune = 139
	// CharILowerCaret ILowerCaret
	CharILowerCaret rune = 140
	// CharILowerGrave ILowerGrave
	CharILowerGrave rune = 141
	// CharAUpperUmlaut AUpperUmlaut
	CharAUpperUmlaut rune = 142
	// CharAUpperCircle AUpperCircle
	CharAUpperCircle rune = 143
	// CharEUpperAcute EUpperAcute
	CharEUpperAcute rune = 144
	// CharAELower AELower
	CharAELower rune = 145
	// CharAEUpper AEUpper
	CharAEUpper rune = 146
	// CharOLowerCaret OLowerCaret
	CharOLowerCaret rune = 147
	// CharOLowerUmlaut OLowerUmlaut
	CharOLowerUmlaut rune = 148
	// CharOLowerGrave OLowerGrave
	CharOLowerGrave rune = 149
	// CharULowerCaret ULowerCaret
	CharULowerCaret rune = 150
	// CharULowerGrave ULowerGrave
	CharULowerGrave rune = 151
	// CharYLowerUmlaut YLowerUmlaut
	CharYLowerUmlaut rune = 152
	// CharOUpperUmlaut OUpperUmlaut
	CharOUpperUmlaut rune = 153
	// CharUUpperUmlaut UUpperUmlaut
	CharUUpperUmlaut rune = 154
	// CharCent is Char 0x00A2
	CharCent rune = 0x00A2
	// CharPound is Char 0x00A3
	CharPound rune = 0x00A3
	// CharYen is Char 0x00A5
	CharYen rune = 0x00A5
	// CharPoint is Char 0x20A7
	CharPoint rune = 0x20A7
	// CharFunction is Char 0x0192
	CharFunction rune = 0x0192
	// CharALowerAcute ALowerAcute
	CharALowerAcute rune = 160
	// CharILowerAccute ILowerAccute
	CharILowerAccute rune = 161
	// CharOLowerAccute OLowerAccute
	CharOLowerAccute rune = 162
	// CharULowerAccute ULowerAccute
	CharULowerAccute rune = 163
	// CharNTildeLower NTildeLower
	CharNTildeLower rune = 164
	// CharNTildeUpper NTildeUpper
	CharNTildeUpper rune = 165
	// CharExpA is Char 0x00AA
	CharExpA rune = 0x00AA
	// CharExpO is Char 0x00BA
	CharExpO rune = 0x00BA
	// CharInvQuestion is Char 0x00BF
	CharInvQuestion rune = 0x00BF
	// CharLogicalNot is Char 0x2310
	CharLogicalNot rune = 0x2310
	// CharLogicalNotInv is Char 0x00AC
	CharLogicalNotInv rune = 0x00AC
	// CharHalf is Char 0x00BD
	CharHalf rune = 0x00BD
	// CharQuarter is Char 0x00BC
	CharQuarter rune = 0x00BC
	// CharInvExclamation is Char 0x00A1
	CharInvExclamation rune = 0x00A1
	// CharDoubleArrowL is Char 0x00AB
	CharDoubleArrowL rune = 0x00AB
	// CharDoubleArrowR is Char 0x00BB
	CharDoubleArrowR rune = 0x00BB
	// CharBlock1 is Char 0x2591
	CharBlock1 rune = 0x2591
	// CharBlock2 is Char 0x2592
	CharBlock2 rune = 0x2592
	// CharBlock3 is Char 0x2593
	CharBlock3 rune = 0x2593
	// CharWallV is Char 0x2502
	CharWallV rune = 0x2502
	// CharTeeW is Char 0x2524
	CharTeeW rune = 0x2524
	// CharTeeHDoubleW is Char 0x2561
	CharTeeHDoubleW rune = 0x2561
	// CharTeeVDoubleW is Char 0x2562
	CharTeeVDoubleW rune = 0x2562
	// CharCornerVDoubleNE is Char 0x2556
	CharCornerVDoubleNE rune = 0x2556
	// CharCornerHDoubleNE is Char 0x2555
	CharCornerHDoubleNE rune = 0x2555
	// CharTeeDoubleW is Char 0x2563
	CharTeeDoubleW rune = 0x2563
	// CharWallDoubleV is Char 0x2551
	CharWallDoubleV rune = 0x2551
	// CharCornerDoubleNE is Char 0x2557
	CharCornerDoubleNE rune = 0x2557
	// CharCornerDoubleSE is Char 0x255D
	CharCornerDoubleSE rune = 0x255D
	// CharCornerVDoubleSE is Char 0x255C
	CharCornerVDoubleSE rune = 0x255C
	// CharCornerHDoubleSE is Char 0x255B
	CharCornerHDoubleSE rune = 0x255B
	// CharCornerNE is Char 0x2510
	CharCornerNE rune = 0x2510
	// CharCornerSW is Char 0x2514
	CharCornerSW rune = 0x2514
	// CharTeeN is Char 0x2534
	CharTeeN rune = 0x2534
	// CharTeeS is Char 0x252C
	CharTeeS rune = 0x252C
	// CharTeeE is Char 0x251C
	CharTeeE rune = 0x251C
	// CharWallH is Char 0x2500
	CharWallH rune = 0x2500
	// CharWallCross is Char 0x253C
	CharWallCross rune = 0x253C
	// CharTeeHDoubleE is Char 0x255E
	CharTeeHDoubleE rune = 0x255E
	// CharTeeVDoubleE is Char 0x255F
	CharTeeVDoubleE rune = 0x255F
	// CharCornerDoubleSW is Char 0x255A
	CharCornerDoubleSW rune = 0x255A
	// CharCornerDoubleNW is Char 0x2554
	CharCornerDoubleNW rune = 0x2554
	// CharTeeDoubleN is Char 0x2569
	CharTeeDoubleN rune = 0x2569
	// CharTeeDoubleS is Char 0x2566
	CharTeeDoubleS rune = 0x2566
	// CharTeeDoubleE is Char 0x2560
	CharTeeDoubleE rune = 0x2560
	// CharWallDoubleH is Char 0x2550
	CharWallDoubleH rune = 0x2550
	// CharWallDoubleCross is Char 0x256C
	CharWallDoubleCross rune = 0x256C
	// CharTeeHDoubleN is Char 0x2567
	CharTeeHDoubleN rune = 0x2567
	// CharTeeVDoubleN is Char 0x2568
	CharTeeVDoubleN rune = 0x2568
	// CharTeeHDoubleS is Char 0x2564
	CharTeeHDoubleS rune = 0x2564
	// CharTeeVDoubleS is Char 0x2565
	CharTeeVDoubleS rune = 0x2565
	// CharCornerVDoubleSW is Char 0x2559
	CharCornerVDoubleSW rune = 0x2559
	// CharCornerHdoubleSW is Char 0x2558
	CharCornerHdoubleSW rune = 0x2558
	// CharCornerHDoubleNW is Char 0x2552
	CharCornerHDoubleNW rune = 0x2552
	// CharCornerVDoubleNW is Char 0x2553
	CharCornerVDoubleNW rune = 0x2553
	// CharWallVDoubleCross is Char 0x256B
	CharWallVDoubleCross rune = 0x256B
	// CharWallHDoubleCross is Char 0x256A
	CharWallHDoubleCross rune = 0x256A
	// CharCornerSE is Char 0x2518
	CharCornerSE rune = 0x2518
	// CharCornerNW is Char 0x250C
	CharCornerNW rune = 0x250C
	// CharBlock4 is Char 0x2588
	CharBlock4 rune = 0x2588
	// CharSubpDown is Char 0x2584
	CharSubpDown rune = 0x2584
	// CharSubpLeft is Char 0x258C
	CharSubpLeft rune = 0x258C
	// CharSubpRight is Char 0x2590
	CharSubpRight rune = 0x2590
	// CharSubpUp is Char 0x2580
	CharSubpUp rune = 0x2580
	// CharAlpha is Char 0x03B1
	CharAlpha rune = 0x03B1
	// CharBeta is Char 0x00DF
	CharBeta rune = 0x00DF
	// CharGamma is Char 0x0393
	CharGamma rune = 0x0393
	// CharPi is Char 0x03C0
	CharPi rune = 0x03C0
	// CharSigmaUpper is Char 0x03A3
	CharSigmaUpper rune = 0x03A3
	// CharSigmaLower is Char 0x03C3
	CharSigmaLower rune = 0x03C3
	// CharMi is Char 0x00B5
	CharMi rune = 0x00B5
	// CharTau is Char 0x03C4
	CharTau rune = 0x03C4
	// CharPhiUpper is Char 0x03A6
	CharPhiUpper rune = 0x03A6
	// CharTheta is Char 0x0398
	CharTheta rune = 0x0398
	// CharOmega is Char 0x03A9
	CharOmega rune = 0x03A9
	// CharDelta is Char 0x03B4
	CharDelta rune = 0x03B4
	// CharInfinite is Char 0x221E
	CharInfinite rune = 0x221E
	// CharPhiLower is Char 0x03C6
	CharPhiLower rune = 0x03C6
	// CharEpsilon is Char 0x03B5
	CharEpsilon rune = 0x03B5
	// CharArc is Char 0x2229
	CharArc rune = 0x2229
	// CharList is Char 0x2261
	CharList rune = 0x2261
	// CharPlusMinus is Char 0x00B1
	CharPlusMinus rune = 0x00B1
	// CharGreaterEqual is Char 0x2265
	CharGreaterEqual rune = 0x2265
	// CharLowerEqual is Char 0x2264
	CharLowerEqual rune = 0x2264
	// CharIntegralUp is Char 0x2320
	CharIntegralUp rune = 0x2320
	// CharIntegralDown is Char 0x2321
	CharIntegralDown rune = 0x2321
	// CharDivision is Char 0x00F7
	CharDivision rune = 0x00F7
	// CharAlmostEqual is Char 0x2248
	CharAlmostEqual rune = 0x2248
	// CharDegree is Char 0x00B0
	CharDegree rune = 0x00B0
	// CharDot1 is Char 0x2219
	CharDot1 rune = 0x2219
	// CharDot2 is Char 0x00B7
	CharDot2 rune = 0x00B7
	// CharRoot is Char 0x221A
	CharRoot rune = 0x221A
	// CharExpN is Char 0x207F
	CharExpN rune = 0x207F
	// CharExp2 is Char 0x00B2
	CharExp2 rune = 0x00B2
	// CharSquare is Char 0x25A0
	CharSquare rune = 0x25A0
	// CharSquareInv is Char 0x00A0
	CharSquareInv rune = 0x00A0
)

rune enum

View Source
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}
)

Functions

func CreditsEmbed

func CreditsEmbed(x, y int, alpha bool) bool

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 CreditsReset

func CreditsReset()

CreditsReset resets the animation generated by CreditsEmbed

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 Flush

func Flush()

Flush renders the screen and presents it to the player

func Fullscreen

func Fullscreen() bool

Fullscreen returns true if the game window is in fullscreen mode

func GetFade

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

func SetFade(fade byte, color Color)

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

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

func GetFadeColor() Color

GetFadeColor returns the fading color of the game window

func (Color) Add

func (c Color) Add(o Color) Color

Add sums the RGB values of c and o, capping each one at 255

func (Color) Sub

func (c Color) Sub(o Color) Color

Sub subtracts the RGB values of o from c, with a minimum of 0 for each one

type Console

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

Console is a wrapper around the C struct of the same name.

func InitRoot

func InitRoot(w, h int, title string, fullscreen bool, renderer Renderer) (Console, error)

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

func NewConsole(w, h int) Console

NewConsole creates a console of size w by h cells

func NewConsoleASC

func NewConsoleASC(filename string) Console

NewConsoleASC creates a console from the .asc image specified by filename

func (Console) Blit

func (c Console) Blit(x, y, w, h int, target Console, x2, y2 int, bgAlpha, fgAlpha float32)

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) GetAlign

func (c Console) GetAlign() Alignment

GetAlign returns the console's alignment

func (Console) GetBgFlag

func (c Console) GetBgFlag() BgFlag

GetBgFlag returns the default BgFlag of a console

func (Console) GetChar

func (c Console) GetChar(x, y int) byte

GetChar returns the ascii code at a specific coordinate

func (Console) GetCharBg

func (c Console) GetCharBg(x, y int) Color

GetCharBg returns the background color at a specific coordinate

func (Console) GetCharFg

func (c Console) GetCharFg(x, y int) Color

GetCharFg returns the foreground color at a specific coordinate

func (Console) GetDefaultBg

func (c Console) GetDefaultBg() Color

GetDefaultBg returns the default background colour of a console

func (Console) GetDefaultFg

func (c Console) GetDefaultFg() Color

GetDefaultFg returns the default foreground colour of a console

func (*Console) GetH

func (c *Console) GetH() int

GetH returns the height of the console

func (*Console) GetW

func (c *Console) GetW() int

GetW returns the width of the console

func (Console) HLine

func (c Console) HLine(x, y, l int, flag BgFlag)

HLine renders a horizontal line starting at (x, y) and extending leftward for l cells

func (*Console) LoadASC

func (c *Console) LoadASC(filename string) bool

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

func (c *Console) Print(x, y int, format string, values ...interface{})

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

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

func (c *Console) PrintFrame(x, y, w, h int, clear bool,
	format string, values ...interface{})

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

func (c *Console) PrintRect(x, y, w, h int, format string, values ...interface{})

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

func (c Console) PutChar(x, y int, b rune, flag BgFlag)

PutChar sets the character of a cell and it's background flag

func (Console) SaveASC

func (c Console) SaveASC(filename string) bool

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) SetAlign

func (c Console) SetAlign(align Alignment)

SetAlign sets the console's alignment

func (Console) SetBgFlag

func (c Console) SetBgFlag(flag BgFlag)

SetBgFlag sets the default BgFlag of a console

func (Console) SetCellBg

func (c Console) SetCellBg(x, y int, color Color, flag BgFlag)

SetCellBg sets the background colour and flag at the given coordinates

func (Console) SetCellFg

func (c Console) SetCellFg(x, y int, color Color)

SetCellFg sets the foreground colour at the given coordinates

func (Console) SetChar

func (c Console) SetChar(x, y int, b rune)

SetChar renders a single character to the given coordinates

func (*Console) SetDefaultBg

func (c *Console) SetDefaultBg(bg Color)

SetDefaultBg sets which color a console's background should have by default. For example:

c := tcod.New*Console(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

func (c *Console) SetDefaultFg(fg Color)

SetDefaultFg sets which color a console's foreground should have by default, similar to SetDefaultBg. For example:

c := tcod.New*Console(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

func (c Console) SetKeyColor(color Color)

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.

func (Console) VLine

func (c Console) VLine(x, y, l int, flag BgFlag)

VLine renders a vertical line starting at (x, y), and extending downward for l cells

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
)

Directories

Path Synopsis
Package assets is generated by github.com/omeid/go-resources
Package assets is generated by github.com/omeid/go-resources
examples
chars
Package main defines a demo for viewing the character map supported by the library, as defined by CP437 https://en.wikipedia.org/wiki/Code_page_437
Package main defines a demo for viewing the character map supported by the library, as defined by CP437 https://en.wikipedia.org/wiki/Code_page_437
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.

Jump to

Keyboard shortcuts

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