-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathBackground.js
59 lines (42 loc) · 1.25 KB
/
Background.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
var Background = function (config) {
var x, y,
curTile;
config = config || {};
this.originX = (config.x || 0) + FIELD_OFFSET_X;
this.originY = (config.y || 0) + FIELD_OFFSET_Y;
this.width = 10;
this.height = 20;
this.tiles = [];
for (x = 0; x < this.width; x += 1) {
for (y = 0; y < this.height; y += 1) {
curTile = new Block({ empty: true, blockX: x, blockY: y });
this.tiles.push(curTile);
}
}
this.backdrop = new jaws.Sprite({image: 'media/background/backdrop.png'});
this.backdrop.x = 0;
this.backdrop.y = 0;
this.topBar = new jaws.Sprite({image: 'media/background/topbar.png'});
this.topBar.x = 181;
this.topBar.y = 0;
this.fullRedrawNeeded = true;
};
Background.prototype.draw = function (lastPaused) {
var i;
if (this.fullRedrawNeeded || lastPaused) {
this.backdrop.draw();
for (i = 0; i < this.tiles.length; i += 1) {
this.tiles[i].draw();
}
this.fullRedrawNeeded = false;
} else {
this.topBar.draw();
// clear the swap group / previews
jaws.context.fillstyle = "#000D00";
jaws.context.fillRect(24, 42, 118, 60);
jaws.context.fillRect(457, 18, 107, 341);
for (i = 0; i < this.tiles.length; i += 1) {
this.tiles[i].drawIfInvalid();
}
}
};