This commit is contained in:
Jan Breitkreuz 2024-06-27 11:00:09 +02:00
parent 323e27648d
commit 33e48cb2c3
2 changed files with 27 additions and 11 deletions

View File

@ -18,6 +18,8 @@ body{
}
#fuchs img{
width: 200px;
position: relative;
left: 50px;
}
#enemy img{
width: 220px;

View File

@ -2,9 +2,13 @@ let playerAnim = [];
let tomAnim = [];
let enemyAnim = [];
let playerAnimState = 0;
let runDirection = 1;
let runSpeed = 5;
let currentPosition = 0;
let player = document.querySelector("#fuchs img");
fillArrays();
//currentPosition = window.getComputedStyle(player).left;
function fillArrays()
{
@ -22,8 +26,7 @@ let start = setInterval(gameLoop, 100);
function gameLoop()
{
playerRunAnim();
checkInput();
move();
}
function playerRunAnim()
@ -34,22 +37,33 @@ function playerRunAnim()
}
player.src = playerAnim[playerAnimState];
playerAnimState++;
}
function checkInput()
{
}
document.addEventListener('keydown', function(event) {
if(event.key == "d")
{
console.log("d");
if(runDirection == -1)
{
player.style.transform = 'scaleX(1)';
}
runDirection = 1;
}
else if(event.key == "a")
{
if(runDirection == 1)
{
player.style.transform = 'scaleX(-1)';
}
runDirection = -1;
}
});
function move()
{
playerRunAnim();
currentPosition = currentPosition + runDirection * runSpeed;
player.style.left = currentPosition + "px";
console.log(currentPosition);
}