Spieler kann nicht aus die gelbe Box laufen

This commit is contained in:
Jan Breitkreuz 2024-08-29 08:43:21 +02:00
parent a56345cc45
commit 45a4164d9f

View File

@ -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";
}