Simplified the teleport function. Closes #5
This commit is contained in:
parent
2e13d93a53
commit
d77d84a891
26
player.go
26
player.go
@ -1,9 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (game *Game) drawPlayer() {
|
func (game *Game) drawPlayer() {
|
||||||
game.screen.SetContent(game.player.position.x, game.player.position.y, '@', nil, game.style)
|
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() {
|
func (game *Game) teleport() {
|
||||||
// Draw something nice
|
pos := game.randPos()
|
||||||
// Use 1+rand.Intn(77) instead this
|
game.player.position.x = pos.x
|
||||||
|
game.player.position.y = pos.y
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) onPlayer(pos Position) bool {
|
func (game *Game) onPlayer(pos Position) bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user