From f211a272c9cace8470631af0c940d961766ca093 Mon Sep 17 00:00:00 2001 From: "NB-PBG2H23ABR\\bib" Date: Thu, 4 Jul 2024 10:32:27 +0200 Subject: [PATCH] Script optimiert --- js/allg.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/js/allg.js b/js/allg.js index 15ab902..a6427d6 100644 --- a/js/allg.js +++ b/js/allg.js @@ -2,7 +2,7 @@ let playerAnim = []; let tomAnim = []; let enemyAnim = []; let playerAnimState = 0; -let runDirection = 1; +let runDirection = 0; let runSpeed = 5; let currentPosition = 0; let player = document.querySelector("#fuchs img"); @@ -13,6 +13,7 @@ let runAnimation; fillArrays(); //currentPosition = window.getComputedStyle(player).left; +// Pictures function fillArrays() { fillArray("fuchs_", 8, playerAnim); @@ -20,23 +21,20 @@ function fillArrays() fillArray("enemy_",3, enemyAnim); } -playerAnim.forEach(function(player) -{ - console.log(player); -}); - +// startGame let start = setInterval(gameLoop, 100); -function startAnimation() -{ - runAnimation = setInterval(playerRunAnim, 100); -} - function gameLoop() { move(); } +//-------------------------------------------------------------- Animation ----------------------------------------------------------------------- +function startAnimation() +{ + runAnimation = setInterval(playerRunAnim, 100); +} + function playerRunAnim() { if(playerAnimState == 8) @@ -47,7 +45,7 @@ function playerRunAnim() playerAnimState++; } - +//------------------------------------------------------------- checkInput ------------------------------------------------------------------ document.addEventListener('keydown', function(event) { if(!aIsPressed && !dIsPressed) { @@ -91,6 +89,7 @@ document.addEventListener('keyup', function(event) } }); +//---------------------------------------------------------- Move Player ------------------------------------------------------------ function move() { currentPosition = currentPosition + runDirection * runSpeed;