本文整理汇总了Golang中github.com/JoelOtter/termloop.NewGame函数的典型用法代码示例。如果您正苦于以下问题:Golang NewGame函数的具体用法?Golang NewGame怎么用?Golang NewGame使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewGame函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// create game object
game := tl.NewGame()
// create cell
cell := tl.Cell{
Bg: tl.ColorGreen,
Fg: tl.ColorBlack,
Ch: 'v',
}
// create level filled with cell
level := tl.NewBaseLevel(cell)
// create body of water
level.AddEntity(tl.NewRectangle(10, 10, 50, 20, tl.ColorBlue))
// create player
player := Player{
entity: tl.NewEntity(1, 1, 1, 1),
level: level,
}
player.entity.SetCell(0, 0, &tl.Cell{Fg: tl.ColorRed, Ch: '@'})
// add player to level
level.AddEntity(&player)
// set level of screen
game.Screen().SetLevel(level)
// start the game
game.Start()
}
示例2: main
func main() {
g := tl.NewGame()
sound := CreateSoundCtrl(os.Args[1], true)
defer sound.audio.Stop()
g.Screen().AddEntity(sound)
g.Start()
}
示例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: world
func world() {
game := tl.NewGame()
level := tl.NewBaseLevel(tl.Cell{
Bg: tl.ColorWhite,
Fg: tl.ColorWhite,
Ch: '_',
})
for i := -1000; i < 1000; i = i + 40 {
if i == 0 {
continue
}
for j := -1000; j < 1000; j = j + 40 {
level.AddEntity(tl.NewRectangle(i, j, 20, 10, tl.ColorBlue))
}
}
player := Player{
entity: tl.NewEntity(1, 1, 1, 1),
level: level,
}
player.entity.SetCell(0, 0, &tl.Cell{Fg: tl.ColorBlack, Ch: '옷'})
level.AddEntity(&player)
game.Screen().SetLevel(level)
go func() {
for {
player.Tick(tl.Event{})
time.Sleep(200 * time.Millisecond)
}
}()
game.Start()
}
示例5: main
func main() {
g := tl.NewGame()
dat, err := ioutil.ReadFile("lorry.txt")
check(err)
e := tl.NewEntityFromCanvas(1, 1, tl.CanvasFromString(string(dat)))
g.Screen().AddEntity(e)
g.Start()
}
示例6: main
func main() {
game := tl.NewGame()
snake := NewSnake(game)
game.Screen().SetLevel(snake.Level())
game.Start()
}
示例7: main
func main() {
g := tl.NewGame()
g.Screen().SetFps(30)
gamelevel.TheGameState.StartLevel(1, g.Screen())
// g.Screen().AddEntity(tl.NewFpsText(0, 0, tl.ColorRed, tl.ColorDefault, 0.5))
g.Start()
}
示例8: 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()
}
示例9: main
func main() {
if len(os.Args) < 2 {
fmt.Println("Please provide a filepath to open")
return
}
g := tl.NewGame()
c := tl.BackgroundCanvasFromFile(os.Args[1])
g.AddEntity(NewImage(c))
g.Start()
}
示例10: 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
}
示例11: main
func main() {
g := tl.NewGame()
for i := 0; i < 40; i++ {
for j := 0; j < 20; j++ {
g.Screen().AddEntity(NewClickable(i, j, 1, 1, tl.ColorWhite))
}
}
g.Start()
}
示例12: main
func main() {
game := tl.NewGame()
// pengo default maze size is 13x15
BuildLevel(game, 15, 17, 0)
game.SetDebugOn(false)
game.Start()
}
示例13: main
func main() {
g := tl.NewGame()
l := tl.NewBaseLevel(tl.Cell{Bg: 76, Fg: 1})
lmap, err := ioutil.ReadFile("level.json")
checkErr(err)
parsers := make(map[string]tl.EntityParser)
parsers["Player"] = parsePlayer
err = tl.LoadLevelFromMap(string(lmap), parsers, l)
checkErr(err)
g.Screen().SetLevel(l)
g.Start()
}
示例14: main
func main() {
b := NewGame()
board := &Board{b, &[13][13]point{}, Point{5, 2}, false,
&[]Point{}, false, []*termloop.Text{}}
board.build()
game := termloop.NewGame()
level = termloop.NewBaseLevel(termloop.Cell{})
game.Screen().SetLevel(level)
level.AddEntity(board)
game.Start()
}
示例15: main
func main() {
g := tl.NewGame()
l := tl.NewBaseLevel(tl.Cell{
Bg: tl.ColorWhite,
})
l.AddEntity(&CollRec{
r: tl.NewRectangle(3, 3, 3, 3, tl.ColorRed),
move: true,
})
l.AddEntity(&CollRec{
r: tl.NewRectangle(7, 4, 3, 3, tl.ColorGreen),
move: false,
})
g.SetLevel(l)
g.Start()
}