Script optimiert
This commit is contained in:
parent
9fbf6f1103
commit
f211a272c9
23
js/allg.js
23
js/allg.js
@ -2,7 +2,7 @@ let playerAnim = [];
|
|||||||
let tomAnim = [];
|
let tomAnim = [];
|
||||||
let enemyAnim = [];
|
let enemyAnim = [];
|
||||||
let playerAnimState = 0;
|
let playerAnimState = 0;
|
||||||
let runDirection = 1;
|
let runDirection = 0;
|
||||||
let runSpeed = 5;
|
let runSpeed = 5;
|
||||||
let currentPosition = 0;
|
let currentPosition = 0;
|
||||||
let player = document.querySelector("#fuchs img");
|
let player = document.querySelector("#fuchs img");
|
||||||
@ -13,6 +13,7 @@ let runAnimation;
|
|||||||
fillArrays();
|
fillArrays();
|
||||||
//currentPosition = window.getComputedStyle(player).left;
|
//currentPosition = window.getComputedStyle(player).left;
|
||||||
|
|
||||||
|
// Pictures
|
||||||
function fillArrays()
|
function fillArrays()
|
||||||
{
|
{
|
||||||
fillArray("fuchs_", 8, playerAnim);
|
fillArray("fuchs_", 8, playerAnim);
|
||||||
@ -20,23 +21,20 @@ function fillArrays()
|
|||||||
fillArray("enemy_",3, enemyAnim);
|
fillArray("enemy_",3, enemyAnim);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerAnim.forEach(function(player)
|
// startGame
|
||||||
{
|
|
||||||
console.log(player);
|
|
||||||
});
|
|
||||||
|
|
||||||
let start = setInterval(gameLoop, 100);
|
let start = setInterval(gameLoop, 100);
|
||||||
|
|
||||||
function startAnimation()
|
|
||||||
{
|
|
||||||
runAnimation = setInterval(playerRunAnim, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
function gameLoop()
|
function gameLoop()
|
||||||
{
|
{
|
||||||
move();
|
move();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------- Animation -----------------------------------------------------------------------
|
||||||
|
function startAnimation()
|
||||||
|
{
|
||||||
|
runAnimation = setInterval(playerRunAnim, 100);
|
||||||
|
}
|
||||||
|
|
||||||
function playerRunAnim()
|
function playerRunAnim()
|
||||||
{
|
{
|
||||||
if(playerAnimState == 8)
|
if(playerAnimState == 8)
|
||||||
@ -47,7 +45,7 @@ function playerRunAnim()
|
|||||||
playerAnimState++;
|
playerAnimState++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------- checkInput ------------------------------------------------------------------
|
||||||
document.addEventListener('keydown', function(event) {
|
document.addEventListener('keydown', function(event) {
|
||||||
if(!aIsPressed && !dIsPressed)
|
if(!aIsPressed && !dIsPressed)
|
||||||
{
|
{
|
||||||
@ -91,6 +89,7 @@ document.addEventListener('keyup', function(event)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//---------------------------------------------------------- Move Player ------------------------------------------------------------
|
||||||
function move()
|
function move()
|
||||||
{
|
{
|
||||||
currentPosition = currentPosition + runDirection * runSpeed;
|
currentPosition = currentPosition + runDirection * runSpeed;
|
||||||
|
Loading…
Reference in New Issue
Block a user