Path: blob/main/public/games/files/algaes-escapade/js/lib/door.js
1037 views
/**1* Represents a door which can be passed only when the state is set to true2*3* @author David North4*/5function door()6{7door.prototype.constructor.call(this);89//Set up the variables required by the sprite inheritance10this.image = gamejs.image.load('img/door.png');11this.image.crop( new gamejs.Rect( [0,0], [83,466] ));1213var _size = this.image.getSize();14this.rect = new gamejs.Rect([0, 0], [_size[0], _size[1]]);1516/**17* Overrides the setState method of the parent so that the object changes18* depending on whether it is on or off19*20* @param boolean state The state to apply21*22* @return door23*/24this.setState = function( state ){25//Only update if the state has actually changed26if ( state != this.getState() )27{28if ( state )29{30this.image.crop( new gamejs.Rect( [83,0], [83,466] ));31}32else33{34this.image.crop( new gamejs.Rect( [0,0], [83,466] ));35}36}3738//Update the state using the parent setState method39return door.prototype.setState.call(this, state);40}4142/**43* Handles the collision between a playable and this object44*45* @return door46*/47this.handleCollision = function( playable ){4849if ( !this.getState() )50{51//Modify the rectangle. The player shouldn't hit the door52//until they are at the beam53var targetX = this.rect.x + 26;54var targetY = this.rect.y;5556var targetWidth = this.rect.width - 52;57var targetHeight = this.rect.height;5859var rect = new gamejs.Rect(60[targetX, targetY], [targetWidth, targetHeight]61);6263playerCollides(playable, rect);64}6566return this;67}68}6970//Set the parent of the door to io71include_once(['lib/io.js']);72door.prototype = new io();737475