Esempio n. 1
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()
}
Esempio n. 2
0
func main() {
	g := tl.NewGame()
	sound := CreateSoundCtrl(os.Args[1], true)
	defer sound.audio.Stop()
	g.Screen().AddEntity(sound)
	g.Start()
}
Esempio n. 3
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()
}
Esempio n. 4
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()
}
Esempio n. 5
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()
}
Esempio n. 6
0
func main() {
	game := tl.NewGame()

	snake := NewSnake(game)

	game.Screen().SetLevel(snake.Level())
	game.Start()
}
Esempio n. 7
0
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()
}
Esempio n. 8
0
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()
}
Esempio n. 9
0
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()
}
Esempio n. 10
0
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
}
Esempio n. 11
0
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()
}
Esempio n. 12
0
func main() {

	game := tl.NewGame()

	// pengo default maze size is 13x15
	BuildLevel(game, 15, 17, 0)

	game.SetDebugOn(false)

	game.Start()

}
Esempio n. 13
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()
}
Esempio n. 14
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()
}
Esempio n. 15
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()
}
Esempio n. 16
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()
}
Esempio n. 17
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()
}
Esempio n. 18
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()
}
Esempio n. 19
0
// NewGopherTyper gets the game ready to run.
func NewGopherTyper() (*GopherTyper, error) {
	wReader, err := os.Open("data/words.txt")
	if err != nil {
		return nil, err
	}

	gt := GopherTyper{}
	gt.g = tl.NewGame()
	gt.g.Screen().SetFps(30)
	gt.wordList = newWordLoader(wReader)
	gt.intro = newIntroLevel(&gt, tl.ColorBlack, tl.ColorBlue)
	gt.game = newGameLevel(&gt, tl.ColorBlack, tl.ColorRed)
	gt.store = newStoreLevel(&gt, tl.ColorBlack, tl.ColorCyan)
	gt.end = newEndLevel(&gt, tl.ColorBlack, tl.ColorGreen)

	gt.stats = newStats()

	return &gt, nil
}
Esempio n. 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()
}
Esempio n. 21
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()
}
Esempio n. 22
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()
}
Esempio n. 23
0
func (d *TermloopDriver) OnInit(c *hachi.Chip8) {
	// hex keyboard with 16 keys.
	// 8, 4, 6 and 2 are typically used for directional input.
	d.keyMap = map[tl.Key]uint16{
		tl.KeyTab:        hachi.Key0,
		tl.KeyF2:         hachi.Key1,
		tl.KeyF3:         hachi.Key2,
		tl.KeyF4:         hachi.Key3,
		tl.KeyF5:         hachi.Key4,
		tl.KeyF6:         hachi.Key5,
		tl.KeyF7:         hachi.Key6,
		tl.KeyF8:         hachi.Key7,
		tl.KeyF9:         hachi.Key8,
		tl.KeyF10:        hachi.Key9,
		tl.KeyCtrlA:      hachi.KeyA,
		tl.KeyCtrlB:      hachi.KeyB,
		tl.KeyCtrlC:      hachi.KeyC,
		tl.KeyCtrlD:      hachi.KeyD,
		tl.KeyCtrlE:      hachi.KeyE,
		tl.KeyCtrlF:      hachi.KeyF,
		tl.KeyArrowDown:  hachi.Key2,
		tl.KeyArrowLeft:  hachi.Key4,
		tl.KeyArrowRight: hachi.Key6,
		tl.KeyArrowUp:    hachi.Key8,
		tl.KeyEnter:      hachi.Key5,
	}

	// init termloop
	d.g = tl.NewGame()
	scr := d.g.Screen()

	scr.AddEntity(&inputHandler{c, d, make(map[uint16]time.Time)})
	scr.AddEntity(tl.NewText(0, 0, "Stack   Syscalls",
		tl.ColorDefault, tl.ColorDefault))

	// stack
	d.stack = make([]*tl.Text, len(c.Stack))
	for i := 0; i < len(d.stack); i++ {
		d.stack[i] = tl.NewText(
			0, i+1, "", tl.ColorDefault, tl.ColorDefault)
		d.g.Screen().AddEntity(d.stack[i])
	}

	// syscall log
	for i := 0; i < 10; i++ {
		d.syscalls[i] = tl.NewText(
			8, i+1, "", tl.ColorDefault, tl.ColorDefault)
		d.g.Screen().AddEntity(d.syscalls[i])
	}

	// chip info
	d.memory = tl.NewText(20, 0, "placeholder",
		tl.ColorDefault, tl.ColorDefault)
	scr.AddEntity(d.memory)

	d.registers = tl.NewText(20, 1, "placeholder",
		tl.ColorDefault, tl.ColorDefault)
	scr.AddEntity(d.registers)

	d.pointersAndTimers = tl.NewText(20, 2, "placeholder",
		tl.ColorDefault, tl.ColorDefault)
	scr.AddEntity(d.pointersAndTimers)

	d.devices = tl.NewText(20, 3, "placeholder",
		tl.ColorDefault, tl.ColorDefault)
	scr.AddEntity(d.devices)

	// screen preview at 20,5
	d.screen = make([][]*tl.Rectangle, c.Width)
	color := tl.ColorWhite // foreground

	for i := uint8(0); i < c.Width; i++ {
		d.screen[i] = make([]*tl.Rectangle, c.Height)

		for j := uint8(0); j < c.Height; j++ {
			d.screen[i][j] = tl.NewRectangle(
				20+int(i), 5+int(j),
				1, 1, color,
			)
		}
	}

	d.lastScreen = make([]byte, uint16(c.Width)*uint16(c.Height)/8)
	log.Println("TermloopDriver initialized")
}
Esempio n. 24
0
func main() {
	g := tl.NewGame()
	buildLevel(g, 6, 2, 0)
	g.SetDebugOn(true)
	g.Start()
}