/BossLevel.hx
http://boxyboxumber.googlecode.com/ · Haxe · 675 lines · 579 code · 60 blank · 36 comment · 124 complexity · f8ae6097f061cc027eeaed17ad26a93a MD5 · raw file
- import flash.display.Sprite;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.events.Event;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- import flash.geom.Matrix;
- import flash.utils.Timer;
- import haxe.FastList;
- import haxe.Timer;
- import Images;
- import TileModel;
- import HealthBarView;
- import BaseLevel;
- import Kongregate;
- class BossLevel extends BaseLevel
- {
- private var whiteMask:Sprite;
- private var won:Int;
- private var mult:Int;
- private var _pinkMap:Array<Array<Int>>;
- private static inline var MAX_TILE_SIZE:Int = 64;
- private static inline var MAP_COLUMNS:Int = 10;
- private static inline var MAP_ROWS:Int = 8;
-
- //tile ID s in tile sheet
- private static inline var BOX:Int = 00;
- private static inline var PLATFORM:Int = 11;
- private static inline var BOSS:Int = 12;
- private static inline var SKY_:Int = 10;
- private static inline var PLAT:Int = 11;
- private static inline var MACHINE_GUN:Int = 01;
- private static inline var PISTOL:Int = 02;
- private static inline var SHOTGUN:Int = 03;
- private static inline var PINK:Int = 21;
- private static inline var BLUE:Int = 20;
- private static inline var FAIRY:Int = 30;
- private static inline var PINK_FAIRY:Int = 22;
- private static inline var FLOWER:Int = 31;
- private static inline var HEART:Int = 32;
- private static inline var KITTY:Int = 33;
- private static inline var PinkRadius:Float = 20.5;
- private static inline var BlueRadius:Float = 20.5;
-
- public function new(stage:Dynamic){
- super(stage);
- MAP_COLUMNS = 70;
- removeChild(_staticBackgroundBitmap);
- removeChild(_backgroundBitmap);
- removeChild(_foregroundBitmap);
- removeChild(shotVectorView);
- won = 0;
- mult = 1;
- _staticBackgroundBitmapData = new CardboardBackground();
- _staticBackgroundBitmap = new Bitmap(_staticBackgroundBitmapData);
- _backgroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
- MAP_ROWS * MAX_TILE_SIZE, true, 0);
- _backgroundBitmap = new Bitmap(_backgroundBitmapData);
- _foregroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
- MAP_ROWS * MAX_TILE_SIZE, true, 0);
- _foregroundBitmap = new Bitmap(_foregroundBitmapData);
- _camera = new Rectangle (0, 0, stage.stageWidth, stage.stageHeight);
- addChild(_staticBackgroundBitmap);
- addChild(_backgroundBitmap);
- addChild(_foregroundBitmap);
-
- whiteMask = new Sprite();
- whiteMask.graphics.beginFill(0xFFFFFF);
- whiteMask.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
- whiteMask.graphics.endFill();
- whiteMask.alpha = 0.5;
- shotVector = new VectorModel();
- shotVectorView = new VectorView(shotVector,_camera, 1);
- addChild(shotVectorView);
- _platformMap =
- [
- // Level 1 Level 2 Level 3 Level 4 Level 5 Level 6 Level 7
- // 0 , 1 , 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
- [SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_],
- [SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,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1],
- ] ;
- maxEnemiesOnScreen = 10;
-
- // myTimer = new Timer(12);
- // myTimer.addEventListener("timer", OnEnter);
- // myTimer.start();
- //Add the game bitmaps
-
- }
- public override function Load(inVolume:Bool,inSound:Bool,inKongVar:CKongregate,inDifficulty:Int)
- {
- super.Load(inVolume,inSound,inKongVar,inDifficulty);
- //Run the buildMap method to convert the
- //map array data into a visual display
- won = 0;
- buildMap(_platformMap);
- buildMap(_gameObjectMap);
- if(_bossModel != null)
- {
- addChild(_bossHealth);
- }
- minX = stage.stageWidth*0;
- maxX = stage.stageWidth*1;
- _bossModel.setX = stage.stageWidth-64;
- if(Difficulty >= 3)
- {
- mult = 2;
- }
- //buildReserveEnemies();
- }
- public override function checkWin()
- {
- if(won > 50)
- {removeChild(whiteMask);}
- return (won > 50);
- }
- public override function buildReserveEnemies()
- {
- }
- override function OnEnter(e:flash.events.Event)
- {
- try
- {
- if(won > 0)
- {
- won++;
- if(won%2 == 0)
- {
- super.OnEnter(e);
- }
- return;
- }
- super.OnEnter(e);
- var enemyModelCount = 0;
- //_bossModel.hit();
- for(enemyModel in _enemies)
- {
- enemyModelCount++;
- }
- if(_bossModel.health > 90 * mult)
- {
- if(enemyModelCount == 0)
- {
- //addEnemyReserve(PINK,"Pink",6,9);
- addEnemyReserve(PINK,"Pink",6,8);
- addEnemyReserve(PINK,"Pink",6,7);
- addEnemyReserve(PINK,"Pink",6,6);
-
- addEnemyReserve(PINK,"Pink",6,4);
- addEnemyReserve(PINK,"Pink",6,3);
- addEnemyReserve(PINK,"Pink",6,2);
- }
- else if(enemyModelCount < 6)
- {
- addEnemyReserve(PINK,"Pink",6,8);
- }
-
-
- }
- else if(_bossModel.health > 75 * mult)
- {
- if(_bossModel.xPos < 640)
- {
- _bossModel.CanHit = false;
- clearEnemies();
- _bossModel.vx = 5;
- }
- else
- {
- maxX = stage.stageWidth*2;
- if(_boxModel.xPos >= stage.stageWidth)
- {minX = stage.stageWidth;}
- _bossModel.CanHit = true;
- _bossModel.setX = 1216;
- if(minX >= stage.stageWidth)
- {
- if(enemyModelCount == 0)
- {
- //addEnemyReserve(PINK,"Pink",6,9);
- addEnemyReserve(BLUE,"Blue",6,16);
- addEnemyReserve(BLUE,"Blue",6,15);
- addEnemyReserve(BLUE,"Blue",6,14);
-
- }
- else if(enemyModelCount < 3)
- {
- addEnemyReserve(BLUE,"Blue`",6,16);
- }
- }
- }
- }
- else if(_bossModel.health > 60 * mult)
- {
- if(_bossModel.xPos < stage.stageWidth*2)
- {
- _bossModel.CanHit = false;
- clearEnemies();
- _bossModel.vx = 5;
- }
- else
- {
- maxX = stage.stageWidth*3;
- if(_boxModel.xPos >= stage.stageWidth*2)
- {minX = stage.stageWidth*2;}
- _bossModel.CanHit = true;
- _bossModel.setX = stage.stageWidth*3-64;
- if(minX >= stage.stageWidth*2)
- {
- if(enemyModelCount == 0)
- {
- //addEnemyReserve(PINK,"Pink",6,9);
- // addEnemyReserve(FAIRY,"Fairy",6,26);
- addEnemyReserve(FAIRY,"Fairy",6,25);
- addEnemyReserve(FAIRY,"Fairy",6,24);
- addEnemyReserve(FAIRY,"Fairy",6,23);
- // addEnemyReserve(FAIRY,"Fairy",6,22);
- // addEnemyReserve(FAIRY,"Fairy",6,21);
- // addEnemyReserve(FAIRY,"Fairy",5,26);
- addEnemyReserve(FAIRY,"Fairy",5,25);
- addEnemyReserve(FAIRY,"Fairy",5,24);
- addEnemyReserve(FAIRY,"Fairy",5,23);
- // addEnemyReserve(FAIRY,"Fairy",5,22);
- // addEnemyReserve(FAIRY,"Fairy",5,21);
- addEnemyReserve(FAIRY,"Fairy",2,20);
- addEnemyReserve(FAIRY,"Fairy",2,21);
- addEnemyReserve(FAIRY,"Fairy",2,22);
- addEnemyReserve(FAIRY,"Fairy",1,20);
- addEnemyReserve(FAIRY,"Fairy",1,21);
- addEnemyReserve(FAIRY,"Fairy",1,22);
- addEnemyReserve(FAIRY,"Fairy",2,29);
- addEnemyReserve(FAIRY,"Fairy",2,28);
- addEnemyReserve(FAIRY,"Fairy",2,27);
- addEnemyReserve(FAIRY,"Fairy",1,29);
- addEnemyReserve(FAIRY,"Fairy",1,28);
- addEnemyReserve(FAIRY,"Fairy",1,27);
-
- }
- else if(enemyModelCount < 18)
- {
- addEnemyReserve(FAIRY,"Fairy",6,25);
- }
- }
- }
- }
- else if(_bossModel.health > 45 * mult)
- {
- if(_bossModel.xPos < stage.stageWidth*3)
- {
- _bossModel.CanHit = false;
- clearEnemies();
- _bossModel.vx = 5;
- }
- else if(_bossModel.xPos >= stage.stageWidth*3 && _bossModel.xPos < stage.stageWidth*3+4*MAX_TILE_SIZE )
- {
- _bossModel.setX = stage.stageWidth*3+4*MAX_TILE_SIZE+5;
- _bossModel.setY = 3*MAX_TILE_SIZE;
- _bossModel.vx = 0;
- }
- else
- {
- maxX = stage.stageWidth*4;
- if(_boxModel.xPos >= stage.stageWidth*3)
- {minX = stage.stageWidth*3;}
- _bossModel.CanHit = true;
- if(minX >= stage.stageWidth*3)
- {
- if(enemyModelCount == 0)
- {
- //addEnemyReserve(PINK,"Pink",6,9);
- // addEnemyReserve(FAIRY,"Fairy",6,26);
- addEnemyReserve(PINK_FAIRY,"PinkFairy",6,39);
- addEnemyReserve(PINK_FAIRY,"PinkFairy",6,38);
- addEnemyReserve(PINK_FAIRY,"PinkFairy",6,37);
-
- }
- else if(enemyModelCount < 3)
- {
- addEnemyReserve(PINK_FAIRY,"PinkFairy",6,39);
- }
- }
- }
- }
- else if(_bossModel.health > 30 * mult)
- {
- if(_bossModel.xPos < stage.stageWidth*4)
- {
- _bossModel.CanHit = false;
- clearEnemies();
- _bossModel.vx = 5;
- }
- else if(_bossModel.xPos >= stage.stageWidth*4 && _bossModel.xPos < stage.stageWidth*5-64 )
- {
- _bossModel.setX = stage.stageWidth*5-64;
- _bossModel.setY = 5*MAX_TILE_SIZE;
- _bossModel.vx = 0;
- }
- else
- {
- maxX = stage.stageWidth*5;
- if(_boxModel.xPos >= stage.stageWidth*4)
- {minX = stage.stageWidth*4;}
- _bossModel.CanHit = true;
- if(minX >= stage.stageWidth*4)
- {
- if(enemyModelCount == 0)
- {
- //addEnemyReserve(PINK,"Pink",6,9);
- // addEnemyReserve(FAIRY,"Fairy",6,26);
- addEnemyReserve(FLOWER,"Flower",4,47);
- var tempModel = _enemiesReserve.pop();
- while (tempModel != null)
- {
- addChild(tempModel.HealthBar);
- tempModel.model.health = 100;
- tempModel.model.MaxHealth = 100;
- tempModel.model.Clockwise = false;
- tempModel.model.setX = tempModel.model.xPos+(MAX_TILE_SIZE-tempModel.model.width);
- tempModel.model.vy = -5;
- tempModel.model.vx = 0;
- tempModel.model.update();
- _enemies.add(tempModel);
- enemyModelCount++;
- tempModel = _enemiesReserve.pop();
- }
- addEnemyReserve(FLOWER,"Flower",4,46);
- var tempModel = _enemiesReserve.pop();
- while (tempModel != null)
- {
- addChild(tempModel.HealthBar);
- tempModel.model.health = 100;
- tempModel.model.MaxHealth = 100;
- tempModel.model.update();
- tempModel.model.Clockwise = false;
- tempModel.model.setX = tempModel.model.xPos+(MAX_TILE_SIZE-tempModel.model.width);
- tempModel.model.vy = 5;
- tempModel.model.vx = 0;
- _enemies.add(tempModel);
- enemyModelCount++;
- tempModel = _enemiesReserve.pop();
- }
- }
- else if(enemyModelCount < 2)
- {
- addEnemyReserve(PINK_FAIRY,"PinkFairy",6,39);
- }
- }
- }
- }
- else if(_bossModel.health > 15* mult)
- {
- if(_bossModel.xPos < stage.stageWidth*5)
- {
- _bossModel.CanHit = false;
- clearEnemies();
- _bossModel.vx = 5;
- }
- else if(_bossModel.xPos >= stage.stageWidth*5 && _bossModel.xPos < stage.stageWidth*5+MAX_TILE_SIZE )
- {
- _bossModel.setX = stage.stageWidth*5+6*MAX_TILE_SIZE;
- _bossModel.setY = 4*MAX_TILE_SIZE;
- _bossModel.vx = 0;
- }
- else
- {
- maxX = stage.stageWidth*6;
- if(_boxModel.xPos >= stage.stageWidth*5)
- {minX = stage.stageWidth*5;}
- _bossModel.CanHit = true;
- if(minX >= stage.stageWidth*5)
- {
- if(enemyModelCount == 0)
- {
- //addEnemyReserve(PINK,"Pink",6,9);
- // addEnemyReserve(FAIRY,"Fairy",6,26);
- addEnemyReserve(HEART,"Heart",4,57);
- addEnemyReserve(HEART,"Heart",6,57);
- addEnemyReserve(HEART,"Heart",4,56);
- addEnemyReserve(HEART,"Heart",6,56);
- }
- else if(enemyModelCount < 4)
- {
- addEnemyReserve(HEART,"Heart",6,57);
- }
- }
- }
- }
- else if(_bossModel.health > 0* mult)
- {
- if(_bossModel.xPos < stage.stageWidth*6)
- {
- _bossModel.CanHit = false;
- clearEnemies();
- _bossModel.vx = 5;
- }
- else if(_bossModel.xPos >= stage.stageWidth*6 && _bossModel.xPos < stage.stageWidth*6+MAX_TILE_SIZE )
- {
- _bossModel.setX = stage.stageWidth*7-MAX_TILE_SIZE;
- _bossModel.setY = 0*MAX_TILE_SIZE;
- _bossModel.vx = 0;
- }
- else
- {
- maxX = stage.stageWidth*7;
- if(_boxModel.xPos >= stage.stageWidth*6)
- {minX = stage.stageWidth*6;}
- _bossModel.CanHit = true;
- if(minX >= stage.stageWidth*6)
- {
- if(enemyModelCount == 0)
- {
- //addEnemyReserve(PINK,"Pink",6,9);
- // addEnemyReserve(FAIRY,"Fairy",6,26);
- addEnemyReserve(KITTY,"Kitty",0,67);
- addEnemyReserve(KITTY,"Kitty",0,66);
- addEnemyReserve(KITTY,"Kitty",0,65);
- addEnemyReserve(KITTY,"Kitty",0,64);
- }
- else if(enemyModelCount < 4)
- {
- addEnemyReserve(KITTY,"Kitty",0,67);
- }
- }
- }
- }
- else if(_bossModel.health < 0 * mult)
- {
- clearEnemies();
- addChild(whiteMask);
- if(won <= 0)
- {won = 1;}
- }
- var tempModel = _enemiesReserve.pop();
- while (tempModel != null)
- {
- addChild(tempModel.HealthBar);
- tempModel.model.health = 100;
- tempModel.model.MaxHealth = 100;
- tempModel.model.update();
- _enemies.add(tempModel);
- enemyModelCount++;
- tempModel = _enemiesReserve.pop();
- }
- }
- catch(err:flash.Error)
- {
- trace(err.message);
- }
- }
- public override function findNewDirection(gameObject:TileModel)
- {
- var newDirection:String = "";
- //A random number between 1 and 4
- if(gameObject.changeDirection == "down")
- {
- if((gameObject.centerX*MAX_TILE_SIZE) <stage.stageWidth*5+5*MAX_TILE_SIZE)
- {newDirection = "left";}
- else
- {newDirection = "right";}
- }
- else if(gameObject.changeDirection == "up")
- {
- if((gameObject.centerX*MAX_TILE_SIZE) <stage.stageWidth*5+5*MAX_TILE_SIZE)
- {newDirection = "left";}
- else
- {newDirection = "right";}
- }
- else if(gameObject.changeDirection == "left")
- {
- newDirection = "up";
- }
- else if(gameObject.changeDirection == "right")
- {
- newDirection = "up";
- }
-
- //Test the new direction and call this method recursively
- //if the direction runs the object into a wall
- switch(newDirection)
- {
- case "left":
- if(_platformMap[gameObject.mapRow][gameObject.mapColumn - 1]
- != PLATFORM)
- {
- gameObject.direction = newDirection;
- gameObject.vx = -5;
- gameObject.vy = 0;
- }
- else
- {
- //If the test hits a wall, assign this direction as
- //the object's new direction and test again.
- //(Assigning the new direction prevents the objects
- //from accidentally getting stuck in cul-de-sacs)
- gameObject.direction = newDirection;
- findRandomDirection(gameObject);
- }
-
- case "right":
- if(_platformMap[gameObject.mapRow][gameObject.mapColumn + 1]
- != PLATFORM)
- {
- gameObject.direction = newDirection;
- gameObject.vx = 5;
- gameObject.vy = 0;
- }
- else
- {
- gameObject.direction = newDirection;
- findRandomDirection(gameObject);
- }
-
- case "up":
- if(_platformMap[gameObject.mapRow - 1][gameObject.mapColumn]
- != PLATFORM)
- {
- gameObject.direction = newDirection;
- gameObject.vx = 0;
- gameObject.vy = -5;
- }
- else
- {
- gameObject.direction = newDirection;
- findRandomDirection(gameObject);
- }
-
- case "down":
- if(_platformMap[gameObject.mapRow + 1][gameObject.mapColumn]
- != PLATFORM)
- {
- gameObject.direction = newDirection;
- gameObject.vx = 0;
- gameObject.vy = 5;
- }
- else
- {
- gameObject.direction = newDirection;
- findRandomDirection(gameObject);
- }
- default:
- gameObject.direction = newDirection;
- findRandomDirection(gameObject);
- }
- }
- public function addEnemyReserve(TileNumber:Int,characterType:String,row:Int,column:Int)
- {
- var tileSheetColumn:Int = Std.int(TileNumber / 10);
- var tileSheetRow:Int = Std.int(TileNumber % 10);
- var enemyModel = new TileModel
- (
- MAX_TILE_SIZE,
- tileSheetColumn, tileSheetRow,
- row, column,
- 41, 41,false, MAX_TILE_SIZE, MAX_TILE_SIZE
- );
- if(characterType == "Pink" || characterType == "Blue")
- {
- enemyModel.gravity_Vy = 0.98;
- enemyModel.vx = -5;
- enemyModel.ImageX = 11;
- enemyModel.ImageY = 11;
- enemyModel.ImageWidth = 41;
- enemyModel.ImageHeight= 41;
- }
- else if(characterType == "Fairy")
- {
- enemyModel.vx = -5;
- enemyModel.vy = -5;
- enemyModel.ImageX = 0;
- enemyModel.ImageY = 0;
- enemyModel.ImageXOffset = 11;
- enemyModel.ImageYOffset = 11;
- enemyModel.ImageWidth = 64;
- enemyModel.ImageHeight= 64;
- }
- else if(characterType == "Flower")
- {
- enemyModel.vx = -5;
- enemyModel.vy = 0;
- enemyModel.ImageX = 0;
- enemyModel.ImageY = 0;
- enemyModel.ImageXOffset = 11;
- enemyModel.ImageYOffset = 11;
- enemyModel.ImageWidth = 64;
- enemyModel.ImageHeight= 64;
- }
- else if(characterType == "Kitty")
- {
- enemyModel.gravity_Vy = 0.98;
- enemyModel.ImageX = 0;
- enemyModel.ImageY = 0;
- enemyModel.ImageXOffset = 11;
- enemyModel.ImageYOffset = 11;
- enemyModel.ImageWidth = 64;
- enemyModel.ImageHeight= 64;
- }
- else
- {
- enemyModel.ImageX = 0;
- enemyModel.ImageY = 0;
- enemyModel.ImageXOffset = 11;
- enemyModel.ImageYOffset = 11;
- enemyModel.ImageWidth = 64;
- enemyModel.ImageHeight= 64;
- }
- enemyModel.friction = 1;
- //addChild(Circle);
- enemyModel.setY = enemyModel.yPos +PinkRadius;
- enemyModel.setX = enemyModel.xPos +PinkRadius;
- enemyModel.CharacterType = characterType;
- var enemyModelContainer = new TileModelContainer(enemyModel,_camera);
- _enemiesReserve.add(enemyModelContainer);
- }
- }