forked from 8bit-peter/Zombie-Game-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (52 loc) · 1.82 KB
/
app.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
document.addEventListener('DOMContentLoaded', function() {
var score = 0;
var scoreValue = document.querySelector('.score span');
var plansza = document.querySelector('.plansza');
var timer = setInterval(function () {
var zombie = document.createElement('div');
zombie.classList.add('zombie');
//Scale
var scale = 0.8 + Math.random() * 0.5;
zombie.style.transform = "scale("+scale+")";
//blur
if (bottomPos > 200) {
zombie.style.filter = "blur(2px)"
} else if (bottomPos > 100) {
zombie.style.filter = "blur(1px)"
} else {
}
var min = 10;
var max = 360;
var bottomPos = Math.floor(Math.random()*(max-min+1)+min);
zombie.style.bottom = bottomPos + 'px';
zombie.style.zIndex = 360 - bottomPos;
//movement speed
var min = 10;
var max = 20;
var walkSpeed = Math.floor(Math.random()*(max-min+1)+min);
var anim = "0.5s,"+walkSpeed+"s"
zombie.style.animationDuration = anim;
//zombie life
zombie.live = 2;
plansza.appendChild(zombie);
zombie.addEventListener('animationend', function(e) {
if(e.animationName === "zombieWalk") {
score -= 10;
this.remove();
}
scoreValue.innerText = score;
}); if (score == -20 ){
alert("you lost the game ");location.reload();
}
}, 500);
plansza.addEventListener('click', function(e) {
if (e.target.classList.contains ('zombie')) {
e.target.live--;
if(e.target.live <= 0 ) {
score += 10;
e.target.remove();
}
scoreValue.innerText = score;
}
});
})