/
Bat.js
45 lines (29 loc) · 815 Bytes
/
Bat.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
var Bat = function(){
var rect;
var bat = this;
this.init = function( obj ){
bat = obj;
bat.rect = new Rectangle();
bat.rect.init( bat.rect );
};
this.setColor = function( color ){
bat.rect.setColor( color );
};
this.setCoord = function( x, y ){
bat.rect.setCoord( x, y );
};
this.setDim = function( len, height ){
bat.rect.setDim( len, height );
};
this.resetPosition = function(){
bat.setCoord( ( windowWidth - batLength ) / 2 , windowHeight - batHeight - 2 );
};
this.draw = function( context ){
context.clearRect( 0, windowHeight-batHeight-2 , windowWidth, windowHeight+batHeight+2 );
bat.rect.draw( context );
};
this.move = function( context, offset ){
bat.rect.setCoord( this.rect.x+offset, this.rect.y );
bat.draw( context );
};
}