home *** CD-ROM | disk | FTP | other *** search
- class Game extends MovieClip
- {
- var mcSummary;
- var lives;
- var points;
- var mcLevel;
- var mcStatusBar;
- var mcPoints;
- var mcEnergy;
- var mcLives;
- var btnPause;
- var aRoadTiles;
- var aRoadDef;
- var aRandomCarsDef;
- var aEnemiesDef;
- var mcBonus;
- var bmpRoad;
- var bmpShoulder;
- var mcCanvas;
- var aRoad;
- var aRoadBmp;
- var aRoadNames;
- var aRoadShoulderBmp;
- var aRoadShoulderNames;
- var roadInd;
- var lane;
- var distance;
- var totalDistance;
- var sEnemy;
- var enemy;
- var player;
- var aRandomCars;
- var onEnterFrame;
- var mcObstacle;
- var puddle;
- var mcShot;
- var mcContinue;
- var mcMissionInfo;
- var counter;
- var startTime;
- var oKeyList;
- static var instance;
- static var carDepth;
- static var bulletDepth;
- static var level = 0;
- static var screenW = 550;
- static var screenH = 400;
- function Game(Void)
- {
- super();
- Game.instance = this;
- this.mcSummary.gotoAndStop(1);
- this.lives = !Application.bEasy ? 3 : 4;
- Game.level = 0;
- this.points = 0;
- this.mcLevel = this.mcStatusBar.mcLevel;
- this.mcPoints = this.mcStatusBar.mcPoints;
- this.mcEnergy = this.mcStatusBar.mcEnergy;
- this.mcLives = this.mcStatusBar.mcLives;
- this.btnPause = this.mcStatusBar.btnPause;
- this.btnPause.onRelease = mx.utils.Delegate.create(this,this.onReleasePause);
- this.mcStatusBar.btnEasyMoney.onRelease = function()
- {
- this.getURL("http://www.easymoney.com","_blank");
- };
- this.aRoadTiles = new Array();
- this.aRoadTiles[0] = {ind:0,sName:"road 0",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[1] = {ind:1,sName:"road 1",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[2] = {ind:2,sName:"road 2",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[3] = {ind:3,sName:"road 3",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[4] = {ind:4,sName:"road 4",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[5] = {ind:5,sName:"road 5",width:550,height:400,b2Lanes:true};
- this.aRoadTiles[6] = {ind:6,sName:"road 6",width:550,height:200,b2Lanes:true};
- this.aRoadTiles[7] = {ind:7,sName:"road 7",width:550,height:400,b2Lanes:true};
- this.aRoadTiles[8] = {ind:8,sName:"road 8",width:550,height:200,b2Lanes:true};
- this.aRoadTiles[9] = {ind:9,sName:"road 9",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[10] = {ind:10,sName:"road 10",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[11] = {ind:11,sName:"road 11",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[12] = {ind:12,sName:"road 12",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[13] = {ind:13,sName:"road 13",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[14] = {ind:14,sName:"road 14",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[15] = {ind:15,sName:"road 15",width:550,height:400,b2Lanes:false};
- this.aRoadTiles[16] = {ind:16,sName:"road 16",width:550,height:400,b2Lanes:false};
- this.aRoadDef = new Array();
- this.aRoadDef[0] = new Array(0,0,0,0,1,2,2,2,3,4,5,5,6,7,7,7,8,9,2,2,2,3,0,0,0,11,13,13,13,15,0,0,4,5,5,6,7,7,8,5,5,9,2,2,3,0,12,14,14,14,16);
- this.aRandomCarsDef = new Array();
- this.aRandomCarsDef[0] = {sLinkageId:"car1",maxVel:25,minVel:5};
- this.aRandomCarsDef[1] = {sLinkageId:"car2",maxVel:25,minVel:5};
- this.aRandomCarsDef[2] = {sLinkageId:"car3",maxVel:25,minVel:5};
- this.aRandomCarsDef[3] = {sLinkageId:"car4",maxVel:25,minVel:5};
- this.aRandomCarsDef[4] = {sLinkageId:"car5",maxVel:25,minVel:5};
- this.aRandomCarsDef[5] = {sLinkageId:"car6",maxVel:25,minVel:5};
- this.aRandomCarsDef[6] = {sLinkageId:"car7",maxVel:25,minVel:5};
- this.aEnemiesDef = new Array();
- this.aEnemiesDef.push("esure");
- this.aEnemiesDef.push("tesco");
- this.aEnemiesDef.push("directLine");
- this.aEnemiesDef.push("elephant");
- this.aEnemiesDef.push("sainsbury");
- this.aEnemiesDef.push("rac");
- this.aEnemiesDef.push("churchil");
- this.aEnemiesDef.push("moreThan");
- this.aEnemiesDef.push("asda");
- this.aEnemiesDef.push("lloyd");
- this.aEnemiesDef.push("aa");
- this.aEnemiesDef.push("admiral");
- this.showMissionInfo();
- Sounds.stopAllSounds();
- Sounds.playSound("water",99999);
- Sounds.setVolume("water",18);
- Sounds.startAmbience(true);
- this.setPointsMeter();
- this.setLevelMeter();
- this.setLivesMeter();
- this.setEnergyMeter(100);
- }
- static function getInstance(Void)
- {
- return Game.instance;
- }
- function initLevel(Void)
- {
- trace("Application.bEasy> " + Application.bEasy);
- this.btnPause.enabled = true;
- this.mcBonus.gotoAndStop(1);
- Game.carDepth = 10;
- Game.bulletDepth = 100;
- this.bmpRoad = new flash.display.BitmapData(Game.screenW,Game.screenH,false);
- this.bmpShoulder = new flash.display.BitmapData(Game.screenW,Game.screenH,true,0);
- this.mcCanvas.attachBitmap(this.bmpShoulder,0);
- this.mcCanvas.attachBitmap(this.bmpRoad,1,"Never");
- this.aRoad = new Array();
- var _loc4_ = this.aRoadDef[0].length;
- var _loc2_ = 0;
- while(_loc2_ < _loc4_)
- {
- this.aRoad[_loc2_] = this.aRoadTiles[this.aRoadDef[0][_loc2_]];
- _loc2_ = _loc2_ + 1;
- }
- this.aRoadBmp = new Array();
- this.aRoadNames = new Array();
- this.aRoadShoulderBmp = new Array();
- this.aRoadShoulderNames = new Array();
- this.roadInd = 0;
- this.lane = 0;
- this.distance = 0;
- this.totalDistance = 0;
- this.draw();
- this.sEnemy = this.aEnemiesDef[Game.level];
- if(Application.bEasy)
- {
- this.enemy = new Enemy(8000 + 500 * Game.level,this.sEnemy,new flash.geom.Point(275,Game.screenH + 80),new flash.geom.Point(0,0),this.mcCanvas,900);
- }
- else
- {
- this.enemy = new Enemy(15000 + 1000 * Game.level,this.sEnemy,new flash.geom.Point(275,Game.screenH + 80),new flash.geom.Point(0,0),this.mcCanvas,900);
- }
- this.player = new PlayerCar(new flash.geom.Point(300,-50),this.mcCanvas,this.sEnemy);
- var _loc3_ = undefined;
- if(Application.bEasy)
- {
- _loc3_ = Game.level >= 5 ? 2 : 1;
- }
- else
- {
- _loc3_ = 2;
- }
- this.aRandomCars = new Array();
- _loc2_ = 0;
- while(_loc2_ < _loc3_)
- {
- this.addRandomCar(220 + _loc2_ * 60);
- _loc2_ = _loc2_ + 1;
- }
- this.addPuddle(new flash.geom.Point(-50,-55));
- this.setPointsMeter();
- this.setLevelMeter();
- this.setLivesMeter();
- this.setEnergyMeter(100);
- }
- function startWork(Void)
- {
- this.onEnterFrame = this.loop;
- Sounds.stopSound("engineIdle");
- Sounds.playSound("engineIdle",99999);
- }
- function stopWork(Void)
- {
- Sounds.stopSound("engineIdle");
- this.onEnterFrame = null;
- }
- function step(Void)
- {
- this.player.step();
- var _loc7_ = this.bmpShoulder.hitTest(new flash.geom.Point(0,0),250,new flash.geom.Point(this.player.pos.x,Game.screenH - this.player.pos.y));
- if(_loc7_)
- {
- this.player.reactionOnShoulder(this.bmpShoulder);
- }
- this.player.checkObstacle(this.mcObstacle);
- this.player.checkPuddle(this.puddle);
- this.enemy.step(this.player,this.totalDistance,this.bmpShoulder);
- if(this.enemy.bOnScreen)
- {
- this.enemy.checkDistance(this.player);
- this.enemy.checkCollision(this.player,true);
- this.enemy.checkWeapon(this.player.mcWeaponArea);
- }
- var _loc4_ = this.aRandomCars.length;
- var _loc2_ = 0;
- while(_loc2_ < _loc4_)
- {
- this.aRandomCars[_loc2_].step(this.player.pos,this.player.vel,this.bmpShoulder);
- this.aRandomCars[_loc2_].checkDistance(this.player);
- this.aRandomCars[_loc2_].checkCollision(this.player,true);
- if(this.enemy.bOnScreen)
- {
- this.aRandomCars[_loc2_].checkDistance(this.enemy);
- this.aRandomCars[_loc2_].checkCollision(this.enemy,false);
- }
- this.aRandomCars[_loc2_].checkWeapon(this.player.mcWeaponArea);
- var _loc3_ = _loc2_ + 1;
- while(_loc3_ < _loc4_)
- {
- this.aRandomCars[_loc2_].checkDistance(this.aRandomCars[_loc3_]);
- this.aRandomCars[_loc2_].checkCollision(this.aRandomCars[_loc3_],false);
- _loc3_ = _loc3_ + 1;
- }
- _loc2_ = _loc2_ + 1;
- }
- if(this.mcShot)
- {
- this.mcShot.step(this.player.vel);
- }
- if(this.mcObstacle)
- {
- this.mcObstacle.step(this.player.vel);
- }
- var _loc6_ = "";
- var _loc5_ = this.aRoad[this.roadInd];
- this.totalDistance += this.player.vel.y;
- this.distance += this.player.vel.y;
- if(this.distance > _loc5_.height)
- {
- this.roadInd = this.roadInd + 1;
- if(this.roadInd == this.aRoad.length)
- {
- this.roadInd = 0;
- }
- this.distance -= _loc5_.height;
- _loc6_ = _loc5_.sName;
- }
- if(_loc5_.b2Lanes && this.player.pos.x > Game.screenW / 2)
- {
- this.lane = 1;
- }
- else
- {
- this.lane = 0;
- }
- this.setRoadBmp(_loc6_);
- this.puddle.step(this.player.vel);
- }
- function draw(Void)
- {
- this.player.draw();
- this.enemy.draw();
- var _loc13_ = this.aRandomCars.length;
- var _loc2_ = 0;
- while(_loc2_ < _loc13_)
- {
- this.aRandomCars[_loc2_].draw();
- _loc2_ = _loc2_ + 1;
- }
- if(this.mcShot)
- {
- this.mcShot.draw();
- }
- if(this.mcObstacle)
- {
- this.mcObstacle.draw();
- }
- _loc13_ = this.aRandomCars.length;
- _loc2_ = 0;
- while(_loc2_ < _loc13_)
- {
- this.aRandomCars[_loc2_].step(this.player.pos,this.player.vel,this.bmpShoulder);
- _loc2_ = _loc2_ + 1;
- }
- this.bmpShoulder.fillRect(this.bmpShoulder.rectangle,0);
- var _loc3_ = - this.distance;
- var _loc6_ = this.roadInd;
- _loc13_ = this.aRoadBmp.length;
- _loc2_ = 0;
- while(_loc2_ < _loc13_)
- {
- var _loc4_ = this.aRoad[_loc6_];
- var _loc9_ = this.aRoadBmp[_loc2_];
- var _loc11_ = this.aRoadShoulderBmp[_loc2_];
- var _loc5_ = 0;
- _loc3_ += _loc4_.height - 1;
- if(_loc3_ > Game.screenH)
- {
- _loc5_ = _loc3_ - Game.screenH;
- _loc3_ = Game.screenH;
- }
- var _loc10_ = _loc5_;
- var _loc12_ = _loc4_.height - 1 - _loc5_;
- var _loc7_ = new flash.geom.Rectangle(0,_loc10_,_loc4_.width,_loc12_);
- var _loc8_ = new flash.geom.Point(0,Game.screenH - _loc3_);
- this.bmpRoad.copyPixels(_loc9_,_loc7_,_loc8_,null,null,false);
- this.bmpShoulder.copyPixels(_loc11_,_loc7_,_loc8_,null,null,true);
- _loc6_ = _loc6_ + 1;
- if(_loc6_ == this.aRoad.length)
- {
- _loc6_ = 0;
- }
- _loc2_ = _loc2_ + 1;
- }
- this.puddle.draw();
- }
- function setRoadBmp(sBmpToRemove)
- {
- this.aRoadNames[sBmpToRemove].dispose();
- delete this.aRoadNames[sBmpToRemove];
- this.aRoadShoulderNames[sBmpToRemove].dispose();
- delete this.aRoadShoulderNames[sBmpToRemove];
- this.aRoadBmp = new Array();
- this.aRoadShoulderBmp = new Array();
- var _loc3_ = this.roadInd;
- var _loc7_ = - this.distance;
- var _loc4_ = undefined;
- var _loc2_ = undefined;
- var _loc5_ = 0;
- do
- {
- _loc4_ = this.aRoad[_loc3_];
- if(_loc4_.b2Lanes && (this.aRoad[_loc3_ + 1].ind == 10 || this.aRoad[_loc3_ + 1].ind == 9))
- {
- var _loc6_ = 10 - this.lane;
- this.aRoad[_loc3_ + 1] = this.aRoadTiles[_loc6_];
- }
- _loc2_ = _loc4_.sName;
- if(this.aRoadNames[_loc2_] == undefined)
- {
- this.aRoadNames[_loc2_] = flash.display.BitmapData.loadBitmap(_loc2_);
- this.aRoadShoulderNames[_loc2_] = flash.display.BitmapData.loadBitmap(_loc2_ + " shoulder");
- }
- this.aRoadBmp[_loc5_] = this.aRoadNames[_loc2_];
- this.aRoadShoulderBmp[_loc5_] = this.aRoadShoulderNames[_loc2_];
- _loc7_ += _loc4_.height;
- _loc5_ = _loc5_ + 1;
- _loc3_ = _loc3_ + 1;
- if(_loc3_ == this.aRoad.length)
- {
- _loc3_ = 0;
- }
- }
- while(_loc7_ < Game.screenH);
-
- }
- function removeRandomCar(refCar)
- {
- var _loc4_ = this.aRandomCars.length;
- var _loc2_ = 0;
- while(_loc2_ < _loc4_)
- {
- if(this.aRandomCars[_loc2_] == refCar)
- {
- this.aRandomCars.splice(_loc2_,1);
- refCar.remove();
- break;
- }
- _loc2_ = _loc2_ + 1;
- }
- }
- function addRandomCar(posX)
- {
- var _loc7_ = this.aRandomCarsDef.length;
- var _loc10_ = Math.floor(_loc7_ * Math.random());
- var _loc3_ = this.aRandomCarsDef[_loc10_];
- var _loc12_ = _loc3_.maxVel - _loc3_.minVel;
- var _loc5_ = this.player.vel.y + 4 * (1 - 2 * Math.random());
- if(_loc5_ < _loc3_.minVel)
- {
- _loc5_ = _loc3_.minVel;
- }
- else if(_loc5_ > _loc3_.maxVel)
- {
- _loc5_ = _loc3_.maxVel;
- }
- var _loc6_ = new flash.geom.Point(0,_loc5_);
- var _loc2_ = new flash.geom.Point();
- var _loc4_ = undefined;
- if(this.player.vel.y < _loc6_.y)
- {
- _loc2_.y = -50;
- _loc4_ = Game.screenH - 1;
- }
- else
- {
- _loc2_.y = Game.screenH + 50;
- _loc4_ = 1;
- }
- if(posX == undefined)
- {
- do
- {
- _loc2_.x = 30 + 440 * Math.random();
- }
- while(this.bmpShoulder.hitTest(new flash.geom.Point(0,0),250,new flash.geom.Point(_loc2_.x,_loc4_)));
-
- }
- else
- {
- _loc2_.x = posX;
- }
- var _loc8_ = !this.player.bEnter ? 0 : 150;
- var _loc9_ = new Car(_loc3_.sLinkageId,_loc2_,_loc6_,this.mcCanvas,Game.carDepth,_loc8_);
- this.aRandomCars.push(_loc9_);
- Game.carDepth += 3;
- if(Game.carDepth > 190)
- {
- Game.carDepth = 100;
- }
- }
- function addPuddle(posNew)
- {
- var _loc4_ = Math.round(Math.random());
- var _loc2_ = undefined;
- if(posNew != undefined)
- {
- _loc2_ = posNew.clone();
- }
- else
- {
- _loc2_ = new flash.geom.Point(0,1);
- do
- {
- _loc2_.x = 50 + Math.round(450 * Math.random());
- var _loc3_ = new flash.geom.Point(0,0);
- var hit0 = this.bmpShoulder.hitTest(_loc3_,250,_loc2_);
- _loc2_.x += 34;
- var hit1 = this.bmpShoulder.hitTest(_loc3_,250,_loc2_);
- _loc2_.x += 34;
- var hit2 = this.bmpShoulder.hitTest(_loc3_,250,_loc2_);
- }
- while(hit0 || hit1 || hit2);
-
- _loc2_.y = Game.screenH;
- }
- this.puddle = new Puddle(_loc2_,_loc4_,this.mcCanvas);
- }
- function removePuddle(Void)
- {
- this.puddle.remove();
- this.addPuddle();
- }
- function loseLife(Void)
- {
- this.lives = this.lives - 1;
- this.setLivesMeter();
- this.setEnergyMeter(100);
- if(this.lives <= 0)
- {
- this.gameOver(false);
- }
- else
- {
- this.player.newLife();
- }
- }
- function gameOver(bWin)
- {
- this.stopWork();
- if(!bWin)
- {
- this.mcContinue.gotoAndPlay("show");
- this.mcContinue.value = 10;
- this.onEnterFrame = this.checkContinue;
- }
- else
- {
- this.mcSummary.bWin = bWin;
- this.mcSummary.gotoAndPlay(1);
- }
- }
- function onEnemyDead(Void)
- {
- this.enemy.remove;
- delete this.enemy;
- this.player.bExit = true;
- this.player.hideWeapon();
- }
- function onPlayerOut(Void)
- {
- Game.level = Game.level + 1;
- this.stopWork();
- if(Game.level >= this.aEnemiesDef.length)
- {
- this.gameOver(true);
- }
- else
- {
- this.removeRoad();
- this.showMissionInfo();
- }
- }
- function createShot(Void)
- {
- var _loc2_ = Game.bulletDepth;
- this.mcShot = this.mcCanvas.attachMovie(this.sEnemy + " shot","mcShot" + _loc2_,_loc2_);
- this.mcShot.pos.x = this.player.pos.x;
- this.mcShot.pos.y = this.player.pos.y + this.player.height / 2;
- this.mcShot.vel.x = 0;
- this.mcShot.vel.y = 15;
- this.mcShot.type = 0;
- Game.bulletDepth = Game.bulletDepth + 1;
- if(Game.bulletDepth > 290)
- {
- Game.bulletDepth = 200;
- }
- return this.mcShot;
- }
- function removeShot(Void)
- {
- this.mcShot.removeMovieClip();
- }
- function createObstacle(Void)
- {
- this.mcObstacle = this.mcCanvas.attachMovie(this.sEnemy + " obstacle","mcObstacle",6);
- this.mcObstacle.pos.x = this.enemy.pos.x;
- this.mcObstacle.pos.y = this.enemy.pos.y;
- this.mcObstacle.vel.x = 0;
- this.mcObstacle.vel.y = -8;
- this.mcObstacle.type = 1;
- }
- function removeObstacle(Void)
- {
- this.mcObstacle.removeMovieClip();
- }
- function setEnergyMeter(energy)
- {
- this.mcEnergy.gotoAndStop(1 + energy / 10);
- }
- function setLivesMeter(Void)
- {
- this.mcLives.gotoAndStop(1 + this.lives);
- }
- function setLevelMeter(Void)
- {
- this.mcLevel.tfLevel.text = Game.level + 1;
- }
- function setPointsMeter(Void)
- {
- var _loc3_ = 5;
- var _loc2_ = this.points.toString().length;
- var _loc4_ = "00000";
- this.mcPoints.tfPoints.text = _loc4_.substr(0,_loc3_ - _loc2_) + this.points;
- }
- function removeRoad(Void)
- {
- this.enemy.remove();
- this.bmpRoad.dispose();
- this.bmpShoulder.dispose();
- this.player.remove();
- while(this.aRandomCars.length > 0)
- {
- this.removeRandomCar(this.aRandomCars[0]);
- }
- this.removeObstacle(this.mcObstacle);
- this.removeShot(this.mcShot);
- }
- function showMissionInfo(Void)
- {
- this.sEnemy = this.aEnemiesDef[Game.level];
- this.mcMissionInfo.attachMovie("mission info","mcInfo",0);
- this.btnPause.enabled = false;
- }
- function loop(Void)
- {
- this.step();
- this.draw();
- }
- function protectPlayer(Void)
- {
- this.player.setShieldOn();
- }
- function onReleasePause(Void)
- {
- if(this.onEnterFrame == null || this.onEnterFrame == undefined)
- {
- this.startWork();
- }
- else
- {
- this.stopWork();
- }
- }
- function addPoints(value)
- {
- this.points += value;
- if(this.points < 0)
- {
- this.points = 0;
- }
- this.setPointsMeter();
- }
- function showBonus(Void)
- {
- this.mcBonus.play();
- }
- function showPoints(pos, value)
- {
- var _loc3_ = this.mcCanvas.getNextHighestDepth();
- var _loc2_ = this.mcCanvas.attachMovie("points anim","points" + _loc3_,_loc3_);
- _loc2_._x = pos.x;
- _loc2_._y = Game.screenH - pos.y;
- _loc2_.points = value <= 0 ? value : "+" + value;
- }
- function checkContinue(Void)
- {
- if(this.mcContinue._currentframe == this.mcContinue._totalframes)
- {
- this.onEnterFrame = this.countDown;
- this.counter = 10;
- this.startTime = getTimer() + 1000;
- this.mcContinue.btnYes.onRelease = mx.utils.Delegate.create(this,this.onReleaseYes);
- this.mcContinue.btnNo.onRelease = mx.utils.Delegate.create(this,this.onReleaseNo);
- this.oKeyList = new Object();
- this.oKeyList.onKeyDown = mx.utils.Delegate.create(this,this.onSpaceCont);
- Key.addListener(this.oKeyList);
- }
- }
- function countDown(Void)
- {
- this.mcContinue.value = this.counter;
- if(getTimer() - this.startTime > 1000)
- {
- this.startTime = getTimer();
- this.counter = this.counter - 1;
- if(this.counter < 0)
- {
- this.onEnterFrame = null;
- this.onReleaseNo();
- }
- }
- }
- function onReleaseYes(Void)
- {
- Key.removeListener(this.oKeyList);
- this.onEnterFrame = null;
- this.mcContinue.gotoAndStop("hide");
- this.points = 0;
- this.setPointsMeter();
- this.lives = 4;
- this.setLivesMeter();
- this.player.newLife();
- this.startWork();
- }
- function onReleaseNo(Void)
- {
- Key.removeListener(this.oKeyList);
- this.onEnterFrame = null;
- this.mcContinue.gotoAndStop("hide");
- this.mcSummary.bWin = false;
- this.mcSummary.gotoAndPlay(1);
- }
- function onSpaceCont(Void)
- {
- if(Key.isDown(32))
- {
- this.onReleaseYes();
- }
- }
- function setLives(Void)
- {
- this.lives = !Application.bEasy ? 3 : 4;
- this.setLivesMeter();
- }
- }
-