Prevent users from TPing into trash.

This commit is contained in:
Sacha Ligthert 2023-12-06 22:23:47 +01:00
parent 4690e5b1f1
commit 227364f79e

View File

@ -56,9 +56,20 @@ func (game *Game) movePlayer(press int) {
} }
func (game *Game) teleport() { func (game *Game) teleport() {
pos := game.randPos()
var pos Position
var safe bool = false
for !safe {
pos = game.randPos()
if !game.onTrash(pos) {
safe = true
}
}
game.player.position.x = pos.x game.player.position.x = pos.x
game.player.position.y = pos.y game.player.position.y = pos.y
} }
func (game *Game) onPlayer(pos Position) bool { func (game *Game) onPlayer(pos Position) bool {