Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/algaes-escapade/js/lib/platform.js
1036 views
1
function platform()
2
{
3
//Load the variables required by gamejs.sprite.Sprite
4
platform.superConstructor.apply(this, [0, 0]);
5
this.image = new gamejs.Surface([0,0]);
6
7
var _size = this.image.getSize();
8
this.rect = new gamejs.Rect([0, 0]);
9
10
var _leftImg = gamejs.image.load('img/platform-left.png');
11
var _rightImg = gamejs.image.load('img/platform-right.png');
12
var _midImg = gamejs.image.load('img/platform-middle.png');
13
14
this.setDimensions = function(width, height){
15
this.rect.width = width;
16
this.rect.height = height;
17
}
18
19
this.setPosition = function(x, y){
20
this.rect.x = x;
21
this.rect.y = y;
22
}
23
24
this.draw = function( surface ){
25
var rightSize = _rightImg.getSize();
26
var leftSize = _leftImg.getSize();
27
28
var rightSide = new gamejs.Rect(
29
[(this.rect.right - rightSize[0]), this.rect.top],
30
[rightSize[0], this.rect.height]
31
);
32
33
var leftSide = new gamejs.Rect(
34
[this.rect.left, this.rect.top],
35
[leftSize[0], this.rect.height]
36
);
37
38
var middle = new gamejs.Rect(
39
[(this.rect.left + leftSize[0]) , this.rect.top],
40
[(rightSide.left - leftSide.right), this.rect.height]
41
);
42
43
surface.blit(_midImg, middle);
44
surface.blit(_leftImg, leftSide);
45
surface.blit(_rightImg, rightSide);
46
}
47
48
this.handleCollision = function(playable){
49
var collider = new gamejs.Rect(
50
[this.rect.x, this.rect.y + (this.rect.height / 2) ],
51
[this.rect.width, this.rect.height / 2]
52
);
53
54
playerCollides(playable, collider);
55
56
return this;
57
}
58
}
59
60
//Extend the playable object so that the parent is the sprite
61
gamejs.utils.objects.extend(platform, gamejs.sprite.Sprite);
62