fvfvfsv
This commit is contained in:
parent
323e27648d
commit
33e48cb2c3
@ -18,6 +18,8 @@ body{
|
|||||||
}
|
}
|
||||||
#fuchs img{
|
#fuchs img{
|
||||||
width: 200px;
|
width: 200px;
|
||||||
|
position: relative;
|
||||||
|
left: 50px;
|
||||||
}
|
}
|
||||||
#enemy img{
|
#enemy img{
|
||||||
width: 220px;
|
width: 220px;
|
||||||
|
34
js/allg.js
34
js/allg.js
@ -2,9 +2,13 @@ let playerAnim = [];
|
|||||||
let tomAnim = [];
|
let tomAnim = [];
|
||||||
let enemyAnim = [];
|
let enemyAnim = [];
|
||||||
let playerAnimState = 0;
|
let playerAnimState = 0;
|
||||||
|
let runDirection = 1;
|
||||||
|
let runSpeed = 5;
|
||||||
|
let currentPosition = 0;
|
||||||
let player = document.querySelector("#fuchs img");
|
let player = document.querySelector("#fuchs img");
|
||||||
|
|
||||||
fillArrays();
|
fillArrays();
|
||||||
|
//currentPosition = window.getComputedStyle(player).left;
|
||||||
|
|
||||||
function fillArrays()
|
function fillArrays()
|
||||||
{
|
{
|
||||||
@ -22,8 +26,7 @@ let start = setInterval(gameLoop, 100);
|
|||||||
|
|
||||||
function gameLoop()
|
function gameLoop()
|
||||||
{
|
{
|
||||||
playerRunAnim();
|
move();
|
||||||
checkInput();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function playerRunAnim()
|
function playerRunAnim()
|
||||||
@ -34,22 +37,33 @@ function playerRunAnim()
|
|||||||
}
|
}
|
||||||
player.src = playerAnim[playerAnimState];
|
player.src = playerAnim[playerAnimState];
|
||||||
playerAnimState++;
|
playerAnimState++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkInput()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('keydown', function(event) {
|
document.addEventListener('keydown', function(event) {
|
||||||
if(event.key == "d")
|
if(event.key == "d")
|
||||||
{
|
{
|
||||||
console.log("d");
|
if(runDirection == -1)
|
||||||
player.style.transform = 'scaleX(1)';
|
{
|
||||||
|
player.style.transform = 'scaleX(1)';
|
||||||
|
}
|
||||||
|
runDirection = 1;
|
||||||
}
|
}
|
||||||
else if(event.key == "a")
|
else if(event.key == "a")
|
||||||
{
|
{
|
||||||
player.style.transform = 'scaleX(-1)';
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user