home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Puzzle
/
Easter_Eggs.swf
/
scripts
/
__Packages
/
com
/
novelgames
/
flashgames
/
eggsAS2
/
Game.as
< prev
next >
Wrap
Text File
|
2008-09-04
|
21KB
|
641 lines
class com.novelgames.flashgames.eggsAS2.Game extends com.novelgames.flashgames.commonAS2.CommonGame
{
static var DOWN = 1;
static var LEFTDOWN = 2;
static var RIGHTDOWN = 3;
function Game()
{
super();
this.gameOverDialog.__proto__ = com.novelgames.flashgames.eggsAS2.GameOverDialog.prototype;
this.lifePie.__proto__ = com.novelgames.flashgames.eggsAS2.LifePie.prototype;
this.scoreText.__proto__ = com.novelgames.flashgames.commonAS2.NewTextField.prototype;
this.levelText.__proto__ = com.novelgames.flashgames.commonAS2.NewTextField.prototype;
this.eggsHolder.__proto__ = com.novelgames.flashgames.commonAS2.NewMovieClip.prototype;
var _loc4_ = undefined;
var _loc3_ = undefined;
var _loc5_ = undefined;
this.eggs = new Array();
this.depth = 0;
this.occupiers = new Array();
this.chosenEgg = null;
this.isSwapping = false;
this.swappingEgg1 = null;
this.swappingEgg2 = null;
this.isUnswapping = false;
this.unswappingEgg1 = null;
this.unswappingEgg2 = null;
this.isDestroying = false;
this.destroyingEggs = new Array();
this.isDropping = false;
this.droppingEggs = new Array();
this.__set__level(1);
this.life = com.novelgames.flashgames.eggsAS2.Config.LIFE_INITIAL;
this.__set__score(0);
this.combo = 0;
this.decreaseRate = com.novelgames.flashgames.eggsAS2.Config.LEVEL_DECREASERATES[0];
this.decreaseCount = 0;
this.gameStarted = true;
_loc4_ = 0;
while(_loc4_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_X)
{
this.occupiers[_loc4_] = new Array(com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y);
_loc3_ = 0;
while(_loc3_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y)
{
this.occupiers[_loc4_][_loc3_] = null;
_loc3_ = _loc3_ + 1;
}
_loc4_ = _loc4_ + 1;
}
_loc4_ = 0;
while(_loc4_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y)
{
_loc3_ = 0;
while(_loc3_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_X)
{
_loc5_ = this.eggsHolder.createMovie("Egg");
this.eggs[this.depth] = _loc5_;
this.eggs[this.depth].initialize(this.getRealX(_loc3_,_loc4_),this.getRealY(_loc3_,_loc4_),Math.floor(Math.random() * com.novelgames.flashgames.eggsAS2.Config.EGG_TYPES));
this.eggsHolder.addChild(this.eggs[this.depth]);
this.setEggXY(this.eggs[this.depth],_loc3_,_loc4_);
this.depth = this.depth + 1;
_loc3_ = _loc3_ + 1;
}
_loc4_ = _loc4_ + 1;
}
this.soundChoose = this.createSound("SoundChoose");
this.soundSwap = this.createSound("SoundSwap");
this.soundGroup = this.createSound("SoundGroup");
this.soundGameOver = this.createSound("SoundGameOver");
this.lastDecreaseTime = com.novelgames.flashgames.commonAS2.NewTimer.getTimer();
this.timer = new com.novelgames.flashgames.commonAS2.NewTimer(1,0);
this.timer.addEventListener(com.novelgames.flashgames.commonAS2.TimerEvent.TIMER,this,"onTime");
this.timer.start();
}
function set score(score)
{
this.__score = score;
this.scoreText.text = score.toString();
}
function get score()
{
return this.__score;
}
function set level(level)
{
this.__level = level;
this.levelText.text = level.toString();
}
function get level()
{
return this.__level;
}
function getRealX(x, y)
{
return x * com.novelgames.flashgames.eggsAS2.Config.EGG_WIDTH;
}
function getRealY(x, y)
{
if(x % 2 == 0)
{
return y * com.novelgames.flashgames.eggsAS2.Config.EGG_HEIGHT;
}
return y * com.novelgames.flashgames.eggsAS2.Config.EGG_HEIGHT + com.novelgames.flashgames.eggsAS2.Config.EGG_HEIGHT / 2;
}
function chooseEgg(egg)
{
if(!this.gameStarted)
{
return undefined;
}
if(this.isSwapping || this.isUnswapping || this.isDestroying || this.isDropping)
{
return undefined;
}
if(!this.chosenEgg)
{
this.chosenEgg = egg;
egg.showChosen();
this.soundChoose.play();
}
else if(this.eggsAreAdjacent(egg,this.chosenEgg))
{
this.swapEggs(egg,this.chosenEgg);
this.chosenEgg.showNormal();
this.chosenEgg = null;
this.soundSwap.play();
}
else
{
this.chosenEgg.showNormal();
this.chosenEgg = null;
this.soundChoose.play();
}
}
function finishSwapping()
{
var _loc2_ = undefined;
if(this.swappingEgg1.isSwapping || this.swappingEgg2.isSwapping)
{
return undefined;
}
this.isSwapping = false;
this.setEggXY(this.swappingEgg1,this.swappingEgg1.targetX,this.swappingEgg1.targetY);
this.setEggXY(this.swappingEgg2,this.swappingEgg2.targetX,this.swappingEgg2.targetY);
_loc2_ = this.getGroups();
if(_loc2_.length == 0)
{
this.combo = 0;
this.unswapEggs(this.swappingEgg1,this.swappingEgg2);
this.soundSwap.play();
}
else
{
this.combo = this.combo + 1;
this.addScore(this.getScore(_loc2_));
this.addLife(_loc2_.length);
this.destroyEggs(_loc2_);
this.soundGroup.play();
}
}
function finishUnswapping()
{
if(this.unswappingEgg1.isUnswapping || this.unswappingEgg2.isUnswapping)
{
return undefined;
}
this.isUnswapping = false;
this.setEggXY(this.unswappingEgg1,this.unswappingEgg1.targetX,this.unswappingEgg1.targetY);
this.setEggXY(this.unswappingEgg2,this.unswappingEgg2.targetX,this.unswappingEgg2.targetY);
}
function finishDestroying()
{
var _loc2_ = undefined;
_loc2_ = 0;
while(_loc2_ < this.destroyingEggs.length)
{
if(this.destroyingEggs[_loc2_].visible)
{
return undefined;
}
_loc2_ = _loc2_ + 1;
}
_loc2_ = 0;
while(_loc2_ < this.destroyingEggs.length)
{
this.destroyEgg(this.destroyingEggs[_loc2_]);
_loc2_ = _loc2_ + 1;
}
this.isDestroying = false;
this.dropEggs();
}
function finishDropping()
{
var _loc2_ = undefined;
var _loc3_ = undefined;
_loc2_ = 0;
while(_loc2_ < this.droppingEggs.length)
{
if(this.droppingEggs[_loc2_].isDropping)
{
return undefined;
}
_loc2_ = _loc2_ + 1;
}
_loc2_ = 0;
while(_loc2_ < this.droppingEggs.length)
{
this.setEggXY(this.droppingEggs[_loc2_],this.droppingEggs[_loc2_].targetX,this.droppingEggs[_loc2_].targetY);
_loc2_ = _loc2_ + 1;
}
this.isDropping = false;
_loc3_ = this.getGroups();
if(_loc3_.length == 0)
{
this.combo = 0;
}
else
{
this.combo = this.combo + 1;
this.addScore(this.getScore(_loc3_));
this.addLife(_loc3_.length);
this.destroyEggs(_loc3_);
this.soundGroup.play();
}
}
function onTime(timerEvent)
{
var _loc2_ = undefined;
timerEvent.updateAfterEvent();
_loc2_ = 0;
while(_loc2_ < this.eggs.length)
{
if(this.eggs[_loc2_])
{
if(this.eggs[_loc2_].parent)
{
this.eggs[_loc2_].onTime();
}
}
_loc2_ = _loc2_ + 1;
}
this.updateLife();
}
function setEggXY(egg, x, y)
{
egg.indexX = x;
egg.indexY = y;
this.occupiers[x][y] = egg;
}
function eggsAreAdjacent(egg1, egg2)
{
if(egg1.indexX == egg2.indexX)
{
return egg1.indexY == egg2.indexY + 1 || egg1.indexY == egg2.indexY - 1;
}
if(egg1.indexX == egg2.indexX - 1)
{
if(egg1.indexX % 2 == 0)
{
return egg1.indexY == egg2.indexY || egg1.indexY == egg2.indexY + 1;
}
return egg1.indexY == egg2.indexY || egg1.indexY == egg2.indexY - 1;
}
if(egg1.indexX == egg2.indexX + 1)
{
if(egg2.indexX % 2 == 0)
{
return egg1.indexY == egg2.indexY || egg1.indexY == egg2.indexY - 1;
}
return egg1.indexY == egg2.indexY || egg1.indexY == egg2.indexY + 1;
}
return false;
}
function swapEggs(egg1, egg2)
{
this.isSwapping = true;
this.swappingEgg1 = egg1;
this.swappingEgg2 = egg2;
egg1.swapTo(egg2.indexX,egg2.indexY);
egg2.swapTo(egg1.indexX,egg1.indexY);
}
function unswapEggs(egg1, egg2)
{
this.isUnswapping = true;
this.unswappingEgg1 = egg1;
this.unswappingEgg2 = egg2;
egg1.unswapTo(egg2.indexX,egg2.indexY);
egg2.unswapTo(egg1.indexX,egg1.indexY);
}
function destroyEggs(groups)
{
var _loc3_ = undefined;
var _loc2_ = undefined;
this.isDestroying = true;
this.destroyingEggs = new Array();
_loc3_ = 0;
while(_loc3_ < groups.length)
{
_loc2_ = 0;
while(_loc2_ < groups[_loc3_].length)
{
this.destroyingEggs.push(groups[_loc3_][_loc2_]);
groups[_loc3_][_loc2_].destroy();
_loc2_ = _loc2_ + 1;
}
_loc3_ = _loc3_ + 1;
}
}
function destroyEgg(egg)
{
this.occupiers[egg.indexX][egg.indexY] = null;
if(egg.__get__parent())
{
this.eggsHolder.removeChild(egg);
}
}
function dropEggs()
{
var _loc4_ = undefined;
var _loc2_ = undefined;
var _loc3_ = undefined;
var _loc5_ = undefined;
var _loc6_ = undefined;
this.isDropping = true;
this.droppingEggs = new Array();
_loc4_ = 0;
while(_loc4_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_X)
{
_loc3_ = 0;
_loc2_ = com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y - 1;
while(_loc2_ >= 0)
{
_loc5_ = this.occupiers[_loc4_][_loc2_];
if(!_loc5_)
{
_loc3_ = _loc3_ + 1;
}
else if(_loc3_ > 0)
{
_loc5_.drop(_loc5_.indexY + _loc3_);
this.droppingEggs.push(_loc5_);
}
_loc2_ = _loc2_ - 1;
}
_loc2_ = 0;
while(_loc2_ < _loc3_)
{
_loc6_ = this.eggsHolder.createMovie("Egg");
this.eggs[this.depth] = _loc6_;
this.eggs[this.depth].indexX = _loc4_;
this.eggs[this.depth].indexY = - _loc2_ - 1;
this.eggs[this.depth].initialize(this.getRealX(_loc4_,- _loc2_ - 1),this.getRealY(_loc4_,- _loc2_ - 1),Math.floor(Math.random() * com.novelgames.flashgames.eggsAS2.Config.EGG_TYPES));
this.eggsHolder.addChild(this.eggs[this.depth]);
this.eggs[this.depth].drop(_loc3_ - 1 - _loc2_);
this.droppingEggs.push(this.eggs[this.depth]);
this.depth = this.depth + 1;
_loc2_ = _loc2_ + 1;
}
_loc4_ = _loc4_ + 1;
}
}
function getGroups()
{
var _loc6_ = new Array();
var _loc4_ = undefined;
var _loc3_ = undefined;
var _loc2_ = undefined;
var _loc5_ = undefined;
_loc5_ = 0;
while(_loc5_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_X)
{
_loc4_ = this.occupiers[_loc5_][0];
_loc3_ = _loc4_;
_loc2_ = new Array();
_loc2_.push(_loc3_);
while(_loc3_ = this.getNextEgg(_loc3_,com.novelgames.flashgames.eggsAS2.Game.DOWN))
{
if(_loc3_.type == _loc4_.type)
{
_loc2_.push(_loc3_);
}
else
{
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc4_ = _loc3_;
_loc2_ = new Array();
_loc2_.push(_loc4_);
}
}
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc5_ = _loc5_ + 1;
}
_loc5_ = 0;
while(_loc5_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_X)
{
_loc4_ = this.occupiers[_loc5_][0];
_loc3_ = _loc4_;
_loc2_ = new Array();
_loc2_.push(_loc3_);
while(_loc3_ = this.getNextEgg(_loc3_,com.novelgames.flashgames.eggsAS2.Game.RIGHTDOWN))
{
if(_loc3_.type == _loc4_.type)
{
_loc2_.push(_loc3_);
}
else
{
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc4_ = _loc3_;
_loc2_ = new Array();
_loc2_.push(_loc4_);
}
}
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc5_ += 2;
}
_loc5_ = 0;
while(_loc5_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y)
{
_loc4_ = this.occupiers[0][_loc5_];
_loc3_ = _loc4_;
_loc2_ = new Array();
_loc2_.push(_loc3_);
while(_loc3_ = this.getNextEgg(_loc3_,com.novelgames.flashgames.eggsAS2.Game.RIGHTDOWN))
{
if(_loc3_.type == _loc4_.type)
{
_loc2_.push(_loc3_);
}
else
{
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc4_ = _loc3_;
_loc2_ = new Array();
_loc2_.push(_loc4_);
}
}
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc5_ = _loc5_ + 1;
}
_loc5_ = 0;
while(_loc5_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_X)
{
_loc4_ = this.occupiers[_loc5_][0];
_loc3_ = _loc4_;
_loc2_ = new Array();
_loc2_.push(_loc3_);
while(_loc3_ = this.getNextEgg(_loc3_,com.novelgames.flashgames.eggsAS2.Game.LEFTDOWN))
{
if(_loc3_.type == _loc4_.type)
{
_loc2_.push(_loc3_);
}
else
{
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc4_ = _loc3_;
_loc2_ = new Array();
_loc2_.push(_loc4_);
}
}
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc5_ += 2;
}
_loc5_ = 0;
while(_loc5_ < com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y)
{
_loc4_ = this.occupiers[com.novelgames.flashgames.eggsAS2.Config.DIMENSION_X - 1][_loc5_];
_loc3_ = _loc4_;
_loc2_ = new Array();
_loc2_.push(_loc3_);
while(_loc3_ = this.getNextEgg(_loc3_,com.novelgames.flashgames.eggsAS2.Game.LEFTDOWN))
{
if(_loc3_.type == _loc4_.type)
{
_loc2_.push(_loc3_);
}
else
{
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc4_ = _loc3_;
_loc2_ = new Array();
_loc2_.push(_loc4_);
}
}
if(_loc2_.length >= com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE)
{
_loc6_.push(_loc2_);
}
_loc5_ = _loc5_ + 1;
}
return _loc6_;
}
function getNextEgg(egg, direction)
{
if(direction == com.novelgames.flashgames.eggsAS2.Game.DOWN)
{
if(egg.indexY == com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y - 1)
{
return null;
}
return this.occupiers[egg.indexX][egg.indexY + 1];
}
if(direction == com.novelgames.flashgames.eggsAS2.Game.LEFTDOWN)
{
if(egg.indexX == 0)
{
return null;
}
if(egg.indexX % 2 == 0)
{
return this.occupiers[egg.indexX - 1][egg.indexY];
}
if(egg.indexY == com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y - 1)
{
return null;
}
return this.occupiers[egg.indexX - 1][egg.indexY + 1];
}
if(egg.indexX == com.novelgames.flashgames.eggsAS2.Config.DIMENSION_X - 1)
{
return null;
}
if(egg.indexX % 2 == 0)
{
return this.occupiers[egg.indexX + 1][egg.indexY];
}
if(egg.indexY == com.novelgames.flashgames.eggsAS2.Config.DIMENSION_Y - 1)
{
return null;
}
return this.occupiers[egg.indexX + 1][egg.indexY + 1];
}
function getScore(groups)
{
var _loc2_ = undefined;
var _loc4_ = 0;
_loc2_ = 0;
while(_loc2_ < groups.length)
{
_loc4_ += this.combo * ((groups[_loc2_].length - com.novelgames.flashgames.eggsAS2.Config.GROUPSIZE) * com.novelgames.flashgames.eggsAS2.Config.SCORE_EXTRAEGG + com.novelgames.flashgames.eggsAS2.Config.SCORE_GROUP);
_loc2_ = _loc2_ + 1;
}
return _loc4_;
}
function addScore(amount)
{
this.score += amount;
this.updateLevel();
}
function updateLevel()
{
var _loc2_ = undefined;
_loc2_ = this.__get__level() - 1;
while(_loc2_ < com.novelgames.flashgames.eggsAS2.Config.LEVEL_SCORES.length)
{
if(this.__get__score() < com.novelgames.flashgames.eggsAS2.Config.LEVEL_SCORES[_loc2_])
{
break;
}
_loc2_ = _loc2_ + 1;
}
if(this.__get__level() != _loc2_ + 1)
{
this.__set__level(_loc2_ + 1);
this.decreaseRate = com.novelgames.flashgames.eggsAS2.Config.LEVEL_DECREASERATES[_loc2_];
}
}
function updateLife()
{
if(!this.gameStarted)
{
return undefined;
}
if(this.lastDecreaseTime + this.decreaseRate <= com.novelgames.flashgames.commonAS2.NewTimer.getTimer())
{
this.lastDecreaseTime += this.decreaseRate;
this.addLife(-1);
}
}
function addLife(amount)
{
this.life += amount;
if(this.life < 0)
{
this.life = 0;
}
else if(this.life > com.novelgames.flashgames.eggsAS2.Config.LIFE_FULL)
{
this.life = com.novelgames.flashgames.eggsAS2.Config.LIFE_FULL;
}
this.lifePie.setLife(this.life);
if(this.life <= 0)
{
this.gameOver();
this.soundGameOver.play();
}
}
function gameOver()
{
var _loc2_ = undefined;
this.gameStarted = false;
this.gameOverDialog.show();
_loc2_ = new com.novelgames.flashgames.commonAS2.NewTimer(com.novelgames.flashgames.eggsAS2.Config.MESSAGE_GAMEOVERTIME,1);
_loc2_.addEventListener(com.novelgames.flashgames.commonAS2.TimerEvent.TIMER,this,"showPlayAgain");
_loc2_.start();
}
function showPlayAgain(timerEvent)
{
Object(this.__get__parent()).showEnterHighScore(this.__get__score());
this.gameOverDialog.showPlayAgain();
}
}