Пример #1
0
// 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
		}
	}
}
Пример #2
0
func NewSnake(game *tl.Game) *Snake {

	snake := new(Snake)
	snake.head = tl.NewEntity(1, 1, 1, 1)
	snake.px = 1
	snake.py = 0
	snake.head.SetPosition(snake.px, snake.py)
	snake.head.SetCell(0, 0, &tl.Cell{Fg: tl.ColorRed, Ch: '#'})
	snake.dir = KeyArrowRight
	snake.stop = false
	snake.update = time.Now()

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

	snake.level.AddEntity(snake)

	snake.body = make([]*Body, 10)
	snake.size = 0

	// create food
	snake.food = NewFood()
	snake.level.AddEntity(snake.food)

	return snake
}
Пример #3
0
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()
}
Пример #4
0
func (g *Game) buildLevel(gameLevel int) {
	level := tl.NewBaseLevel(tl.Cell{})
	// TODO: Remove this abomination
	width := boardWidth*squareWidth + (boardWidth+1)*borderWidth
	height := boardHeight*squareHeight + (boardHeight+1)*borderHeight
	level.AddEntity(tl.NewRectangle(1, 1, width, height, tl.ColorGreen))
	for i := 0; i < boardHeight; i++ {
		for j := 0; j < boardWidth; j++ {
			x := offsetX + borderWidth + (j * squareWidth) + j*borderWidth
			y := offsetY + borderHeight + (i * squareHeight) + i*borderHeight
			level.AddEntity(tl.NewRectangle(x, y, squareWidth, squareHeight, tl.ColorBlue))
		}
	}
	g.board.populateBoard(gameLevel, answersPerLevel, level)
	level.AddEntity(g.player)
	// Add Foes
	foes := int(gameLevel/10) + 2
	g.foes = g.foes[:0]
	var foe *Foe
	for i := 0; i < foes; i++ {
		foe = NewFoe(g)
		g.foes = append(g.foes, foe)
		level.AddEntity(foe)
	}
	g.game.Screen().SetLevel(level)
	g.updateStatus()
}
Пример #5
0
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()
}
Пример #6
0
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()
}
Пример #7
0
func (l *endLevel) ActivateWin() {
	l.Level = tl.NewBaseLevel(tl.Cell{Bg: l.bg, Fg: l.fg})
	l.Level.AddEntity(&l.gt.console)

	l.win = true

	moneyEarned := 1000
	l.gt.stats.LevelsCompleted++
	l.gt.stats.LevelsAttempted++
	l.gt.stats.Dollars += moneyEarned
	l.gt.stats.TotalEarned += moneyEarned
	l.gt.console.SetText("")
	w, h := l.gt.g.Screen().Size()
	rect := tl.NewRectangle(10, 2, w-20, h-4, tl.ColorCyan)
	l.AddEntity(rect)

	l.endMessages = []*tl.Entity{}
	l.addEndMessage("data/you_win_a.txt", w/2, 3)
	l.addEndMessage("data/you_win_b.txt", w/2, 3)
	l.AddEntity(l.endMessages[l.currentMessage])

	l.PrintStats(moneyEarned, w/2, 13)

	l.Activate()
}
Пример #8
0
func (l *endLevel) ActivateFail() {
	l.win = false
	l.gt.stats.LevelsAttempted++
	l.gt.stats.Lives--
	if l.gt.stats.Lives == 0 {
		l.ActivateGameOver()
		return
	}
	l.Level = tl.NewBaseLevel(tl.Cell{Bg: l.bg, Fg: l.fg})
	l.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.ColorCyan)
	l.AddEntity(rect)

	l.endMessages = []*tl.Entity{}
	l.addEndMessage("data/you_loose_a.txt", w/2, 3)
	l.addEndMessage("data/you_loose_b.txt", w/2, 3)
	l.AddEntity(l.endMessages[l.currentMessage])

	l.PrintStats(0, w/2, 13)

	l.Activate()
}
Пример #9
0
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)
}
Пример #10
0
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()
}
Пример #11
0
func createLevelBase(wallColor tl.Attr, wallWidth int, w int, h int) *tl.BaseLevel {
	var level *tl.BaseLevel = tl.NewBaseLevel(tl.Cell{
		Bg: tl.ColorBlack,
		Fg: tl.ColorWhite,
		Ch: ' ',
	})

	level.AddEntity(NewWall(0, 0, w+wallWidth, wallWidth, wallColor))
	level.AddEntity(NewWall(0, h+wallWidth, w+wallWidth, wallWidth, tl.ColorCyan))
	level.AddEntity(NewWall(0, 0, wallWidth, h+wallWidth, tl.ColorCyan))
	level.AddEntity(NewWall(w+wallWidth, 0, wallWidth, h+wallWidth*2, tl.ColorCyan))

	return level
}
Пример #12
0
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()
}
Пример #13
0
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()
}
Пример #14
0
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)
}
Пример #15
0
func Start(comOut chan [boardSize][boardSize]int8, comIn chan [2]int8, comHud chan string) {
	game := tl.NewGame()

	level := tl.NewBaseLevel(tl.Cell{
		Bg: Bg,
		Fg: Fg,
	})
	w := newWelcome(game)
	level.AddEntity(w)
	b := newBoard(level, game.Screen(), P1, AI2, comIn, comOut, w)
	level.AddEntity(b)
	h := newHud(comHud, game.Screen())
	b.comHud = comHud
	game.Screen().AddEntity(h)
	game.Screen().SetLevel(level)
	game.Start()
}
Пример #16
0
func main() {
	g := tl.NewGame()
	g.Screen().SetFps(60)
	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.Screen().SetLevel(l)
	g.Screen().AddEntity(tl.NewFpsText(0, 0, tl.ColorRed, tl.ColorDefault, 0.5))
	g.Start()
}
Пример #17
0
func main() {
	game := tl.NewGame()
	level := tl.NewBaseLevel(tl.Cell{
		Bg: tl.ColorGreen,
		Fg: tl.ColorBlack,
		Ch: 'v',
	})
	level.AddEntity(tl.NewRectangle(10, 10, 50, 20, tl.ColorBlue))
	player := Player{
		entity: tl.NewEntity(1, 1, 1, 1),
		level:  level,
	}
	// Set the character at position (0, 0) on the entity.
	player.entity.SetCell(0, 0, &tl.Cell{Fg: tl.ColorRed, Ch: '옷'})
	level.AddEntity(&player)
	game.SetLevel(level)
	game.Start()
}
Пример #18
0
func (text *StartLevel) Tick(event tl.Event) {
	if event.Type == tl.EventKey {
		if event.Key == tl.KeyEnter {
			level := tl.NewBaseLevel(tl.Cell{
				Bg: tl.ColorBlack,
				Fg: tl.ColorBlack,
			})

			player := Player{
				snake: []*tl.Rectangle{tl.NewRectangle(0, 0, 1, 1, tl.ColorRed)},
				level: level,
			}

			//player.entity.SetCell(0, 0, &tl.Cell{Fg: tl.ColorRed, Ch: '☺'})
			level.AddEntity(&player)
			game.Screen().SetLevel(level)
		}
	}
}
Пример #19
0
func (l *endLevel) ActivateGameOver() {
	l.Level = tl.NewBaseLevel(tl.Cell{Bg: l.bg, Fg: l.fg})
	l.AddEntity(&l.gt.console)
	l.gt.console.SetText("")
	l.gt.g.SetEndKey(tl.KeyEnter)

	w, h := l.gt.g.Screen().Size()
	rect := tl.NewRectangle(10, 2, w-20, h-4, tl.ColorCyan)
	l.AddEntity(rect)

	l.endMessages = []*tl.Entity{}
	l.addEndMessage("data/game_over_a.txt", w/2, 3)
	l.addEndMessage("data/game_over_b.txt", w/2, 3)
	l.AddEntity(l.endMessages[l.currentMessage])

	l.PrintStats(0, w/2, 13)

	l.Activate()
}
Пример #20
0
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()
}
Пример #21
0
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))
			}
		}
	}
}
Пример #22
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()
}
Пример #23
0
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)
}
Пример #24
0
func main() {
	game = termloop.NewGame()
	player = NewPlayer()
	level = termloop.NewBaseLevel(termloop.Cell{Bg: termloop.ColorBlack})
	grid = NewGrid(width, height, mineCount)
	game.SetDebugOn(true)

	SetupUI()

	// Add cells to level
	for x := 0; x < width; x++ {
		for y := 0; y < height; y++ {
			level.AddEntity(&grid.cells[x][y])
		}
	}

	// Add player to level
	level.AddEntity(&player)

	game.Screen().SetLevel(level)
	UpdateUI()
	GameSetup()
	game.Start()
}
Пример #25
0
func newIntroLevel(g *GopherTyper, fg, bg tl.Attr) introLevel {
	l := tl.NewBaseLevel(tl.Cell{Bg: bg, Fg: fg})
	return introLevel{Level: l, gt: g}
}