Script optimiert
This commit is contained in:
		
							
								
								
									
										23
									
								
								js/allg.js
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user