| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package main
- func (game *Game) drawPlayer() {
- game.screen.SetContent(game.player.position.x, game.player.position.y, '@', nil, game.style)
- }
- func (g *Game) movePlayer(game *Game, press int) {
- if press == Left {
- if game.player.position.x != 2 {
- game.player.position.x--
- game.player.moves++
- }
- } else if press == Right {
- if game.player.position.x != 78 {
- game.player.position.x++
- game.player.moves++
- }
- } else if press == Up {
- if game.player.position.y != 1 {
- game.player.position.y--
- game.player.moves++
- }
- } else if press == Down {
- if game.player.position.y != 22 {
- game.player.position.y++
- game.player.moves++
- }
- } else if press == upleft {
- if game.player.position.x != 2 && game.player.position.y != 1 {
- game.player.position.x--
- game.player.position.y--
- game.player.moves++
- }
- } else if press == upright {
- if game.player.position.x != 78 && game.player.position.y != 1 {
- game.player.position.x++
- game.player.position.y--
- game.player.moves++
- }
- } else if press == downright {
- if game.player.position.x != 78 && game.player.position.y != 22 {
- game.player.position.x++
- game.player.position.y++
- game.player.moves++
- }
- } else if press == downleft {
- if game.player.position.x != 2 && game.player.position.y != 22 {
- game.player.position.x--
- game.player.position.y++
- game.player.moves++
- }
- } else if press == teleport {
- game.teleport()
- game.player.teleports++
- }
- }
- func (game *Game) teleport() {
- pos := game.randPos()
- game.player.position.x = pos.x
- game.player.position.y = pos.y
- }
- func (game *Game) onPlayer(pos Position) bool {
- var onPlayer bool
- if pos.x == game.player.position.x && pos.y == game.player.position.y {
- onPlayer = true
- } else {
- onPlayer = false
- }
- return onPlayer
- }
|