rowboz/player.go

93 lines
2.0 KiB
Go
Raw Normal View History

package main
import (
"math/rand"
)
2023-12-01 22:41:35 +01:00
func (game *Game) drawPlayer() {
game.screen.SetContent(game.player.position.x, game.player.position.y, '@', nil, game.style)
}
2023-12-01 22:41:35 +01:00
func (g *Game) movePlayer(game *Game, press int) {
if press == Left {
if game.player.position.x != 2 {
game.player.position.x--
2023-12-01 23:08:17 +01:00
game.player.moves++
}
} else if press == Right {
if game.player.position.x != 78 {
game.player.position.x++
2023-12-01 23:08:17 +01:00
game.player.moves++
}
} else if press == Up {
if game.player.position.y != 1 {
game.player.position.y--
2023-12-01 23:08:17 +01:00
game.player.moves++
}
} else if press == Down {
if game.player.position.y != 22 {
game.player.position.y++
2023-12-01 23:08:17 +01:00
game.player.moves++
}
2023-12-01 22:41:35 +01:00
} else if press == upleft {
if game.player.position.x != 2 && game.player.position.y != 1 {
game.player.position.x--
game.player.position.y--
2023-12-01 23:08:17 +01:00
game.player.moves++
2023-12-01 22:41:35 +01:00
}
} else if press == upright {
if game.player.position.x != 78 && game.player.position.y != 1 {
game.player.position.x++
game.player.position.y--
2023-12-01 23:08:17 +01:00
game.player.moves++
2023-12-01 22:41:35 +01:00
}
} else if press == downright {
if game.player.position.x != 78 && game.player.position.y != 22 {
game.player.position.x++
game.player.position.y++
2023-12-01 23:08:17 +01:00
game.player.moves++
2023-12-01 22:41:35 +01:00
}
} else if press == downleft {
if game.player.position.x != 2 && game.player.position.y != 22 {
game.player.position.x--
game.player.position.y++
2023-12-01 23:08:17 +01:00
game.player.moves++
2023-12-01 22:41:35 +01:00
}
} else if press == teleport {
game.teleport()
2023-12-01 23:08:17 +01:00
game.player.teleports++
}
}
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
}
func (game *Game) onPlayer(pos Position) bool {
var onPlayer bool
if pos.x == game.player.position.x && pos.y == game.player.position.y {
onPlayer = true
} else {
onPlayer = false
}
return onPlayer
}