From 227364f79ec798cdd9958ad1c0c0b8fc76a86621 Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Wed, 6 Dec 2023 22:23:47 +0100 Subject: [PATCH] Prevent users from TPing into trash. --- player.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/player.go b/player.go index 0901e85..37990ed 100644 --- a/player.go +++ b/player.go @@ -56,9 +56,20 @@ func (game *Game) movePlayer(press int) { } 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.y = pos.y + } func (game *Game) onPlayer(pos Position) bool {