home *** CD-ROM | disk | FTP | other *** search
- class Venus_game extends games.Game
- {
- var gameMC;
- var timer;
- var manager;
- var fader;
- var _scoreValue;
- var score;
- var jumperMC;
- var fuelMC;
- var bonus;
- var noColorTransform;
- var itemsArray;
- var itemsByClassArray;
- var objectsscene;
- var _playerOutBounds;
- var _playerInBounds;
- var foregroundscene;
- var backgroundscene;
- var _endLevel = false;
- var _isPaused = false;
- var _bonusValue = 0;
- var _bonusInUse = false;
- var bonusMax = 8;
- var bonus_Values = [1,2,4];
- var bonus_addString = "";
- var bonus_stepdisplay = 10;
- var _superBonusValue = 0;
- var _speedValue = 0;
- var _speedRate = 0;
- var _distance = 0;
- var _lastdistance = 0;
- var _lastitemplace = 0;
- var startSpeed = 50;
- var speedMin = 3;
- var speedMax = 50;
- var rotatMin = 5;
- var prevspeed = 0;
- var resistance = 0.99;
- var minItemDistance = 250;
- var moveByY = 0;
- var multipleY = 8;
- var moveByX = 0;
- var multipleX = 5;
- var moveByHitValue = 0;
- var moveByHitStepValue = 0;
- var moveByHitStep = 1;
- var moveByHitMax = 10;
- var rotateByHitValue = 0;
- var rotateHitStepValue = 0;
- var rotateByHitStep = 2;
- var rotateByHitMax = 52.5;
- var time_endLevelPause = 1500;
- var jumper_jetFrames = 10;
- var jumper_jetEndFrame = 1;
- var jumper_enabledEvents = true;
- var setJumper = null;
- var onBonusUse = null;
- var onKeysMove = null;
- function Venus_game(MC, w, h, managerinstance)
- {
- super();
- this.gameMC = MC;
- this.timer = system.Timer.getInstance(this.gameMC);
- this.manager = managerinstance;
- this.fader = new effects.Fader(this.gameMC);
- this.manager.addListener(this);
- this.gameArea = {_width:w,_height:h};
- this._speedValue = 0;
- this._scoreValue = 0;
- this.score = new games.Score(this,this.gameMC.scoreMC,1010);
- this.score.resetTo(0);
- this.jumperMC = this.gameMC.jumperMC;
- this.jumperMC.swapDepths(111);
- this.jumperMC.gotoAndStop("fly");
- this.jumperMC._x = 212;
- this.jumperMC._y = 221;
- this.jumperMC.man._rotation = 180;
- this.jumperMC.man.jet.gotoAndStop("minimum");
- this.jumperMC.man.jet.flame._visible = false;
- this.jumperMC.man.jet.flame_shadow._visible = false;
- this.jumper_jetEndFrame = this.jumperMC.man.jet._currentframe;
- this.fuelMC = this.gameMC.fuelMC;
- this.fuelMC.swapDepths(1001);
- this.fuelMC.item.gotoAndStop("fuel");
- this.fuelMC.energyline.bar._y = - this.fuelMC.energyline.bar._height;
- this.gameMC.bonusMC.swapDepths(1002);
- this.gameMC.bonusMC.item.gotoAndStop("bonus");
- this.gameMC.bonusMC.energyline.bar._visible = false;
- this.bonus = new games.Bonus(this,this.gameMC.bonusMC.item);
- this.bonus.resetTo("0");
- this.setItems();
- this.noColorTransform = new flash.geom.ColorTransform();
- this.makeScene(this.gameMC);
- }
- function setItems()
- {
- this.itemsArray = new Array();
- this.itemsByClassArray = new Array();
- this.itemsArray[0] = {classname:"item",sndname:"snd_item_item",nextpoint:500,dist:1000,pp:100,superbonus:1,rotation:0,space:200,fuel:0,bonus:0,upper:false};
- this.itemsArray[1] = {classname:"smallfuel",sndname:"snd_item_smallfuel",nextpoint:500,dist:2250,pp:50,superbonus:0,rotation:0,space:200,fuel:0.25,bonus:0,upper:false};
- this.itemsArray[2] = {classname:"bigfuel",sndname:"snd_item_bigfuel",nextpoint:4500,dist:4500,pp:100,superbonus:1,rotation:0,space:200,fuel:1,bonus:0,upper:false};
- this.itemsArray[3] = {classname:"atom",sndname:"snd_item_atom",nextpoint:6000,dist:11000,pp:50,superbonus:0,rotation:0,space:200,fuel:0,bonus:2,upper:false};
- this.itemsArray[4] = {classname:"atom2",sndname:"snd_item_atom",nextpoint:11000,dist:11000,pp:50,superbonus:0,rotation:0,space:0,fuel:0,bonus:2,upper:true};
- this.itemsArray[5] = {classname:"laser",sndname:"snd_enemy_laser",nextpoint:4000,dist:4000,pp:0,superbonus:-10,rotation:0,space:0,fuel:0,bonus:-0.5,upper:true,animation:"stroke"};
- this.itemsArray[6] = {classname:"redstar",sndname:"snd_enemy_enemy",nextpoint:6000,dist:6000,pp:0,superbonus:-10,rotation:-1,space:200,fuel:-0.25,bonus:0,upper:false};
- this.itemsArray[7] = {classname:"enemy",sndname:"snd_enemy_enemy",nextpoint:9000,dist:9000,pp:0,superbonus:-10,rotation:1,space:200,fuel:-0.25,bonus:0,upper:false};
- for(var pos in this.itemsArray)
- {
- this.itemsByClassArray[this.itemsArray[pos].classname] = this.itemsArray[pos];
- }
- }
- function addBonusValue(val)
- {
- this._bonusValue += !(val > 0 && this._bonusValue == 0) ? this._bonusValue * val : 1;
- if(this._bonusValue > this.bonusMax)
- {
- this._bonusValue = this.bonusMax;
- }
- else if(this._bonusValue < 0)
- {
- this._bonusValue = 0;
- }
- this.bonus.setValue(this._bonusValue);
- }
- function addFuelValue(fuel)
- {
- this._speedValue += fuel * this.speedMax;
- if(this._speedValue > this.speedMax)
- {
- this._speedValue = this.speedMax;
- }
- else if(this._speedValue < 0)
- {
- this._speedValue = 0;
- }
- }
- function checkObjectsCollision()
- {
- if(this._bonusInUse == true)
- {
- return undefined;
- }
- var objects = this.objectsscene.getTable();
- var t_length = objects.length;
- var pos;
- var typeobject;
- var hitMC;
- var i = 0;
- while(i < t_length)
- {
- pos = objects[i];
- if(pos.collected != true)
- {
- hitMC = pos.MC.p_hit != undefined ? pos.MC.p_hit : pos.MC;
- if(this.jumperMC.hitTest(hitMC))
- {
- pos.MC.gotoAndPlay("collect");
- pos.collected = true;
- typeobject = this.itemsByClassArray[pos.type];
- break;
- }
- }
- i++;
- }
- if(typeobject == undefined)
- {
- return undefined;
- }
- this.manager.playFX(typeobject.sndname);
- this._scoreValue += typeobject.pp;
- this.score.setValue(this._scoreValue);
- if(typeobject.bonus != 0)
- {
- this.addBonusValue(typeobject.bonus);
- }
- if(typeobject.fuel != 0)
- {
- this.addFuelValue(typeobject.fuel);
- }
- if(typeobject.rotation != 0)
- {
- this.setJumperRotation(typeobject.rotation);
- }
- if(typeobject.animation != undefined)
- {
- this.setJumper = null;
- this.jumperMC.gotoAndPlay(typeobject.animation);
- this.jumper_enabledEvents = false;
- this.jumperMC.onJumperStroke = system.Delegate.create(this,this.backJumperToAction);
- }
- }
- function backJumperToAction()
- {
- this.jumperMC.gotoAndStop("fly");
- this.jumperMC.man.jet.flame._visible = true;
- this.jumperMC.man.jet.flame_shadow._visible = true;
- this.setJumper = this.setJumperOnMove;
- this.jumper_enabledEvents = true;
- }
- function checkForegroundCollision()
- {
- var foregroundBitmap;
- var playerHitPoint = new flash.geom.Point();
- var foregroundPoint = new flash.geom.Point();
- var hitted1;
- var hitted0;
- var hittest;
- var gb = this._playerOutBounds;
- var gb2 = this._playerInBounds;
- var rectangle = new flash.geom.Rectangle(0,0,this.jumperMC._width,this.jumperMC._height);
- var tMC = this.foregroundscene.getMCOf(0);
- var playerBitmap = new flash.display.BitmapData(gb.xMax - gb.xMin,gb.yMax - gb.yMin,true,255);
- var matrix = new flash.geom.Matrix(-1,0,0,1,- gb2.xMin,- gb2.yMin);
- playerBitmap.draw(this.jumperMC,matrix,this.noColorTransform,"normal");
- playerHitPoint.x = gb.xMin;
- playerHitPoint.y = gb.yMin;
- foregroundBitmap = this.foregroundscene.getBitmapOf(0);
- foregroundPoint.x = tMC._x;
- foregroundPoint.y = tMC._y;
- hitted0 = playerBitmap.hitTest(playerHitPoint,255,foregroundBitmap,foregroundPoint,255);
- if(hitted0 == true)
- {
- do
- {
- this.jumperMC._y++;
- playerHitPoint.y++;
- hittest = playerBitmap.hitTest(playerHitPoint,255,foregroundBitmap,foregroundPoint,255);
- }
- while(hittest == true);
-
- }
- playerBitmap.dispose();
- tMC = this.foregroundscene.getMCOf(1);
- playerBitmap = new flash.display.BitmapData(gb.xMax - gb.xMin,gb.yMax - gb.yMin,true,255);
- matrix = new flash.geom.Matrix(-1,0,0,-1,gb2.xMax,gb2.yMax);
- playerBitmap.draw(this.jumperMC,matrix,this.noColorTransform,"normal");
- playerHitPoint.y = this.gameArea._height - gb.yMax;
- foregroundBitmap = this.foregroundscene.getBitmapOf(1);
- foregroundPoint.x = tMC._x;
- foregroundPoint.y = 0;
- hitted1 = playerBitmap.hitTest(playerHitPoint,255,foregroundBitmap,foregroundPoint,255);
- if(hitted1 == true)
- {
- do
- {
- this.jumperMC._y--;
- playerHitPoint.y++;
- hittest = playerBitmap.hitTest(playerHitPoint,255,foregroundBitmap,foregroundPoint,255);
- }
- while(hittest == true);
-
- }
- playerBitmap.dispose();
- if(hitted0 == true || hitted1 == true)
- {
- this.manager.playFX("snd_ground");
- this.setJumperRotation(!hitted0 ? -1 : 1);
- }
- }
- function setJumperRotation(dir)
- {
- if(this.jumper_enabledEvents == false)
- {
- return undefined;
- }
- this.jumper_enabledEvents = false;
- this.rotateByHitValue = dir * this.rotateByHitMax;
- this.moveByHitValue = dir * int(2 * this.moveByHitMax * this._speedRate);
- this.moveByHitStepValue = dir * this.moveByHitStep;
- this.rotateHitStepValue = dir * this.rotateByHitStep;
- this.jumperMC.man.jet.flame._visible = false;
- this.jumperMC.man.jet.flame_shadow._visible = false;
- this.setJumper = dir != 1 ? this.setJumperAfterHitDown : this.setJumperAfterHitUp;
- }
- function setJumperAfterHitUp()
- {
- var rot = this.jumperMC.man._rotation;
- this.jumperMC._y += this.moveByHitValue;
- if(this.moveByHitValue < this.moveByHitStep)
- {
- this.moveByHitValue = 0;
- }
- else
- {
- this.moveByHitValue -= this.moveByHitStepValue;
- }
- if(Math.abs(this.rotateByHitValue) <= this.rotatMin)
- {
- rot = this.jumperMC.man._rotation += this.rotatMin;
- if((rot > 180 - this.rotatMin || rot < this.rotatMin - 180) && this.moveByHitValue == 0)
- {
- this.backJumperToAction();
- }
- }
- else
- {
- this.jumperMC.man._rotation += this.rotateByHitValue;
- this.rotateByHitValue -= this.rotateHitStepValue;
- }
- this.getPlayerBounds();
- }
- function setJumperAfterHitDown()
- {
- var rot = this.jumperMC.man._rotation;
- this.jumperMC._y += this.moveByHitValue;
- if(this.moveByHitValue < this.moveByHitStep)
- {
- this.moveByHitValue = 0;
- }
- else
- {
- this.moveByHitValue -= this.moveByHitStepValue;
- }
- if(Math.abs(this.rotateByHitValue) <= this.rotatMin)
- {
- rot = this.jumperMC.man._rotation -= this.rotatMin;
- if((rot > 180 - this.rotatMin || rot < this.rotatMin - 180) && this.moveByHitValue == 0)
- {
- this.backJumperToAction();
- }
- }
- else
- {
- this.jumperMC.man._rotation += this.rotateByHitValue;
- this.rotateByHitValue -= this.rotateHitStepValue;
- }
- this.getPlayerBounds();
- }
- function setJumperOnMove()
- {
- var d_rot = (- this.rotatMin) * this.moveByY * this._speedRate;
- this.jumperMC._y += this.moveByY * this._speedRate;
- this.jumperMC._x += this.moveByX;
- this.jumperMC.man._rotation = 180 + d_rot;
- this.jumperMC.man.leg1._rotation = this._speedValue + d_rot;
- this.jumperMC.man.leg2._rotation = this._speedValue + d_rot;
- this.jumperMC.man.korpus._rotation = (- this._speedValue) / 2;
- this.jumperMC.man.korpus.reka1._rotation = this._speedValue;
- this.jumperMC.man.korpus.glowa._rotation = (- this._speedValue) / 4;
- this.jumperMC.man.jet.gotoAndStop(this.jumper_jetEndFrame - int(this.jumper_jetFrames * this._speedRate));
- this.jumperMC.man.jet._rotation = 90 - d_rot;
- this.getPlayerBounds();
- }
- function getPlayerBounds()
- {
- this._playerOutBounds = this.jumperMC.getBounds(this.jumperMC._parent);
- this._playerInBounds = this.jumperMC.getBounds();
- }
- function useBonus()
- {
- if(this._bonusInUse == true || this._bonusValue == 0 || this.jumper_enabledEvents == false || this._isPaused == true)
- {
- return undefined;
- }
- this.manager.playFX("snd_bonus_atom");
- this._bonusInUse = true;
- this._bonusValue = int(this._bonusValue / 2);
- this.bonus.setValue(this._bonusValue);
- this.addFuelValue(1);
- var a = new flash.geom.ColorTransform(1,1,1,1,255,255,255,0);
- var b = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
- var c = new flash.geom.ColorTransform(1,1,1,0,0,0,0,0);
- this.fader.fadeIt(this.gameMC,a,0,null);
- this.fader.fadeIt(this.gameMC,b,50,null);
- this.fader.fadeIt(this.objectsscene.getSceneMC(),c,30,system.Delegate.create(this,this.onBonusUseEnd));
- }
- function onBonusUseEnd()
- {
- this.objectsscene.removeObjects();
- var b = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
- this.fader.fadeIt(this.objectsscene.getSceneMC(),b,0,null);
- this._bonusInUse = false;
- }
- function useKeys(val)
- {
- if(this._isPaused == true)
- {
- return undefined;
- }
- if(val._y != undefined)
- {
- this.moveByY = val._y * this.multipleY;
- }
- }
- function pauseGame(val)
- {
- this._isPaused = val;
- if(val == true)
- {
- this.prevspeed = this._speedValue;
- this._speedValue = 0;
- }
- else
- {
- this._speedValue = this.prevspeed;
- }
- }
- function onNewSceneElement(upper, px, py)
- {
- this.itemsArray.sortOn("nextpoint",Array.NUMERIC);
- if(this.itemsArray[0].nextpoint > this._distance || this._distance - this._lastitemplace < this.minItemDistance)
- {
- return undefined;
- }
- var itemobj = this.itemsArray[0];
- var r = itemobj.classname;
- var s = itemobj.space * Math.random();
- this._lastitemplace = this._distance;
- itemobj.nextpoint += itemobj.dist;
- if(upper == true)
- {
- py += s;
- }
- else
- {
- py -= s;
- }
- this.objectsscene.addObject(r,r,itemobj.upper && upper,px,py,1,0);
- }
- function accelate()
- {
- if(this._isPaused == true)
- {
- return undefined;
- }
- this._speedValue *= this.resistance;
- this._speedRate = this._speedValue / this.speedMax;
- this._lastdistance = this._distance;
- this._distance = Math.round(this._distance + this._speedValue);
- if(this._speedValue < this.speedMin)
- {
- this.endGame();
- }
- }
- function setFuel()
- {
- var tMC = this.fuelMC.energyline.bar;
- tMC._y = (- tMC._height) * this._speedRate;
- }
- function setScore()
- {
- this._scoreValue = int(this._scoreValue + this._speedValue / 10);
- this.score.setValue(this._scoreValue);
- }
- function moveScene()
- {
- this.foregroundscene.moveScene(this._speedValue);
- this.backgroundscene.moveScene(this._speedValue);
- }
- function moveObjects()
- {
- this.objectsscene.moveObjects(this._speedValue,getTimer());
- }
- function do_oEF()
- {
- this.setJumper();
- this.moveScene();
- this.moveObjects();
- this.checkForegroundCollision();
- this.checkObjectsCollision();
- this.setFuel();
- this.setScore();
- this.accelate();
- }
- function makeScene(_MC)
- {
- this.backgroundscene = new games.MovingScene(_MC,0,550,400);
- this.foregroundscene = new games.MovingScene(_MC,1000,550,400);
- this.objectsscene = new games.MovingObjects(_MC,110,550,400);
- this.foregroundscene.addBackground(0,1,0,true,50,230,20,150,"wall0","wall0_slope");
- this.foregroundscene.addBackground(1,1,400,false,50,220,20,150,"wall0","wall0_slope");
- this.backgroundscene.addBackground(2,0.75,0,true,50,150,120,200,"wall1","wall1_slope","wall2","wall2_slope");
- this.backgroundscene.addBackground(3,0.75,400,false,50,150,120,200,"wall1","wall1_slope","wall2","wall2_slope");
- this.foregroundscene.broadcastBackground(0);
- this.foregroundscene.broadcastBackground(1);
- this.foregroundscene.addListener(this);
- var tMC = this.objectsscene.addObject("startscene",undefined,false,this.gameArea._width,this.gameArea._height / 2,1,0);
- tMC.startAction = system.Delegate.create(this,this.startGame);
- }
- function startGame()
- {
- this.manager.playMusic("loop_ambient");
- this.setJumper = this.setJumperOnMove;
- this.onBonusUse = this.useBonus;
- this.onKeysMove = this.useKeys;
- this._speedValue = this.startSpeed;
- this._bonusValue = 1;
- this.bonus.resetTo("1");
- this.jumperMC.man.jet.flame._visible = true;
- this.jumperMC.man.jet.flame_shadow._visible = true;
- this.timer.addListener(this.gameMC,0,system.Delegate.create(this,this.do_oEF),0);
- }
- function endGame(txt)
- {
- this.manager.stopMusic("loop_ambient");
- this.manager.playFX("snd_gameover");
- this._bonusValue = 0;
- var gameoverinfo = txt != undefined ? txt : "game over!";
- var gameoverscore = this.score.getValue();
- var fn1 = this.manager.call_gameOver;
- var fn0 = system.Delegate.create(this.manager,fn1,gameoverscore,gameoverinfo);
- this.jumperMC.gotoAndPlay("helpless");
- this.timer.addListener(this.gameMC,this.time_endLevelPause,fn0,1);
- }
- }
-