Exemple #1
0
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()
}
Exemple #2
0
func newTile(y, x, offY, offX int) (t *tile) {
	t = new(tile)
	t.player = UND
	t.entity = tl.NewEntity(x*tileSizeX+offX, y*tileSizeY+offY, tileSizeX, tileSizeY)
	tileCanvas := tl.CanvasFromString(tileStr)
	t.entity.ApplyCanvas(&tileCanvas)
	return t
}
Exemple #3
0
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)
}
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)
}
func (l *endLevel) addEndMessage(path string, x, y int) {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		l.gt.console.SetText(fmt.Sprintf("Err: %+v", err))
		return
	}
	c := tl.CanvasFromString(string(data))

	l.endMessages = append(l.endMessages, tl.NewEntityFromCanvas(x-len(c)/2, y, c))
}
func (l *introLevel) refresh() {
	l.gt.intro.AddEntity(&l.gt.console)
	l.gt.console.SetText("")
	w, h := l.gt.g.Screen().Size()
	quarterH := h / 4
	rect := tl.NewRectangle(10, 2, w-20, h-4, tl.ColorCyan)
	l.AddEntity(rect)

	logo, _ := ioutil.ReadFile("data/logo.txt")
	c := tl.CanvasFromString(string(logo))
	logoEntity := tl.NewEntityFromCanvas(w/2-len(c)/2, quarterH, tl.CanvasFromString(string(logo)))
	l.AddEntity(logoEntity)

	msg := "Press any key to continue"
	l.pressAKeyText = tl.NewText(w/2-len(msg)/2, h/2, msg, tl.ColorBlue|tl.AttrReverse, tl.ColorDefault)
	l.AddEntity(l.pressAKeyText)

	instructions, _ := ioutil.ReadFile("data/instructions.txt")
	c = tl.CanvasFromString(string(instructions))
	l.AddEntity(tl.NewEntityFromCanvas(w/2-len(c)/2, h/2+2, c))

	l.needsRefresh = false
}
Exemple #7
0
func (s *Snake) gameOver() {
	s.stop = true
	s.level.RemoveEntity(s)
	s.level.RemoveEntity(s.food)

	data, err := ioutil.ReadFile("gameover.txt")

	if err != nil {
		panic(err)
	}

	entity := tl.NewEntityFromCanvas(10, 1, tl.CanvasFromString(string(data)))
	s.level.AddEntity(entity)
}