-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
93 lines (71 loc) · 2.48 KB
/
script.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function Sprite(nomdufichier,left,top,image){
this._node=document.createElement('img');
this._node.src=nomdufichier;
this._node.style.position="absolute";
document.body.appendChild(this._node);
this._node.classList.add(image)
// geteur et seteur de la propriete image
Object.defineProperty(this,"image",{
get:function(){
return this._image;
},
set: function(value){
this._image=value;
this._node.classList.image=value;
}
});
// geteur et seteur de la propriete left
Object.defineProperty(this,"left",{
get:function(){
return this._left;
},
set: function(value){
this._left=value;
this._node.style.left=value+"px";
}
});
// geteur et seteur de la propriete top
Object.defineProperty(this,"top",{
get:function(){
return this._top;
},
set: function(value){
this._top=value;
this._node.style.top=value+"px";
}
});
// geteur et seteur de la propriete top
Object.defineProperty(this,"display",{
get:function(){
return this._node.style.diplay;
},
set: function(value){
this._node.style.diplay=value;
}
});
this.left=left;
this.top= top;
}
Sprite.prototype.startAnimation=function(fct,interval){
if(this._clock) window.clearInterval(this._clock);
var _this=this;
this._clock=window.setInterval(function(){
fct( _this);
},interval);
}
Sprite.prototype.stopAnimation= function (){
window.clearInterval(this._clock)
}
Sprite.prototype.checkCollision= function (other){
return ! ((this.top+this._node.height<other.top) ||
this.top>(other.top+other._node.height) ||
(this.left+this._node.width<other.left) ||
this.left>(other.left+other._node.width) );
}
// Chargement audio
let explosion = new Audio();
explosion.src = "audio/explosion.mp3";
let tire = new Audio();
tire.src = "audio/tire.mp3";
const background = new Image()
background.src = 'background.png'