From 45a4164d9f45c31082704032d198784546214485 Mon Sep 17 00:00:00 2001 From: "NB-PBG2H23ABR\\bib" Date: Thu, 29 Aug 2024 08:43:21 +0200 Subject: [PATCH] Spieler kann nicht aus die gelbe Box laufen --- js/allg.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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"; }