示例#1
0
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
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()
}
示例#3
0
func (spellEffect *SpellEffect) Draw(s *tl.Screen) {
	spellEffect.e = tl.NewEntityFromCanvas(spellEffect.x, spellEffect.y, *spellEffect.canvas)
	if spellEffect.turns == spellEffect.duration || spellEffect.done {
		spellEffect.level.RemoveEntity(spellEffect)
	} else {
		spellEffect.e.Draw(s)
	}
}
示例#4
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)
}
示例#6
0
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
}
示例#8
0
文件: snake.go 项目: towry/snakego
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)
}
示例#9
0
func NewPattern(x, y, w, h int, color tl.Attr, inverse bool, ch rune) *Pattern {
	canvas := tl.NewCanvas(w, h)
	for i := 0; i < w; i++ {
		for j := 0; j < h; j++ {
			if inverse {
				canvas[i][j].Fg = tl.ColorBlack
				canvas[i][j].Bg = color
			} else {
				canvas[i][j].Fg = color
			}
			canvas[i][j].Ch = ch
		}
	}
	pattern := Pattern{
		tl.NewEntityFromCanvas(x, y, canvas),
		color,
	}
	return &pattern
}
示例#10
0
func main() {
	g := tl.NewGame()

	level := tl.NewBaseLevel(tl.Cell{
		Bg: tl.ColorBlack,
	})

	background := tl.NewEntityFromCanvas(-50, -50, *tl.BackgroundCanvasFromFile("artwork/background/forest.png"))
	level.AddEntity(background)

	charSelect := "m_mage"
	var playerCanvases []*tl.Canvas
	for i := 0; i < 12; i++ {
		playerCanvases = append(playerCanvases, tl.BackgroundCanvasFromFile(fmt.Sprintf("artwork/sprites/player/%s/%d.png", charSelect, i)))
	}
	playerSprite := NewSprite(playerCanvases, 3, 2, 7, 0, 0, 14, 28, level)
	level.AddEntity(playerSprite)

	var enemyCanvases []*tl.Canvas
	for i := 0; i < 12; i++ {
		enemyCanvases = append(enemyCanvases, tl.BackgroundCanvasFromFile(fmt.Sprintf("artwork/sprites/enemy/flower/%d.png", i)))
	}

	enemySprite := NewSprite(enemyCanvases, 3, 2, 7, 70, 15, 14, 28, level)
	enemySprite.enemy = NewEnemy(5, 10)
	level.AddEntity(enemySprite)

	portrait := tl.BackgroundCanvasFromFile(fmt.Sprintf("artwork/sprites/player/%s/portrait.png", charSelect))
	var spellCanvases []*tl.Canvas
	for i := 0; i < 4; i++ {
		spellCanvases = append(spellCanvases, tl.BackgroundCanvasFromFile(fmt.Sprintf("artwork/spells/fireball/%d.png", i)))
	}
	player := NewPlayer(portrait, spellCanvases, playerSprite)
	playerSprite.player = player
	level.AddEntity(player)

	g.Screen().SetLevel(level)
	g.Start()
}
示例#11
0
func (sprite *Sprite) CurrentEntity() *tl.Entity {
	c := sprite.canvases[sprite.loopI]
	e := tl.NewEntityFromCanvas(sprite.x, sprite.y, *c)
	return e
}