| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package main
- import "math/rand"
- func (g *Game) drawPlayer(game *Game) {
- 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)
- game.player.teleports++
- }
- }
- func (g *Game) teleport(game *Game) {
- // Draw something nice
- game.player.position.x = rand.Intn(80)
- game.player.position.y = rand.Intn(24)
- }
|