本文整理匯總了Golang中github.com/JoelOtter/termloop.NewText函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewText函數的具體用法?Golang NewText怎麽用?Golang NewText使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewText函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Draw
func (player *Player) Draw(s *tl.Screen) {
screenWidthidth, screenh := s.Size()
x := player.sprite.x + screenWidthidth/2 - 30
y := player.sprite.y + screenh - 25
bg := tl.NewRectangle(x, y, x+20, y+10, StatsBG)
bg.Draw(s)
health := tl.NewText(x+1, y+1, fmt.Sprintf("%3.f%% health", float32(player.health)/float32(player.maxHealth)*100), tl.ColorRed, StatsBG)
health.Draw(s)
mana := tl.NewText(x+27, y+1, fmt.Sprintf("%3.f%% mana", float32(player.mana)/float32(player.maxMana)*100), tl.ColorBlue, StatsBG)
mana.Draw(s)
gold := tl.NewText(x+1, y+12, fmt.Sprintf("%d gold", player.gold), tl.ColorYellow, StatsBG)
gold.Draw(s)
experience := tl.NewText(x+29, y+12, fmt.Sprintf("%3.f%% xp", float32(player.experience)/float32(player.experienceToLevel)*100), tl.ColorMagenta, StatsBG)
experience.Draw(s)
if player.isCasting {
player.isCasting = false
newSpellEffect := NewSpellEffect(player.sprite, player.spellCanvases[player.sprite.direction], player.sprite.level)
player.sprite.level.AddEntity(newSpellEffect)
}
e := tl.NewEntityFromCanvas(x+12, y+1, *player.portrait)
e.Draw(s)
}
示例2: newHud
func newHud(com chan string, screen *tl.Screen) (h *hud) {
h = &hud{
screen: screen,
com: com,
}
h.header = tl.NewText(h.offsetX, h.offsetY, "Events:", Fg, Bg)
h.header2 = tl.NewText(h.offsetX, h.offsetY, "--------------------------------------------------------------------------------", Fg, Bg)
for k, _ := range h.toDisp {
h.toDisp[k] = tl.NewText(h.offsetX, h.offsetY+k, "", Fg, Bg)
}
return h
}
示例3: main
func main() {
rand.Seed(time.Now().UTC().UnixNano())
game := tl.NewGame()
level := tl.NewBaseLevel(tl.Cell{
Bg: tl.ColorWhite,
})
for i := 0; i < 4; i++ {
TilePos[i] = rand.Intn(4)
level.AddEntity(&Tile{
r: tl.NewRectangle(X+TilePos[i]*(TileWidth+BorderWidth), Y-i*(TileHeight+BorderHeight), TileWidth, TileHeight, tl.ColorBlack),
})
}
level.AddEntity(tl.NewText(X+TileWidth/2-1, Y+TileHeight, "←", tl.ColorBlack, tl.ColorWhite))
level.AddEntity(tl.NewText(X+(TileWidth+BorderWidth)+TileWidth/2-1, Y+TileHeight, "↓", tl.ColorBlack, tl.ColorWhite))
level.AddEntity(tl.NewText(X+2*(TileWidth+BorderWidth)+TileWidth/2-1, Y+TileHeight, "↑", tl.ColorBlack, tl.ColorWhite))
level.AddEntity(tl.NewText(X+3*(TileWidth+BorderWidth)+TileWidth/2-1, Y+TileHeight, "→", tl.ColorBlack, tl.ColorWhite))
level.AddEntity(&RemainingTime{
r: tl.NewText(X+4*(TileWidth+BorderWidth), 0, fmt.Sprintf("%.3f", Time), tl.ColorRed, tl.ColorDefault),
s: tl.NewText(0, 0, "0", tl.ColorRed, tl.ColorDefault),
t: Time,
m: tl.NewText(0, Y+TileHeight+1, "", tl.ColorRed, tl.ColorDefault),
e: tl.NewText(X+4*(TileWidth+BorderWidth), Y+TileHeight+1, "", tl.ColorRed, tl.ColorDefault),
})
game.Screen().SetLevel(level)
game.Start()
}
示例4: Draw
func (h *hud) Draw(screen *tl.Screen) {
w, _ := screen.Size()
h.offsetX = w - 80
mainLoop:
for {
select {
case str := <-h.com:
i := hudMem - 1
for i > 0 {
h.toDisp[i] = h.toDisp[i-1]
if h.toDisp[i] != nil {
h.toDisp[i].SetPosition(h.offsetX, h.offsetY+i+2)
}
i--
}
h.toDisp[0] = tl.NewText(h.offsetX, h.offsetY+2, str, Fg, Bg)
default:
break mainLoop
}
}
for _, v := range h.toDisp {
v.Draw(screen)
}
h.header.SetPosition(h.offsetX, h.offsetY)
h.header2.SetPosition(h.offsetX, h.offsetY+1)
h.header.Draw(screen)
h.header2.Draw(screen)
}
示例5: BuildLevel
// TODO need to be able to build multiple levels
// maybe look at adding a 'R' key during debug to reload/refresh level
func BuildLevel(g *tl.Game, w, h, score int) {
maze := generateMaze(w, h)
l := tl.NewBaseLevel(tl.Cell{})
l.SetOffset(30, 15)
g.Screen().SetLevel(l)
g.Log("Building level with width %d and height %d", w, h)
scoretext := tl.NewText(0, 1, "Pengo", tl.ColorWhite, tl.ColorBlack)
g.Screen().AddEntity(scoretext)
for i, row := range maze {
for j, path := range row {
if path == '*' {
// check if the iceblock is a wall and set its color to white.
var blockcolor = tl.ColorBlue
if (i <= 1 || j <= 1) || (i >= 15 || j >= 17) {
blockcolor = tl.ColorWhite
}
l.AddEntity(NewIceBlock(i, j, g, blockcolor))
} else if path == 'P' {
// it's Pengo
l.AddEntity(NewPengo(i, j, g))
} else if path == 'S' {
// it's a Snobee
l.AddEntity(NewSnobee(i, j, g))
}
// 'R' it's a Diamond iceblock
// 's' it's a snobee egg iceblock
}
}
}
示例6: CreateSoundCtrl
func CreateSoundCtrl(filename string, loop bool) *SoundCtrl {
a, err := tlx.InitAudio()
chk(err)
t1 := tl.NewText(1, 1, "Push the right arrow to play", tl.ColorWhite, 0)
t2 := tl.NewText(1, 3, "Push the up arrow to pause", tl.ColorWhite, 0)
t3 := tl.NewText(1, 5, "Push the left arrow to restart", tl.ColorWhite, 0)
t4 := tl.NewText(1, 7, "Push the down arrow to stop", tl.ColorWhite, 0)
text := []*tl.Text{t1, t2, t3, t4}
track, err := a.LoadTrack(filename, loop)
chk(err)
return &SoundCtrl{
audio: a,
track: track,
text: text,
}
}
示例7: GameOver
func GameOver() {
end := tl.NewBaseLevel(tl.Cell{
Bg: tl.ColorRed,
Fg: tl.ColorBlack,
})
endText := StartLevel{
message: tl.NewText(0, 0, endMessage, tl.ColorGreen, tl.ColorBlack),
instructions: tl.NewText(0, 0, endInstructions, tl.ColorGreen, tl.ColorBlack),
instructions2: tl.NewText(0, 0, "", tl.ColorGreen, tl.ColorBlack),
}
end.AddEntity(&endText)
firstPass = true
game.Screen().SetLevel(end)
}
示例8: refresh
func (l *storeLevel) refresh() {
l.Level = tl.NewBaseLevel(tl.Cell{Bg: l.bg, Fg: l.fg})
l.gt.store.AddEntity(&l.gt.console)
l.gt.console.SetText("")
w, h := l.gt.g.Screen().Size()
rect := tl.NewRectangle(10, 2, w-20, h-4, tl.ColorGreen)
l.AddEntity(rect)
store, _ := ioutil.ReadFile("data/store.txt")
c := tl.CanvasFromString(string(store))
l.AddEntity(tl.NewEntityFromCanvas(w/2-len(c)/2, 4, c))
msg := "Up/Down(j/k), Enter to purchase, N to return to the game"
l.AddEntity(tl.NewText(w/2-len(msg)/2, 10, msg, tl.ColorBlack, tl.ColorDefault))
msg = fmt.Sprintf("Cash: $%d", l.gt.stats.Dollars)
l.AddEntity(tl.NewText(14, 11, msg, tl.ColorBlack, tl.ColorDefault))
y := 12
for idx, i := range l.items {
i.Reset(l.gt)
x := 14
fg := tl.ColorBlack
if i.Price() > l.gt.stats.Dollars {
fg = tl.ColorRed
}
var price string
if l.currentItem == idx {
price = ">" + i.PriceDesc() + "<"
} else {
price = " " + i.PriceDesc()
}
l.AddEntity(tl.NewText(x, y, price, fg, tl.ColorDefault))
x += len(i.PriceDesc()) + 4
l.AddEntity(tl.NewText(x, y, i.Name(), tl.ColorBlue, tl.ColorDefault))
y++
}
desc := l.items[l.currentItem].Desc()
l.AddEntity(tl.NewText(14, y+1, desc, tl.ColorBlue, tl.ColorDefault))
y = 12
x := w - 30
msg = fmt.Sprintf("Goroutines: %d", len(l.gt.items))
l.AddEntity(tl.NewText(x, y, msg, tl.ColorBlue, tl.ColorDefault))
y++
msg = fmt.Sprintf("CPU Upgrades: %d", l.gt.stats.CPUUpgrades)
l.AddEntity(tl.NewText(x, y, msg, tl.ColorBlue, tl.ColorDefault))
y++
msg = fmt.Sprintf("Go Version: %0.1f", l.gt.stats.GoVersion)
l.AddEntity(tl.NewText(x, y, msg, tl.ColorBlue, tl.ColorDefault))
y++
l.gt.g.Screen().SetLevel(l)
}
示例9: addChrome
func (g *Game) addChrome() {
screen := g.game.Screen()
screen.AddEntity(tl.NewText(offsetX, 0, " Number crusher! ", tl.ColorBlack, tl.ColorGreen))
x := 2*offsetX + (boardWidth * squareWidth) + (boardWidth * borderWidth) + borderWidth
rules := tl.NewEntityFromCanvas(x, offsetY, tl.CanvasFromString(rules))
screen.AddEntity(rules)
screen.AddEntity(g.status)
}
示例10: main
func main() {
if len(os.Args) < 2 {
fmt.Println("Please provide a string as first argument")
return
}
g := tl.NewGame()
g.AddEntity(&MovingText{
text: tl.NewText(0, 0, os.Args[1], tl.ColorWhite, tl.ColorBlue),
})
g.Start()
}
示例11: NewGame
func NewGame() *Game {
game := &Game{
level: startLevel,
game: tl.NewGame(),
board: NewBoard(),
status: tl.NewText(19, 0, "", tl.ColorWhite, tl.ColorBlack),
}
game.player = NewPlayer(game)
game.updateStatus()
return game
}
示例12: main
func main() {
game = tl.NewGame()
game.SetDebugOn(false)
start := tl.NewBaseLevel(
tl.Cell{Bg: tl.ColorBlack, Fg: tl.ColorBlack, Ch: 'S'},
)
startText := StartLevel{
tl.NewText(0, 0, startMessage, tl.ColorGreen, tl.ColorBlack),
tl.NewText(0, 0, instructions, tl.ColorGreen, tl.ColorBlack),
tl.NewText(0, 0, instructions2, tl.ColorGreen, tl.ColorBlack),
}
start.AddEntity(&startText)
game.Screen().SetLevel(start)
firstPass = true
game.Start()
}
示例13: NewCell
// NewCell creates a new cell. Accepts x and y coordinate parameters to
// determine "isWave" state. Returns a new instance of Cell.
func NewCell(x int, y int) Cell {
cell := Cell{
entity: termloop.NewText(x, y, " ", termloop.ColorWhite, termloop.ColorCyan),
isFlagged: false,
isMine: false,
isWave: (x%2 == 0 && y%2 == 0) || (x%2 != 0 && y%2 != 0),
proximity: 0,
isRevealed: false,
}
return cell
}
示例14: buildLevel
func buildLevel(g *tl.Game, w, h, score int) {
maze := generateMaze(w, h)
l := tl.NewBaseLevel(tl.Cell{})
g.SetLevel(l)
g.Log("Building level with width %d and height %d", w, h)
scoretext := tl.NewText(0, 1, "Levels explored: "+strconv.Itoa(score),
tl.ColorBlue, tl.ColorBlack)
g.AddEntity(tl.NewText(0, 0, "Pyramid!", tl.ColorBlue, tl.ColorBlack))
g.AddEntity(scoretext)
for i, row := range maze {
for j, path := range row {
if path == '*' {
l.AddEntity(tl.NewRectangle(i, j, 1, 1, tl.ColorWhite))
} else if path == 'S' {
l.AddEntity(NewBlock(i, j, tl.ColorRed, g, w, h, score, scoretext))
} else if path == 'L' {
l.AddEntity(tl.NewRectangle(i, j, 1, 1, tl.ColorBlue))
}
}
}
}
示例15: Activate
func (l *gameLevel) Activate() {
l.Level = tl.NewBaseLevel(tl.Cell{Bg: l.bg, Fg: l.fg})
l.gt.stats.Garbage = 0
l.gt.game.AddEntity(&l.gt.console)
l.gt.console.SetText("")
numWords := l.gt.stats.LevelsCompleted + 1
w, h := l.gt.g.Screen().Size()
l.words = []*word{}
x := 0
y := 0
for i := 0; i < numWords; i++ {
str := l.gt.wordList[rand.Intn(len(l.gt.wordList))]
if len(str)+x > w {
x = 0
y++
}
w := newWord(x, y, str, tl.ColorRed, tl.ColorGreen, tl.ColorBlue, tl.ColorCyan)
l.AddEntity(w)
l.words = append(l.words, w)
x += len(w.str) + 2
}
l.currentWord = nil
l.currentWordText = tl.NewText(0, h-1, "", tl.ColorRed, tl.ColorBlue)
l.AddEntity(l.currentWordText)
l.garbageText = tl.NewText(w, h-1, "", tl.ColorRed, tl.ColorBlue)
l.AddEntity(l.garbageText)
l.AddEntity(tl.NewText(0, h-2, strings.Repeat("*", w), tl.ColorBlack, tl.ColorDefault))
for _, i := range l.gt.items {
i.Reset(l.gt)
}
l.gt.g.Screen().SetLevel(l)
}