From 323e27648d11399905f557a82a992bfc8bcfd208 Mon Sep 17 00:00:00 2001 From: "NB-PBG2H23ABR\\bib" Date: Thu, 27 Jun 2024 10:31:37 +0200 Subject: [PATCH] ouzvoutc7tczutctcztczgczgcz --- js/allg.js | 38 ++++++++++++++++++++++++++++++++++++++ js/funktionen.js | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/js/allg.js b/js/allg.js index 67d0e78..2c1f2ce 100644 --- a/js/allg.js +++ b/js/allg.js @@ -1,6 +1,8 @@ let playerAnim = []; let tomAnim = []; let enemyAnim = []; +let playerAnimState = 0; +let player = document.querySelector("#fuchs img"); fillArrays(); @@ -15,3 +17,39 @@ playerAnim.forEach(function(player) { console.log(player); }); + +let start = setInterval(gameLoop, 100); + +function gameLoop() +{ + playerRunAnim(); + checkInput(); +} + +function playerRunAnim() +{ + if(playerAnimState == 8) + { + playerAnimState = 0; + } + player.src = playerAnim[playerAnimState]; + playerAnimState++; + +} + +function checkInput() +{ + +} + +document.addEventListener('keydown', function(event) { + if(event.key == "d") + { + console.log("d"); + player.style.transform = 'scaleX(1)'; + } + else if(event.key == "a") + { + player.style.transform = 'scaleX(-1)'; + } +}); \ No newline at end of file diff --git a/js/funktionen.js b/js/funktionen.js index 45eccf2..69254ba 100644 --- a/js/funktionen.js +++ b/js/funktionen.js @@ -2,6 +2,6 @@ function fillArray(name, number, playerAnim) { for (let i = 1 ; i <= number ; i++) { - playerAnim[i] = name + i + ".png"; + playerAnim[i-1] = "pics/" + name + i + ".png"; } } \ No newline at end of file