From d77d84a891b5e164e318261f9be870c1c49c53f3 Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Mon, 4 Dec 2023 01:04:51 +0100 Subject: [PATCH] Simplified the teleport function. Closes #5 --- player.go | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/player.go b/player.go index 16ea10b..67381ad 100644 --- a/player.go +++ b/player.go @@ -1,9 +1,5 @@ package main -import ( - "math/rand" -) - func (game *Game) drawPlayer() { game.screen.SetContent(game.player.position.x, game.player.position.y, '@', nil, game.style) } @@ -60,25 +56,9 @@ func (g *Game) movePlayer(game *Game, press int) { } func (game *Game) teleport() { - // Draw something nice - // Use 1+rand.Intn(77) instead this - - var safe bool = false - var x, y int - - for !safe { - x = rand.Intn(80) - y = rand.Intn(24) - - if x == 0 || x == 79 || y == 0 || y == 23 { - safe = false - } else { - safe = true - } - } - - game.player.position.x = x - game.player.position.y = y + pos := game.randPos() + game.player.position.x = pos.x + game.player.position.y = pos.y } func (game *Game) onPlayer(pos Position) bool {