diff --git a/js/allg.js b/js/allg.js index 23a9c55..df76528 100644 --- a/js/allg.js +++ b/js/allg.js @@ -1,6 +1,8 @@ +// animation let playerAnim = []; let tomAnim = []; let enemyAnim = []; +//player let playerAnimState = 0; let runDirection = 0; let runSpeed = 12; @@ -11,6 +13,9 @@ let playerSprite = document.querySelector("#fuchs img"); let dIsPressed = false; let aIsPressed = false; let runAnimation; +// Map +const boxBorderLeft = -40; +const boxBorderRight = 840; fillArrays(); startAnimation(); @@ -96,7 +101,11 @@ document.addEventListener('keyup', function(event) //---------------------------------------------------------- Move Player ------------------------------------------------------------ function move() { - currentPosition = currentPosition + runDirection * runSpeed; + let nextPosition = currentPosition + runDirection * runSpeed; + if(nextPosition > boxBorderLeft && nextPosition < boxBorderRight) + { + currentPosition = nextPosition; + } player.style.left = currentPosition + "px"; }