2023-12-01 21:57:52 +01:00
|
|
|
package main
|
|
|
|
|
2023-12-02 00:19:33 +01:00
|
|
|
func (game *Game) drawPlayer() {
|
2023-12-01 21:57:52 +01:00
|
|
|
game.screen.SetContent(game.player.position.x, game.player.position.y, '@', nil, game.style)
|
|
|
|
}
|
|
|
|
|
2023-12-05 23:20:58 +01:00
|
|
|
func (game *Game) movePlayer(press int) {
|
2023-12-11 00:33:02 +01:00
|
|
|
|
|
|
|
if game.blockedByTrash(press) {
|
|
|
|
game.player.moves++
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-01 21:57:52 +01:00
|
|
|
if press == Left {
|
|
|
|
if game.player.position.x != 2 {
|
|
|
|
game.player.position.x--
|
2023-12-01 23:08:17 +01:00
|
|
|
game.player.moves++
|
2023-12-01 21:57:52 +01:00
|
|
|
}
|
|
|
|
} 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++
|
2023-12-01 21:57:52 +01:00
|
|
|
}
|
|
|
|
} 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++
|
2023-12-01 21:57:52 +01:00
|
|
|
}
|
|
|
|
} 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 21:57:52 +01:00
|
|
|
}
|
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 {
|
2023-12-02 00:19:33 +01:00
|
|
|
game.teleport()
|
2023-12-01 23:08:17 +01:00
|
|
|
game.player.teleports++
|
2023-12-01 21:57:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-11 00:33:02 +01:00
|
|
|
// blockedByTrash() Checks if player can move into a direction and if trash isn't blocking
|
|
|
|
func (game *Game) blockedByTrash(press int) bool {
|
|
|
|
var checkPos Position
|
|
|
|
|
|
|
|
if press == Left {
|
|
|
|
checkPos.x = game.player.position.x - 1
|
|
|
|
checkPos.y = game.player.position.y
|
|
|
|
} else if press == Right {
|
|
|
|
checkPos.x = game.player.position.x + 1
|
|
|
|
checkPos.y = game.player.position.y
|
|
|
|
} else if press == Up {
|
|
|
|
checkPos.x = game.player.position.x
|
|
|
|
checkPos.y = game.player.position.y - 1
|
|
|
|
} else if press == Down {
|
|
|
|
checkPos.x = game.player.position.x
|
|
|
|
checkPos.y = game.player.position.y + 1
|
|
|
|
} else if press == upleft {
|
|
|
|
checkPos.x = game.player.position.x - 1
|
|
|
|
checkPos.y = game.player.position.y - 1
|
|
|
|
} else if press == upright {
|
|
|
|
checkPos.x = game.player.position.x + 1
|
|
|
|
checkPos.y = game.player.position.y - 1
|
|
|
|
} else if press == downright {
|
|
|
|
checkPos.x = game.player.position.x + 1
|
|
|
|
checkPos.y = game.player.position.y + 1
|
|
|
|
} else if press == downleft {
|
|
|
|
checkPos.x = game.player.position.x - 1
|
|
|
|
checkPos.y = game.player.position.y + 1
|
|
|
|
}
|
|
|
|
return game.onTrash(checkPos)
|
|
|
|
}
|
|
|
|
|
2023-12-02 00:19:33 +01:00
|
|
|
func (game *Game) teleport() {
|
2023-12-06 22:23:47 +01:00
|
|
|
|
|
|
|
var pos Position
|
|
|
|
var safe bool = false
|
|
|
|
|
|
|
|
for !safe {
|
|
|
|
pos = game.randPos()
|
|
|
|
if !game.onTrash(pos) {
|
|
|
|
safe = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-04 01:04:51 +01:00
|
|
|
game.player.position.x = pos.x
|
|
|
|
game.player.position.y = pos.y
|
2023-12-06 22:23:47 +01:00
|
|
|
|
2023-12-01 21:57:52 +01:00
|
|
|
}
|
2023-12-02 00:19:33 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2023-12-11 01:04:38 +01:00
|
|
|
|
|
|
|
func (game *Game) resetPlayer() {
|
|
|
|
game.player.position.x = 40
|
|
|
|
game.player.position.y = 12
|
|
|
|
}
|