home *** CD-ROM | disk | FTP | other *** search
- class Sled extends GenericObject
- {
- var velocity;
- var surfacePlane;
- var up;
- var shadow;
- var target;
- var world;
- var vrSound;
- var vrOpen;
- var sledSound;
- var onMessage;
- var specialItem;
- var oldX;
- var oldY;
- var oldZ;
- var shadowX;
- var shadowY;
- var shadowLeftX;
- var shadowLeftY;
- var shadowRightX;
- var shadowRightY;
- var currentTurnFrame;
- var linkageID = "Sled";
- var shadowLinkageID = "SledShadow";
- var turnMultiplier = 4;
- var depthGroup = 2;
- var collisionGroup = BB.ALL;
- var radius = 25;
- var isOnGround = false;
- var maxDamage = 150;
- var damage = 0;
- var score = 0;
- var letters = 0;
- var lives = 0;
- var raceTime = 0;
- var timeRemaining = 0;
- var elevated = false;
- var inMotion = true;
- var maxSpeed = 4000;
- var messagesDisabled = false;
- var keepTrackOfTime = true;
- var currentSpeed = 0;
- var targetFrame = 4;
- var centerFrame = 4;
- var turnDegreePerFrame = 15;
- var maxDisplayTurn = 45;
- function Sled(linkageID)
- {
- super();
- this.velocity = new Vector(0,300,300);
- this.surfacePlane = new Point(1,0);
- this.up = new Point(0,1);
- if(linkageID != null)
- {
- this.linkageID = linkageID;
- }
- }
- function onAddToScene()
- {
- this.shadow = this.world.display.attachMovie(this.shadowLinkageID,"BS",this.target.getDepth() - 1);
- this.vrSound = new Sound(this.target);
- this.vrOpen = new Sound(this.target);
- this.vrOpen.attachSound("VRDeploy");
- this.sledSound = new Sound(this.target.createEmptyMovieClip("SledSound",10));
- this.sledSound.attachSound("SledSound");
- this.sledSound.start(0,16777215);
- this.sledSound.setVolume(0);
- this.world.registerForEffects(this);
- }
- function onRemoveFromScene()
- {
- this.shadow.swapDepths(0);
- this.shadow.removeMovieClip();
- stopAllSounds();
- this.vrSound.stop();
- this.vrOpen.stop();
- this.sledSound.stop();
- }
- function repairDamage(value)
- {
- this.damage = Math.max(this.damage - value,0);
- }
- function takeDamage(ammount)
- {
- this.damage += ammount;
- if(this.damage >= this.maxDamage)
- {
- this.onMessage("damage");
- }
- }
- function collectLetter(value, letterNumber)
- {
- this.addPoints(value);
- this.letters |= 1 << letterNumber;
- }
- function addPoints(value)
- {
- this.score += value;
- }
- function setSpecialItem(newSpecialItem)
- {
- if(this.specialItem)
- {
- this.vrSound.stop();
- this.specialItem = null;
- }
- this.vrOpen.start();
- this.specialItem = newSpecialItem;
- }
- function removeSpecialItem()
- {
- this.specialItem = null;
- this.hideSpecialItems();
- }
- function hideSpecialItems()
- {
- var _loc2_ = this.target.sled;
- _loc2_.magnetLeft._visible = false;
- _loc2_.magnetRight._visible = false;
- _loc2_.lasersLeft._visible = false;
- _loc2_.lasersRight._visible = false;
- }
- function onCollision(object)
- {
- var _loc3_ = object.collisionGroup;
- if(_loc3_ & BB.NODE)
- {
- object.onCross(this);
- }
- else if(_loc3_ & BB.COLLECTABLE)
- {
- object.setCollected(this);
- }
- else
- {
- object.onCollision(this);
- }
- }
- function checkCollisions(from, to)
- {
- var _loc4_ = [];
- var _loc2_ = undefined;
- while(from && from != to.next)
- {
- _loc4_ = _loc4_.concat(from.objects);
- from = from.next;
- }
- var _loc11_ = this.x - this.oldX;
- var _loc10_ = this.y - this.oldY;
- var _loc9_ = this.z - this.oldZ;
- var _loc8_ = undefined;
- var _loc3_ = _loc4_.length - 1;
- while(_loc3_ > -1)
- {
- _loc2_ = _loc4_[_loc3_];
- if(!(_loc2_ == this || !_loc2_.collisionEnabled))
- {
- if(this.collisionGroup & _loc2_.collisionGroup && _loc2_.z >= this.oldZ && _loc2_.z <= this.z)
- {
- _loc8_ = (_loc2_.z - this.oldZ) / _loc9_;
- var _loc7_ = _loc2_.x - (this.oldX + _loc11_ * _loc8_);
- var _loc6_ = _loc2_.y - (this.oldY + _loc10_ * _loc8_);
- if(Math.sqrt(_loc7_ * _loc7_ + _loc6_ * _loc6_) < _loc4_[_loc3_].radius + this.radius)
- {
- this.onCollision(_loc4_[_loc3_]);
- }
- }
- }
- _loc3_ = _loc3_ - 1;
- }
- }
- function updateTime(elapsed)
- {
- if(!this.keepTrackOfTime)
- {
- return undefined;
- }
- this.raceTime += elapsed;
- this.timeRemaining -= elapsed;
- if(this.timeRemaining < 0)
- {
- this.onMessage("timeout");
- }
- }
- function update(elapsed, xShift, yShift, zShift)
- {
- this.updatePosition(elapsed,xShift,yShift,zShift);
- this.updateTime(elapsed);
- if(this.specialItem)
- {
- this.specialItem.update(this,elapsed);
- }
- this.sledSound.setVolume(Math.min(this.currentSpeed / 4000 * 100,35));
- }
- function finishRace()
- {
- this.keepTrackOfTime = false;
- this.inMotion = false;
- this.onMessage("finish");
- }
- function setElevated(elevated)
- {
- this.elevated = elevated;
- if(elevated)
- {
- this.radius *= 2;
- this.target.sled.blades._y += 25;
- }
- else
- {
- this.target.sled.blades._y -= 25;
- delete this.radius;
- }
- }
- function updatePosition(elapsed, xShift, yShift, zShift)
- {
- var _loc23_ = elapsed;
- var _loc18_ = this.sector;
- if(this.inMotion)
- {
- this.currentSpeed += ((0.5 * zShift + 1) * 650 + 10 * this.sector.direction.y - this.currentSpeed) * elapsed;
- }
- else
- {
- this.currentSpeed += (- this.currentSpeed) * elapsed;
- }
- this.currentSpeed = Math.min(this.maxSpeed,this.currentSpeed);
- this.velocity.z += (this.currentSpeed * this.sector.direction.z - this.velocity.z) * elapsed;
- this.oldZ = this.z;
- this.oldY = this.y;
- this.oldX = this.x;
- this.z += this.velocity.z * elapsed;
- var _loc22_ = this.z - this.oldZ;
- if(this.isOnGround)
- {
- this.velocity.x += (this.currentSpeed * this.sector.direction.x + this.surfacePlane.x * xShift * this.velocity.z * 8 - this.velocity.x) * elapsed;
- this.velocity.y += (this.currentSpeed * this.sector.direction.y + this.surfacePlane.y * xShift * this.velocity.z * 8 + 800 * this.sector.yScale - this.velocity.y) * elapsed;
- }
- else
- {
- this.velocity.y += 2400 * elapsed;
- }
- var _loc10_ = this.x + this.velocity.x * elapsed;
- var _loc11_ = this.y + this.velocity.y * elapsed;
- _loc18_ = this.sector;
- if(this.sector)
- {
- this.checkSectorLocation();
- }
- this.checkCollisions(_loc18_,this.sector);
- var _loc7_ = (this.z - this.sector.previous.z) / (this.sector.z - this.sector.previous.z);
- var _loc6_ = this.sector.previous.radius + (this.sector.radius - this.sector.previous.radius) * _loc7_ - this.radius;
- var _loc8_ = this.sector.previous.xScale + (this.sector.xScale - this.sector.previous.xScale) * _loc7_;
- var _loc12_ = this.sector.previous.yScale + (this.sector.yScale - this.sector.previous.yScale) * _loc7_;
- var _loc3_ = this.sector.previous.x + (this.sector.x - this.sector.previous.x) * _loc7_;
- var _loc5_ = this.sector.previous.y + (this.sector.y - this.sector.previous.y) * _loc7_;
- var _loc16_ = new Point((_loc10_ - _loc3_) / _loc8_,(_loc11_ - _loc5_) / _loc12_);
- var _loc19_ = _loc16_.magnitude;
- this.up = _loc16_.getNormalized();
- this.surfacePlane = this.up.cross();
- if((!this.sector.arcClosed || !this.sector.previous.arcClosed) && _loc11_ < _loc5_)
- {
- if(!this.isOnGround)
- {
- }
- this.velocity.x = this.sector.direction.x * this.velocity.magnitude;
- _loc10_ = Math.min(Math.max(_loc10_,_loc3_ - _loc6_ * _loc8_),_loc3_ + _loc6_ * _loc8_);
- this.isOnGround = false;
- }
- else if(this.isOnGround = _loc19_ > _loc6_)
- {
- _loc10_ = _loc3_ + this.up.x * _loc6_ * _loc8_;
- _loc11_ = _loc5_ + this.up.y * _loc6_ * _loc12_;
- this.target._rotation = Math.atan2(this.surfacePlane.y / _loc8_,this.surfacePlane.x / _loc12_) * 180 / 3.14;
- }
- this.x = _loc10_;
- this.y = _loc11_;
- this.updateDepth();
- var _loc13_ = Math.pow(_loc6_ + this.radius,2);
- var _loc9_ = this.x - _loc3_;
- var _loc17_ = Math.sqrt(_loc13_ - _loc9_ * _loc9_);
- var _loc15_ = _loc9_ - this.radius;
- var _loc21_ = Math.sqrt(_loc13_ - _loc15_ * _loc15_);
- var _loc14_ = _loc9_ + this.radius;
- var _loc20_ = Math.sqrt(_loc13_ - _loc14_ * _loc14_);
- var _loc4_ = this.sector.yScale;
- this.shadowX = _loc3_ + _loc9_;
- this.shadowY = _loc5_ + _loc17_ * _loc4_ + (1 - _loc4_) * this.radius;
- this.shadowLeftX = _loc3_ + _loc15_;
- this.shadowLeftY = _loc5_ + _loc21_ * _loc4_ + (1 - _loc4_) * this.radius;
- this.shadowRightX = _loc3_ + _loc14_;
- this.shadowRightY = _loc5_ + _loc20_ * _loc4_ + (1 - _loc4_) * this.radius;
- return undefined;
- }
- function onDisplay(offsetX, offsetY, offsetZ, depthRatio)
- {
- this.shadow.swapDepths(this.target.getDepth() - 1);
- this.shadow.clear();
- this.shadow.beginFill(this.world.fogColor.valueOf());
- var _loc3_ = this.world.camera.depthFocus / (offsetZ + 10);
- var _loc6_ = this.world.camera.depthFocus / (offsetZ + 5);
- var _loc5_ = this.world.camera.x;
- var _loc4_ = this.world.camera.y;
- var _loc10_ = this.shadowX - _loc5_;
- var _loc8_ = this.shadowY - _loc4_;
- var _loc9_ = this.shadowLeftX - _loc5_;
- var _loc7_ = this.shadowLeftY - _loc4_;
- var _loc12_ = this.shadowRightX - _loc5_;
- var _loc11_ = this.shadowRightY - _loc4_;
- var _loc17_ = (this.shadowX - _loc5_) * depthRatio;
- var _loc16_ = (this.shadowY - _loc4_) * depthRatio;
- this.shadow.moveTo(_loc10_ * depthRatio,_loc8_ * depthRatio);
- this.shadow.curveTo(_loc9_ * depthRatio,_loc7_ * depthRatio,_loc9_ * _loc6_,_loc7_ * _loc6_);
- this.shadow.curveTo(_loc9_ * _loc3_,_loc7_ * _loc3_,_loc10_ * _loc3_,_loc8_ * _loc3_);
- this.shadow.curveTo(_loc12_ * _loc3_,_loc11_ * _loc3_,_loc12_ * _loc6_,_loc11_ * _loc6_);
- this.shadow.curveTo(_loc12_ * depthRatio,_loc11_ * depthRatio,_loc10_ * depthRatio,_loc8_ * depthRatio);
- var _loc13_ = this.velocity.x * this.surfacePlane.x + this.velocity.y * this.surfacePlane.y;
- var _loc15_ = Math.max(- this.maxDisplayTurn,Math.min(this.maxDisplayTurn,Math.atan2(this.velocity.z,_loc13_ * 0.4) * 180 / 3.141592653589793 - 90));
- if(this.currentTurnFrame == (this.currentTurnFrame = this.centerFrame - Math.round(_loc15_ / this.turnDegreePerFrame)))
- {
- return undefined;
- }
- this.target.sled.gotoAndStop(this.currentTurnFrame);
- this.target.sled.blades.gotoAndStop(this.currentTurnFrame);
- this.hideSpecialItems();
- this.specialItem.applyDisplay(this,offsetX,offsetY,offsetZ,depthRatio);
- }
- function onEffects()
- {
- this.specialItem.renderEffects(this);
- }
- function toString()
- {
- return "Sled";
- }
- }
-