-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
38 lines (29 loc) · 961 Bytes
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const onlyHero = new Hero('hero', '-70px 0px', '-103px 0px', '0px 0px', 500);
const secondHero = new Hero('hero', '-70px 0px', '-103px 0px', '0px 0px', 300);
let myHeroes = [onlyHero, secondHero];
function eventListeners(leftKey, rightKey, heroName) {
window.addEventListener('keydown', function (event) {
if (event.key === leftKey) {
heroName.changePositionLeft();
} else if (event.key === rightKey) {
heroName.changePositionRight();
}
});
window.addEventListener('keyup', function () {
heroName.lookFront();
});
}
eventListeners('ArrowLeft', 'ArrowRight', onlyHero);
eventListeners('a', 'd', secondHero);
setTimeout(() => new Enemy('ghost', '-45px 0px'), 500)
function setIntervalX(delay, repetitions) {
let x = 1;
let intervalID = setInterval(function () {
new Enemy('ghost', '-45px 0px');
++x
if (x === repetitions) {
clearInterval(intervalID);
}
}, delay);
}
setIntervalX(2500, 25);