Permalink
Browse files

Prevent player from moving past edge of tiles

  • Loading branch information...
1 parent cc94cc3 commit c88a487f8625c2ab2d04998eeecc8fb7ce544d11 @MaxNanasy committed Nov 26, 2012
Showing with 4 additions and 5 deletions.
  1. +4 −5 miner.svg
View
@@ -25,19 +25,18 @@
positionElement(playerElement, playerPosition)
document.addEventListener('keydown', function (event) {
- // FIXME Handle if at edge of tiles
const movementKeyIdToHandlerMap = {
'Up': function () {
- playerPosition.row --
+ playerPosition.row = Math.max(playerPosition.row - 1, 0)
},
'Down': function () {
- playerPosition.row ++
+ playerPosition.row = Math.min(playerPosition.row + 1, rowCount - 1)
},
'Left': function () {
- playerPosition.column --
+ playerPosition.column = Math.max(playerPosition.column - 1, 0)
},
'Right': function () {
- playerPosition.column ++
+ playerPosition.column = Math.min(playerPosition.column + 1, columnCount - 1)
}
}
if (movementKeyIdToHandlerMap.hasOwnProperty(event.keyIdentifier)) {

0 comments on commit c88a487

Please sign in to comment.