Path: blob/main/public/games/files/algaes-escapade/js/lib/platform.js
1036 views
function platform()1{2//Load the variables required by gamejs.sprite.Sprite3platform.superConstructor.apply(this, [0, 0]);4this.image = new gamejs.Surface([0,0]);56var _size = this.image.getSize();7this.rect = new gamejs.Rect([0, 0]);89var _leftImg = gamejs.image.load('img/platform-left.png');10var _rightImg = gamejs.image.load('img/platform-right.png');11var _midImg = gamejs.image.load('img/platform-middle.png');1213this.setDimensions = function(width, height){14this.rect.width = width;15this.rect.height = height;16}1718this.setPosition = function(x, y){19this.rect.x = x;20this.rect.y = y;21}2223this.draw = function( surface ){24var rightSize = _rightImg.getSize();25var leftSize = _leftImg.getSize();2627var rightSide = new gamejs.Rect(28[(this.rect.right - rightSize[0]), this.rect.top],29[rightSize[0], this.rect.height]30);3132var leftSide = new gamejs.Rect(33[this.rect.left, this.rect.top],34[leftSize[0], this.rect.height]35);3637var middle = new gamejs.Rect(38[(this.rect.left + leftSize[0]) , this.rect.top],39[(rightSide.left - leftSide.right), this.rect.height]40);4142surface.blit(_midImg, middle);43surface.blit(_leftImg, leftSide);44surface.blit(_rightImg, rightSide);45}4647this.handleCollision = function(playable){48var collider = new gamejs.Rect(49[this.rect.x, this.rect.y + (this.rect.height / 2) ],50[this.rect.width, this.rect.height / 2]51);5253playerCollides(playable, collider);5455return this;56}57}5859//Extend the playable object so that the parent is the sprite60gamejs.utils.objects.extend(platform, gamejs.sprite.Sprite);6162