Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/algaes-escapade/js/lib/block.js
1038 views
1
/**
2
* Represents a block that the player may hit
3
*
4
* @author David North
5
*/
6
function block()
7
{
8
//Load the variables required by gamejs.sprite.Sprite
9
block.superConstructor.apply(this, [0, 0]);
10
this.image = gamejs.image.load('img/blank.png');
11
12
var _size = this.image.getSize();
13
this.rect = new gamejs.Rect([0, 0], [800, 20]);
14
15
/**
16
* Sets the position of the object
17
*
18
* @param float x The X co-ordinate
19
* @param float y The Y co-ordinate
20
*
21
* @return block
22
*/
23
this.setPosition = function(x, y){
24
if ( typeof(x) !== 'number' )
25
{
26
throw 'X must be a number';
27
}
28
29
if ( typeof(y) !== 'number' )
30
{
31
throw 'Y must be a number';
32
}
33
34
this.rect.x = x;
35
this.rect.y = y;
36
37
return this;
38
}
39
40
/**
41
* Returns the position of the object
42
*
43
* @return object Contains an x and y property
44
*/
45
this.getPosition = function(){
46
return {"x": this.rect.x, "y": this.rect.y};
47
}
48
49
/**
50
* Handles the collision between a playable and this object
51
*
52
* @return block
53
*/
54
this.handleCollision = function( playable ){
55
playerCollides(playable, this.rect);
56
57
return this;
58
}
59
}
60
61
//Extend the playable object so that the parent is the sprite
62
gamejs.utils.objects.extend(block, gamejs.sprite.Sprite);
63