home *** CD-ROM | disk | FTP | other *** search
- class Game.Objects.BonusItem extends Engine.PongObject
- {
- var itemIndex;
- var __assetFrame;
- var __direction;
- var __speed;
- var currentPos;
- var target;
- var __viewTimer;
- var lastPos;
- var motionVec;
- var motionDist;
- var motionDir;
- var motionLeft;
- var motionRight;
- var motionTop;
- var motionBottom;
- var world;
- var className = "BonusItem";
- var assetID = "Item";
- var depthShift = 3000;
- static var itemID = 0;
- var __fading = false;
- function BonusItem(myIndex, myDirection, mySpeed)
- {
- super();
- Game.Objects.BonusItem.itemID = Game.Objects.BonusItem.itemID + 1;
- if(Game.Objects.BonusItem.itemID > 256)
- {
- Game.Objects.BonusItem.itemID = 0;
- }
- this.itemIndex = myIndex;
- this.__assetFrame = myIndex + 1;
- this.__direction = myDirection;
- this.__speed = mySpeed;
- }
- function onAddToScene()
- {
- this.currentPos = new Vector(this.x,this.y,0);
- this.width = this.target._width;
- this.height = this.target._height;
- this.target.gotoAndStop(this.__assetFrame);
- this.target.swapDepths(this.depthShift * 61440 + Game.Objects.BonusItem.itemID);
- this.getUpdates();
- }
- function onDisplay()
- {
- this.left = this.x;
- this.right = this.x + this.width;
- this.top = this.y;
- this.bottom = this.y + this.height;
- }
- function update(elapsed)
- {
- this.calcNewPosBy(this.__direction.x * this.__speed * elapsed,this.__direction.y * this.__speed * elapsed);
- if(this.__fading)
- {
- this.__viewTimer += elapsed;
- if(this.__viewTimer < Engine.PongObject.FRAME_TIME)
- {
- return undefined;
- }
- this.__viewTimer = 0;
- this.target._alpha -= 30;
- if(this.target._alpha < 20)
- {
- this.target._visible = false;
- this.cancelUpdates();
- this.removeFromWorld();
- return undefined;
- }
- }
- else if(this.checkPaddles() || this.checkBounds())
- {
- this.__fading = true;
- this.__viewTimer = 0;
- this.target._alpha -= 30;
- }
- this.moveTo(this.currentPos.x,this.currentPos.y,0);
- }
- function calcNewPosTo(newX, newY, keepLastPos)
- {
- if(!keepLastPos)
- {
- this.lastPos = this.currentPos;
- }
- this.currentPos = new Vector(newX,newY,0);
- this.calcNewMotionProps();
- }
- function calcNewPosBy(dx, dy, keepLastPos)
- {
- if(!keepLastPos)
- {
- this.lastPos = this.currentPos;
- }
- this.currentPos = new Vector(this.lastPos.x + dx,this.lastPos.y + dy,0);
- this.calcNewMotionProps();
- }
- function calcNewMotionProps()
- {
- this.motionVec = new Vector(this.currentPos.x - this.lastPos.x,this.currentPos.y - this.lastPos.y,0);
- this.motionDist = this.motionVec.length;
- this.motionDir = this.motionVec.getNormalized();
- this.motionLeft = Math.min(this.currentPos.x,this.lastPos.x);
- this.motionRight = Math.max(this.currentPos.x,this.lastPos.x) + this.width;
- this.motionTop = Math.min(this.currentPos.y,this.lastPos.y);
- this.motionBottom = Math.max(this.currentPos.y,this.lastPos.y) + this.height;
- }
- function checkPaddles()
- {
- return this.world.checkPaddles(this);
- }
- function checkBounds()
- {
- return this.world.checkBounds(this);
- }
- }
-