Path: blob/main/public/games/files/algaes-escapade/js/lib/block.js
1038 views
/**1* Represents a block that the player may hit2*3* @author David North4*/5function block()6{7//Load the variables required by gamejs.sprite.Sprite8block.superConstructor.apply(this, [0, 0]);9this.image = gamejs.image.load('img/blank.png');1011var _size = this.image.getSize();12this.rect = new gamejs.Rect([0, 0], [800, 20]);1314/**15* Sets the position of the object16*17* @param float x The X co-ordinate18* @param float y The Y co-ordinate19*20* @return block21*/22this.setPosition = function(x, y){23if ( typeof(x) !== 'number' )24{25throw 'X must be a number';26}2728if ( typeof(y) !== 'number' )29{30throw 'Y must be a number';31}3233this.rect.x = x;34this.rect.y = y;3536return this;37}3839/**40* Returns the position of the object41*42* @return object Contains an x and y property43*/44this.getPosition = function(){45return {"x": this.rect.x, "y": this.rect.y};46}4748/**49* Handles the collision between a playable and this object50*51* @return block52*/53this.handleCollision = function( playable ){54playerCollides(playable, this.rect);5556return this;57}58}5960//Extend the playable object so that the parent is the sprite61gamejs.utils.objects.extend(block, gamejs.sprite.Sprite);6263