Script optimiert

This commit is contained in:
Jan Breitkreuz 2024-07-04 10:32:27 +02:00
parent 9fbf6f1103
commit f211a272c9

View File

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