-
Notifications
You must be signed in to change notification settings - Fork 3
/
background_edge.js
54 lines (39 loc) · 1.34 KB
/
background_edge.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
// --- inherits from game_object
// spec:
// game_object spec
// boolean is_top = true if its a top edge, otherwise false
//
var background_edge = function(p, spec) {
//var background_image = p.loadImage("images/background.jpg");
//var background_image = p.loadImage("images/background1.png");
var edge = spec.is_top ?
image_manager.get_image("background_topside.png") :
image_manager.get_image("background_bottomside.png");
// --- defaults ---
spec.mode = p.CORNERS;
spec.width = spec.width || edge.width;
spec.height = spec.height || edge.height;
// if bottom, height should have been set to bottom of screen
// so we need to shift it up
if (!spec.is_top) {
spec.pos.add(new p.PVector(0, -spec.height));
}
// obj to return
var obj = background_object(p, spec);
obj.get_type = function() {
return "background_edge";
};
// --- private variables ---
// --- public methods ---
// override draw method only
obj.draw = function() {
p.imageMode(obj.get_mode());
p.image(edge, obj.get_pos().x, obj.get_pos().y);
};
// override offscreen check cuz we draw from the corners
obj.is_offscreen = function() {
// only need to check left edge of screen
return obj.get_pos().x + obj.get_width() < 0;
};
return obj;
};