-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattackers.js
60 lines (59 loc) · 2.12 KB
/
attackers.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
///////////////////////////////////////////////////
////////////////////UTOCNICI///////////////////////
///////////////////////////////////////////////////
class Lopty{
constructor(deadSrc, imgSrc, x, y, priemer, rychlost){
this.killAudio = new Audio('zvuky/zabitie.wav');
this.intervalis;
this.dead = 0;
this.toRemove = 0;
this.imgSrc = imgSrc;
this.deadSrc = deadSrc;
this.priemer = priemer;
this.pozx = x + (priemer / 2);
this.pozy = y + (priemer / 2);
this.rychlost = rychlost;
this.smerY = ((canvas.height / 2) - this.pozy) / Math.sqrt((((canvas.width / 2) - this.pozx)*((canvas.width / 2) - this.pozx))+(((canvas.height / 2) - this.pozy)*((canvas.height / 2) - this.pozy)));
this.smerX = ((canvas.width / 2) - this.pozx) / Math.sqrt((((canvas.width / 2) - this.pozx)*((canvas.width / 2) - this.pozx))+(((canvas.height / 2) - this.pozy)*((canvas.height / 2) - this.pozy)));
}
drawLopty(ctx){
if(this.dead){
ctx.beginPath();
ctx.drawImage(this.deadSrc, this.pozx - (this.priemer / 2), this.pozy - (this.priemer / 2), this.priemer, this.priemer);
ctx.closePath();
}
else{
ctx.beginPath();
ctx.drawImage(this.imgSrc, this.pozx - (this.priemer / 2), this.pozy - (this.priemer / 2), this.priemer, this.priemer);
ctx.closePath();
this.moveLopty();
}
}
StartRemoveBall(){
this.priemer -= 30;
this.intervalis = setInterval(()=>this.RemoveBall(), 3000);
}
RemoveBall(Intervalis){
clearInterval(this.intervalis);
this.toRemove++;
}
detectMiddle(){
if(this.pozx > canvas.width / 2 - 50 && this.pozx < canvas.width / 2 + 50 && this.pozy > canvas.height / 2 - 50 && this.pozy < canvas.height / 2 + 50)
return 1;
else return 0;
}
detectCollision(e){
var mouseX;
var mouseY;
if (!e) e = window.event;
mouseX = e.clientX;
mouseY = e.clientY;
if(((mouseX - this.pozx) * (mouseX - this.pozx)) + ((mouseY - this.pozy) * (mouseY - this.pozy)) <= ((this.priemer / 2) * (this.priemer / 2)))
return 1;
else return 0;
}
moveLopty(){
this.pozx += (this.smerX * this.rychlost);
this.pozy += (this.smerY * this.rychlost);
};
}