瀏覽代碼

Prevent users from TPing into trash.

Sacha Ligthert 2 年之前
父節點
當前提交
227364f79e
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12 1
      player.go

+ 12 - 1
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 {