Ejemplo n.º 1
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
}
Ejemplo n.º 2
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()
}
Ejemplo n.º 3
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()
}
Ejemplo n.º 4
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
}
Ejemplo n.º 5
0
func NewFoe(game *Game) *Foe {
	foe := Foe{
		game:   game,
		entity: tl.NewEntity(1, 1, 1, 1),
	}
	foe.Init()
	foe.entity.SetCell(0, 0, &tl.Cell{Bg: tl.ColorMagenta, Ch: foeChar})
	return &foe
}
Ejemplo n.º 6
0
func NewPlayer(game *Game) *Player {
	player := Player{
		game:   game,
		entity: tl.NewEntity(1, 1, 1, 1),
	}
	player.Init()
	player.entity.SetCell(0, 0, &tl.Cell{Bg: tl.ColorRed, Ch: playerChar})
	return &player
}
Ejemplo n.º 7
0
func NewPlayer() Player {
	player := Player{
		entity: termloop.NewEntity(width/2, height/2, 1, 1),
		state:  Alive,
	}
	// player.entity.SetCell(0, 0, &termloop.Cell{Fg: termloop.ColorBlack, Ch: '⛴'})
	player.entity.SetCell(0, 0, &termloop.Cell{Fg: termloop.ColorBlack, Ch: 'o'})

	return player
}
Ejemplo n.º 8
0
func NewFood() *Food {
	food := &Food{
		entity: tl.NewEntity(1, 1, 1, 1),
		x:      -1,
		y:      -1,
	}

	food.entity.SetCell(0, 0, &tl.Cell{Fg: tl.ColorRed, Ch: '❁'})
	return food
}
Ejemplo n.º 9
0
func NewPlayer(sx, sy int) *Player {
	player := Player{
		entity: tl.NewEntity(sx, sy, 1, 1),
		keys:   make(map[tl.Attr]int, 100),
		Score:  NewScoreText(),
		Level:  NewLevelText(),
		Health: NewHealthText(),
	}
	player.entity.SetCell(0, 0, &tl.Cell{Fg: tl.ColorRed, Ch: '옷'})
	return &player
}
Ejemplo n.º 10
0
func NewBody(x, y int, d Direct) *Body {
	body := &Body{
		entity: tl.NewEntity(1, 1, 1, 1),
		px:     x,
		py:     y,
		dir:    d,
	}
	body.entity.SetPosition(x, y)
	body.entity.SetCell(0, 0, &tl.Cell{Fg: tl.ColorRed, Ch: '#'})

	return body
}
Ejemplo n.º 11
0
// Here we define a parse function for reading a Player out of JSON.
func parsePlayer(data map[string]interface{}) tl.Drawable {
	e := tl.NewEntity(
		int(data["x"].(float64)),
		int(data["y"].(float64)),
		1, 1,
	)
	e.SetCell(0, 0, &tl.Cell{
		Ch: []rune(data["ch"].(string))[0],
		Fg: tl.Attr(data["color"].(float64)),
	})
	return &Player{e: e}
}
Ejemplo n.º 12
0
func NewSquare(boardX, boardY int, pr *Problem) *Square {
	str := []rune(pr.String())
	c := make([]tl.Cell, len(str))
	for i := range c {
		c[i] = tl.Cell{Ch: str[i]}
	}
	sq := Square{
		boardX:  boardX,
		boardY:  boardY,
		problem: pr,
		visible: true,
		canvas:  c,
		entity:  tl.NewEntity(1, 1, squareWidth, squareHeight),
	}
	sq.entity.SetPosition(sq.getPosition())
	return &sq
}
Ejemplo n.º 13
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()
}
Ejemplo n.º 14
0
func NewImage(c *tl.Canvas) *Image {
	i := Image{e: tl.NewEntity(0, 0, len(*c), len((*c)[0]))}
	i.e.ApplyCanvas(c)
	return &i
}