2023-12-01 21:57:52 +01:00
|
|
|
package main
|
|
|
|
|
2023-12-01 22:41:35 +01:00
|
|
|
import "math/rand"
|
|
|
|
|
|
|
|
func (g *Game) drawPlayer(game *Game) {
|
2023-12-01 21:57:52 +01:00
|
|
|
game.screen.SetContent(game.player.position.x, game.player.position.y, '@', nil, game.style)
|
|
|
|
}
|
|
|
|
|
2023-12-01 22:41:35 +01:00
|
|
|
func (g *Game) movePlayer(game *Game, press int) {
|
2023-12-01 21:57:52 +01:00
|
|
|
if press == Left {
|
|
|
|
if game.player.position.x != 2 {
|
|
|
|
game.player.position.x--
|
|
|
|
}
|
|
|
|
} else if press == Right {
|
|
|
|
if game.player.position.x != 78 {
|
|
|
|
game.player.position.x++
|
|
|
|
}
|
|
|
|
} else if press == Up {
|
|
|
|
if game.player.position.y != 1 {
|
|
|
|
game.player.position.y--
|
|
|
|
}
|
|
|
|
} else if press == Down {
|
|
|
|
if game.player.position.y != 22 {
|
|
|
|
game.player.position.y++
|
|
|
|
}
|
2023-12-01 22:41:35 +01:00
|
|
|
} else if press == upleft {
|
|
|
|
if game.player.position.x != 2 && game.player.position.y != 1 {
|
|
|
|
game.player.position.x--
|
|
|
|
game.player.position.y--
|
|
|
|
}
|
|
|
|
} else if press == upright {
|
|
|
|
if game.player.position.x != 78 && game.player.position.y != 1 {
|
|
|
|
game.player.position.x++
|
|
|
|
game.player.position.y--
|
|
|
|
}
|
|
|
|
} else if press == downright {
|
|
|
|
if game.player.position.x != 78 && game.player.position.y != 22 {
|
|
|
|
game.player.position.x++
|
|
|
|
game.player.position.y++
|
|
|
|
}
|
|
|
|
} else if press == downleft {
|
|
|
|
if game.player.position.x != 2 && game.player.position.y != 22 {
|
|
|
|
game.player.position.x--
|
|
|
|
game.player.position.y++
|
|
|
|
}
|
|
|
|
} else if press == teleport {
|
|
|
|
game.teleport(game)
|
2023-12-01 21:57:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-01 22:41:35 +01:00
|
|
|
func (g *Game) teleport(game *Game) {
|
2023-12-01 21:57:52 +01:00
|
|
|
// Draw something nice
|
2023-12-01 22:41:35 +01:00
|
|
|
game.player.position.x = rand.Intn(80)
|
|
|
|
game.player.position.y = rand.Intn(24)
|
2023-12-01 21:57:52 +01:00
|
|
|
}
|