Checks of players are blocked by heaps of trash. Closes #11
This commit is contained in:
parent
d1af011acb
commit
ec8c3fb8a3
38
player.go
38
player.go
@ -5,6 +5,12 @@ func (game *Game) drawPlayer() {
|
||||
}
|
||||
|
||||
func (game *Game) movePlayer(press int) {
|
||||
|
||||
if game.blockedByTrash(press) {
|
||||
game.player.moves++
|
||||
return
|
||||
}
|
||||
|
||||
if press == Left {
|
||||
if game.player.position.x != 2 {
|
||||
game.player.position.x--
|
||||
@ -55,6 +61,38 @@ func (game *Game) movePlayer(press int) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
func (game *Game) teleport() {
|
||||
|
||||
var pos Position
|
||||
|
Loading…
x
Reference in New Issue
Block a user