home *** CD-ROM | disk | FTP | other *** search
- class Game extends MovieClip
- {
- var sectors;
- var objects;
- var backgrounds;
- var effectsObjects;
- var updateObjects;
- var camera;
- var display;
- var outsideFogColor;
- var deadPreview;
- var fogColor;
- var width;
- var height;
- var halfWidth;
- var halfHeight;
- var levelSpline;
- var currentVisibleMarker;
- var fogDistanceNear = 200;
- var fogDistanceFar = 3000;
- var fogAmount = 0;
- var nearestSector = 0;
- var objectCount = 0;
- function Game()
- {
- super();
- this.sectors = new Array();
- this.objects = new Array();
- this.backgrounds = new Array();
- this.effectsObjects = new Array();
- this.updateObjects = new Array();
- this.camera = new GameCamera();
- this.addObject(this.camera);
- this.camera.update();
- this.camera.moveTo(0,0,1);
- this.display = this.createEmptyMovieClip("display",100);
- this.setSize(this._width,this._height);
- this._xscale = 100;
- this._yscale = 100;
- this.setFog(new RGB(62,153,255),200,4500,0);
- this.outsideFogColor = new RGB(215,215,235);
- this.deadPreview.swapDepths(255);
- this.deadPreview.removeMovieClip();
- }
- function addBackground(bg)
- {
- bg.target = this.display.attachMovie(bg.linkageID,"BG" + this.backgrounds.length,bg.depth);
- this.backgrounds.push(bg);
- this.backgrounds.sortOn(bg.depth,Array.NUMERIC);
- }
- function setFog(color, near, far, amount)
- {
- this.fogColor = color;
- this.fogDistanceNear = near;
- this.fogDistanceFar = far;
- this.fogAmount = Math.min(1,Math.max(Number(amount),0));
- }
- function setSize(width, height)
- {
- this.width = width;
- this.height = height;
- this.halfWidth = width * 0.5;
- this.halfHeight = height * 0.5;
- this.display._x = width * 0.5;
- this.display._y = height * 0.5;
- }
- function registerForUpdates(object)
- {
- if(object.___GU)
- {
- return undefined;
- }
- object.___GU = true;
- this.updateObjects.push(object);
- }
- function removeFromUpdates(object)
- {
- var _loc2_ = this.updateObjects.length - 1;
- while(_loc2_ > -1)
- {
- if(this.updateObjects[_loc2_] == object)
- {
- this.updateObjects.splice(_loc2_,1);
- }
- _loc2_ = _loc2_ - 1;
- }
- }
- function registerForEffects(object)
- {
- if(object.___EF)
- {
- return undefined;
- }
- object.___EF = true;
- this.effectsObjects.push(object);
- }
- function addObject(object, x, y, z, marker)
- {
- this.objects.push(object);
- object.uniqueID = this.objectCount++;
- object.world = this;
- object.moveTo(x,y,z);
- if(!object.trackInSectorGrid)
- {
- return undefined;
- }
- if(!marker)
- {
- marker = this.findMarker(z);
- }
- this.sectors[marker].addObject(object);
- object.sector = this.sectors[marker];
- object.onAddToWorld();
- if(object.inScene)
- {
- object.addToScene();
- }
- }
- function removeObject(object)
- {
- var _loc2_ = this.objects.length;
- while(_loc2_ > -1)
- {
- if(this.objects[_loc2_] == object)
- {
- this.objects.splice(_loc2_,1);
- }
- _loc2_ = _loc2_ - 1;
- }
- object.removeFromScene();
- object.sector.removeObject(object);
- }
- function findMarker(z)
- {
- var _loc2_ = 0;
- var _loc4_ = this.sectors.length - 1;
- var _loc3_ = Math.round((_loc4_ - _loc2_) * 0.5);
- var _loc6_ = 0;
- if(z <= this.sectors[_loc2_].z)
- {
- return 0;
- }
- if(z >= this.sectors[_loc4_].z)
- {
- return _loc4_;
- }
- while(true)
- {
- if(z >= this.sectors[_loc2_].z && z < this.sectors[_loc3_].z)
- {
- _loc4_ = _loc3_;
- _loc3_ = _loc2_ + Math.round((_loc4_ - _loc2_) * 0.5);
- }
- else
- {
- _loc2_ = _loc3_;
- _loc3_ = _loc2_ + Math.round((_loc4_ - _loc2_) * 0.5);
- }
- if(_loc2_ == _loc3_ || _loc4_ == _loc3_)
- {
- return _loc4_;
- }
- }
- }
- function finalizeLevel()
- {
- }
- function setLevelSpline(spline)
- {
- this.levelSpline = spline;
- }
- function update(elapsed)
- {
- var _loc2_ = this.updateObjects.length - 1;
- while(_loc2_ > -1)
- {
- this.updateObjects[_loc2_].onUpdate(elapsed);
- _loc2_ = _loc2_ - 1;
- }
- }
- function processLevel(maxSpan, range, flip)
- {
- if(!range)
- {
- range = maxSpan * 0.2;
- }
- var _loc18_ = 5;
- var _loc21_ = 0.01;
- this.levelSpline.flipped = flip;
- var _loc19_ = this.levelSpline.length;
- var _loc7_ = undefined;
- var _loc2_ = undefined;
- var _loc3_ = undefined;
- var _loc22_ = undefined;
- var _loc23_ = undefined;
- var _loc10_ = new Vector();
- var _loc14_ = 0;
- var _loc9_ = 0;
- while(_loc9_ < _loc19_)
- {
- _loc3_ = this.levelSpline.getPoint(_loc9_);
- if(_loc2_)
- {
- var _loc12_ = 0;
- _loc10_.loc(_loc3_.x - _loc2_.x,_loc3_.y - _loc2_.y,_loc3_.z - _loc2_.z);
- var _loc6_ = _loc10_.magnitude;
- var _loc5_ = _loc21_;
- while(_loc12_ < _loc18_)
- {
- if(Math.abs(_loc6_ - maxSpan) < range)
- {
- break;
- }
- if(_loc14_ != Math.floor(_loc9_))
- {
- _loc5_ = _loc9_ - (_loc9_ = Math.floor(_loc9_));
- _loc3_ = this.levelSpline.getPoint(_loc9_);
- break;
- }
- var _loc16_ = maxSpan / _loc6_;
- _loc9_ -= _loc5_;
- _loc9_ += _loc5_ = _loc5_ * maxSpan / _loc6_;
- if(_loc14_ == Math.floor(_loc9_))
- {
- _loc3_ = this.levelSpline.getPoint(_loc9_);
- _loc10_.loc(_loc3_.x - _loc2_.x,_loc3_.y - _loc2_.y,_loc3_.z - _loc2_.z);
- _loc6_ = _loc10_.magnitude;
- _loc12_ += 1;
- }
- }
- }
- _loc22_ = this.levelSpline.getRadius(_loc9_);
- _loc7_ = _loc2_;
- _loc2_ = this.levelSpline.getCourseSegment(this,_loc9_);
- _loc2_.index = this.sectors.length;
- _loc2_.color = this.levelSpline.getRGB(_loc9_);
- var _loc15_ = this.levelSpline.getAssetName(_loc9_);
- if(_loc15_ != null)
- {
- _loc2_.assetName = _loc15_;
- }
- if((_loc2_.useTint = this.levelSpline[Math.floor(_loc9_)].useTint) == null)
- {
- delete _loc2_.useTint;
- }
- _loc2_.worldIndex = _loc9_;
- _loc2_.span = new Vector(_loc3_.x - _loc7_.x,_loc3_.y - _loc7_.y,_loc3_.z - _loc7_.z);
- _loc2_.length = _loc2_.span.length;
- _loc2_.direction = _loc2_.span.getNormalized();
- _loc2_.arcClosed = this.levelSpline[Math.floor(_loc9_)].arcClosed;
- _loc2_.arcClosedFace = !_loc7_.arcClosed && _loc2_.arcClosed;
- _loc7_.next = _loc2_;
- _loc2_.previous = _loc7_;
- this.sectors.push(_loc2_);
- _loc14_ = Math.floor(_loc9_);
- _loc9_ += _loc21_;
- }
- _loc2_ = this.sectors[0];
- _loc9_ = 0;
- while(_loc9_ < _loc19_)
- {
- var _loc17_ = this.levelSpline[Math.floor(_loc9_)];
- var _loc8_ = _loc17_.objects;
- if(_loc8_.length != 0)
- {
- _loc8_.sortOnNumeric("index");
- var _loc13_ = _loc8_.length;
- while((_loc13_ = _loc13_ - 1) > -1)
- {
- var _loc4_ = _loc8_[_loc13_];
- this.addObjectRelativeToSpline(_loc4_.object,_loc9_ + _loc4_.index,_loc4_.angle,_loc4_.elevation,_loc4_.useRotation,_loc2_);
- _loc2_ = _loc4_.object.sector;
- }
- }
- _loc9_ = _loc9_ + 1;
- }
- this.currentVisibleMarker = this.sectors[0];
- }
- function addObjectRelativeToSpline(object, index, angle, elevation, useRotation, sector)
- {
- var _loc3_ = this.levelSpline.getPoint(index);
- var _loc8_ = this.levelSpline.getRadius(index);
- if(!sector)
- {
- sector = this.sectors[0];
- }
- else
- {
- while(sector && _loc3_.z < sector.z)
- {
- sector = sector.previous;
- }
- }
- while(sector && _loc3_.z > sector.z)
- {
- sector = sector.next;
- }
- var _loc6_ = Math.sin(Number(angle + 90) / 180 * 3.141592653589793) * sector.yScale;
- var _loc5_ = Math.cos(Number(angle + 90) / 180 * 3.141592653589793) * sector.xScale;
- if(this.levelSpline.flipped)
- {
- _loc5_ *= -1;
- angle = Math.atan2(_loc6_,_loc5_) * 180 / 3.141592653589793 - 90;
- }
- if(useRotation)
- {
- object.setAssetRotation(angle);
- object.up = new Point(- _loc5_,- _loc6_);
- }
- else
- {
- object.up = new Point(0,-1);
- }
- object.up.normalize();
- object.right = object.up.cross();
- this.addObject(object,_loc3_.x + _loc5_ * (_loc8_ - object.radius - elevation - object.generatorDisplacement),_loc3_.y + _loc6_ * (_loc8_ - object.radius - elevation - object.generatorDisplacement),_loc3_.z,sector.index);
- }
- function render()
- {
- while(this.currentVisibleMarker.previous && this.currentVisibleMarker.previous.z - this.camera.z > this.camera.hither)
- {
- this.currentVisibleMarker = this.currentVisibleMarker.previous;
- }
- if(this.currentVisibleMarker.z - this.camera.z < this.camera.hither)
- {
- this.currentVisibleMarker.removeFromScene();
- while(this.currentVisibleMarker = this.currentVisibleMarker.next)
- {
- if(this.currentVisibleMarker.z - this.camera.z > this.camera.hither)
- {
- break;
- }
- this.currentVisibleMarker.removeFromScene();
- }
- }
- var _loc5_ = undefined;
- var _loc8_ = undefined;
- var _loc7_ = undefined;
- var _loc2_ = undefined;
- var _loc4_ = this.currentVisibleMarker;
- var _loc15_ = new RGB();
- var _loc11_ = 16777215;
- while(_loc4_)
- {
- _loc2_ = _loc4_.z - this.camera.z;
- if(_loc2_ > this.camera.yon)
- {
- _loc4_.removeFromScene();
- if(!_loc4_ = _loc4_.next.target)
- {
- break;
- }
- }
- else
- {
- var _loc13_ = Math.min(1,Math.max(0,(_loc2_ - this.fogDistanceNear) / this.fogDistanceFar)) * this.fogAmount;
- _loc8_ = _loc4_.x - this.camera.x;
- _loc7_ = _loc4_.y - this.camera.y;
- var _loc12_ = _loc5_;
- _loc5_ = this.camera.depthFocus / _loc2_;
- var _loc14_ = this.camera.depthFocus / (_loc4_.midPoint.z - this.camera.z);
- _loc4_.setDisplay(_loc8_,_loc7_,_loc5_,_loc12_,_loc13_);
- if(!_loc4_.arcClosed)
- {
- _loc11_ = Math.min(_loc11_,_loc2_);
- }
- if(_loc4_.hasObjects)
- {
- var _loc3_ = undefined;
- var _loc9_ = _loc4_.objects;
- var _loc10_ = _loc9_.length - 1;
- while(_loc10_ > -1)
- {
- _loc3_ = _loc9_[_loc10_];
- _loc2_ = _loc3_.z - this.camera.z;
- if(_loc3_.target._visible = _loc2_ > this.camera.hither && _loc2_ < _loc3_.cullDistance)
- {
- _loc8_ = _loc3_.x - this.camera.x;
- _loc7_ = _loc3_.y - this.camera.y;
- _loc5_ = this.camera.depthFocus / _loc2_;
- _loc3_.setDisplay(_loc8_,_loc7_,_loc2_,_loc5_);
- }
- _loc10_ = _loc10_ - 1;
- }
- }
- _loc4_ = _loc4_.next;
- }
- }
- _loc10_ = this.backgrounds.length - 1;
- while(_loc10_ > -1)
- {
- var _loc6_ = this.backgrounds[_loc10_];
- if(_loc6_.target._visible = _loc11_ < 3000)
- {
- _loc5_ = this.camera.depthFocus / _loc6_.depth;
- _loc6_.target._x = Math.floor((- this.camera.x) * _loc5_);
- _loc6_.target._y = Math.floor((- this.camera.y) * _loc5_);
- _loc6_.target.swapDepths(65535 - Math.floor(_loc6_.depth + this.camera.z) * 100 + 2);
- }
- _loc10_ = _loc10_ - 1;
- }
- _loc10_ = this.effectsObjects.length - 1;
- while(_loc10_ > -1)
- {
- this.effectsObjects[_loc10_].onEffects();
- _loc10_ = _loc10_ - 1;
- }
- updateAfterEvent();
- }
- }
-