initial commit, kind of working.
This commit is contained in:
@@ -0,0 +1,321 @@
|
||||
package com.arc.dh.state
|
||||
{
|
||||
import Playtomic.Log;
|
||||
import com.arc.dh.entities.Player;
|
||||
import com.arc.dh.menu.GameOver;
|
||||
import com.arc.dh.objects.*;
|
||||
import com.arc.dh.util.Config;
|
||||
import com.arc.dh.util.Data;
|
||||
import com.arc.dh.util.DataSerializer;
|
||||
import com.arc.dh.util.Sound;
|
||||
import com.arc.dh.util.SoundSystem;
|
||||
import com.arc.flixel.ArcParticleSystem;
|
||||
import com.arc.flixel.ArcSprite;
|
||||
import flash.display.BitmapData;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import org.flixel.FlxG;
|
||||
import org.flixel.FlxObject;
|
||||
import org.flixel.FlxPoint;
|
||||
import org.flixel.FlxTilemap;
|
||||
import org.flixel.system.FlxTile;
|
||||
|
||||
public class BossMode extends PlayMode
|
||||
{
|
||||
|
||||
private static const ESCAPE_HEIGHT:int = 2000;
|
||||
|
||||
private static const ESCAPE_WIDTH:int = 30;
|
||||
|
||||
private static const BOTTOM_PADDING:int = 1;
|
||||
|
||||
private static const PLATFORM_SIZE:int = 3;
|
||||
|
||||
private static const LAVA_TELEPORT_DISTANCE:int = 220;
|
||||
|
||||
private var sourcePixels:BitmapData;
|
||||
|
||||
private var blankOverlay:BitmapData;
|
||||
|
||||
private var _gameOver:GameOver;
|
||||
|
||||
private var _heroic:Boolean = false;
|
||||
|
||||
private var _stage:int = 1;
|
||||
|
||||
private var _practice:Boolean = false;
|
||||
|
||||
public function BossMode(param1:Boolean, param2:int = 1, param3:Boolean = false)
|
||||
{
|
||||
super();
|
||||
mode = BOSS_MODE;
|
||||
this._stage = param2;
|
||||
_ch = param2;
|
||||
this._heroic = param1;
|
||||
this._practice = param3;
|
||||
this.sourcePixels = new BitmapData(30,20,false);
|
||||
this.blankOverlay = new BitmapData(30,20,false);
|
||||
}
|
||||
|
||||
public function isHeroic() : Boolean
|
||||
{
|
||||
return this._heroic;
|
||||
}
|
||||
|
||||
public function isPractice() : Boolean
|
||||
{
|
||||
return this._practice;
|
||||
}
|
||||
|
||||
override public function create() : void
|
||||
{
|
||||
super.create();
|
||||
Log.CustomMetric("BossStart","Modes");
|
||||
FlxG.camera.follow(null);
|
||||
SoundSystem.music(Sound.BOSS_MUSIC);
|
||||
}
|
||||
|
||||
override protected function getStartX() : int
|
||||
{
|
||||
switch(this._stage)
|
||||
{
|
||||
case 1:
|
||||
return 64;
|
||||
case 2:
|
||||
return 300;
|
||||
case 3:
|
||||
return 210;
|
||||
case 4:
|
||||
return 64;
|
||||
case 5:
|
||||
return 48;
|
||||
case 6:
|
||||
return 64;
|
||||
case 7:
|
||||
return 300;
|
||||
default:
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
|
||||
override protected function getStartY() : int
|
||||
{
|
||||
if(this._stage == 5)
|
||||
{
|
||||
return 96;
|
||||
}
|
||||
return 60;
|
||||
}
|
||||
|
||||
override public function update() : void
|
||||
{
|
||||
if(_complete)
|
||||
{
|
||||
this._gameOver.update();
|
||||
return;
|
||||
}
|
||||
super.update();
|
||||
if(inMenu)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
override protected function createLevel() : void
|
||||
{
|
||||
tilemap = this.buildLevel();
|
||||
tilemap.follow();
|
||||
}
|
||||
|
||||
override public function die() : void
|
||||
{
|
||||
_dieTimer = 1;
|
||||
++Data.deaths;
|
||||
DataSerializer.save();
|
||||
}
|
||||
|
||||
override public function reset() : void
|
||||
{
|
||||
_complete = true;
|
||||
inMenu = false;
|
||||
SoundSystem.play(Sound.WIN);
|
||||
this._gameOver = new GameOver(null,null,null).setCallback(function():void
|
||||
{
|
||||
FlxG.switchState(new BossMode(_heroic,_practice ? _stage : 1,_practice));
|
||||
},function():void
|
||||
{
|
||||
FlxG.switchState(new MainMenu(2));
|
||||
});
|
||||
}
|
||||
|
||||
override public function complete() : void
|
||||
{
|
||||
var newTime:Number = NaN;
|
||||
var index:int = 0;
|
||||
_complete = true;
|
||||
inMenu = false;
|
||||
if(!this._practice && _ch < 7)
|
||||
{
|
||||
FlxG.switchState(new BossMode(this._heroic,this._stage + 1));
|
||||
DataSerializer.save();
|
||||
return;
|
||||
}
|
||||
if(!this._practice && _ch == 7)
|
||||
{
|
||||
newTime = Math.ceil(Data.ctime) * 1000;
|
||||
index = this.isHeroic() ? 1 : 0;
|
||||
if(newTime < Data.boss[1 + 2 * index] || Data.boss[1 + 2 * index] == 0)
|
||||
{
|
||||
Data.boss[1 + 2 * index] = newTime;
|
||||
}
|
||||
++Data.boss[2 * index];
|
||||
}
|
||||
DataSerializer.save();
|
||||
Data.kong();
|
||||
Newgrounds.medals();
|
||||
SoundSystem.play(Sound.WIN);
|
||||
this._gameOver = new GameOver(null,null,duration).setCallback(function():void
|
||||
{
|
||||
if(_practice)
|
||||
{
|
||||
FlxG.switchState(new BossMode(_heroic,_stage,_practice));
|
||||
}
|
||||
else
|
||||
{
|
||||
FlxG.switchState(new BossMode(_heroic,1,_practice));
|
||||
}
|
||||
},function():void
|
||||
{
|
||||
FlxG.switchState(new MainMenu(2));
|
||||
});
|
||||
}
|
||||
|
||||
override public function restart() : void
|
||||
{
|
||||
var _loc2_:StoryDialog = null;
|
||||
var _loc1_:Array = checkpoints[checkpoints.length - 1];
|
||||
player.reset(_loc1_[0] * Config.BLOCK_SIZE + 4,_loc1_[1] * Config.BLOCK_SIZE + 12);
|
||||
FlxG.camera.focusOn(new FlxPoint(player.x,player.y));
|
||||
FlxG.camera.follow(player);
|
||||
boss = 0;
|
||||
spawner = new Object();
|
||||
pixels = mpixels.clone();
|
||||
for each(_loc2_ in messages)
|
||||
{
|
||||
_loc2_.load();
|
||||
}
|
||||
bullets.clear();
|
||||
enemies.clear();
|
||||
penemies.clear();
|
||||
diamonds.clear();
|
||||
powerups.clear();
|
||||
damagetexts.clear();
|
||||
healthbars.clear();
|
||||
objects.clear();
|
||||
cobjects.clear();
|
||||
spawnTop = this.calcTop(Config.SPAWN_PADDING);
|
||||
spawnBottom = this.calcBottom(Config.SPAWN_PADDING);
|
||||
despawnTop = player.y / Config.BLOCK_SIZE;
|
||||
despawnBottom = player.y / Config.BLOCK_SIZE + 1;
|
||||
}
|
||||
|
||||
private function createSourcePixels() : void
|
||||
{
|
||||
var _loc1_:BitmapData = new ArcSprite(0,0,StoryMode["CH" + this._stage]).pixels;
|
||||
var _loc2_:Rectangle = new Rectangle(0,0,30,20);
|
||||
this.sourcePixels.copyPixels(_loc1_,_loc2_,new Point(0,0));
|
||||
}
|
||||
|
||||
private function buildLevel() : FlxTilemap
|
||||
{
|
||||
var tileArray:Array;
|
||||
var tileCSV:String;
|
||||
var waterFunction:Function;
|
||||
var map:FlxTilemap = null;
|
||||
this.createSourcePixels();
|
||||
tileArray = this.imageToTileArray(this.sourcePixels,this.blankOverlay);
|
||||
tileCSV = FlxTilemap.arrayToCSV(tileArray,Config.BLOCK_WIDTH);
|
||||
map = new FlxTilemap();
|
||||
map.loadMap(tileCSV,PlayMode["T" + _ch],Config.BLOCK_SIZE,Config.BLOCK_SIZE,0,0,1,80);
|
||||
map.setTileProperties(52,FlxObject.ANY,function(param1:FlxTile, param2:FlxObject):void
|
||||
{
|
||||
if(param2 is Bullet)
|
||||
{
|
||||
ArcParticleSystem.emit(Data.state.particles,"wooden_crate",param1.x,param1.y,10,1,5,400,-100,100,-100,-40,param1.width,param1.height);
|
||||
map.setTileByIndex(param1.mapIndex,0,true);
|
||||
}
|
||||
});
|
||||
map.setTileProperties(53,FlxObject.ANY,function(param1:FlxTile, param2:FlxObject):void
|
||||
{
|
||||
if(param2 is Missile)
|
||||
{
|
||||
ArcParticleSystem.emit(Data.state.particles,"steel_crate",param1.x,param1.y,10,1,5,800,-100,100,-200,-80,param1.width,param1.height);
|
||||
map.setTileByIndex(param1.mapIndex,0,true);
|
||||
}
|
||||
});
|
||||
waterFunction = function(param1:FlxTile, param2:FlxObject):void
|
||||
{
|
||||
var _loc3_:Player = param2 as Player;
|
||||
if(_loc3_ == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loc3_.inWater();
|
||||
};
|
||||
map.setTileProperties(12,FlxObject.NONE,waterFunction,Player);
|
||||
map.setTileProperties(56,FlxObject.ANY);
|
||||
return map;
|
||||
}
|
||||
|
||||
private function imageToTileArray(param1:BitmapData, param2:BitmapData) : Array
|
||||
{
|
||||
var _loc5_:int = 0;
|
||||
var _loc6_:uint = 0;
|
||||
var _loc7_:int = 0;
|
||||
this.pixels = param1;
|
||||
this.overpixels = param2;
|
||||
var _loc3_:Array = new Array();
|
||||
mpixels = param1.clone();
|
||||
var _loc4_:int = 0;
|
||||
while(_loc4_ < param1.height)
|
||||
{
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ < param1.width)
|
||||
{
|
||||
_loc6_ = getLayerTile(_loc5_,_loc4_,true);
|
||||
_loc7_ = colorToTileID(_loc6_,_loc5_,_loc4_);
|
||||
_loc3_.push(_loc7_);
|
||||
_loc5_++;
|
||||
}
|
||||
_loc4_++;
|
||||
}
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
override public function draw() : void
|
||||
{
|
||||
super.draw();
|
||||
if(_complete && this._gameOver != null)
|
||||
{
|
||||
this._gameOver.draw();
|
||||
}
|
||||
}
|
||||
|
||||
override protected function calcTop(param1:int) : int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
override protected function calcBottom(param1:int) : int
|
||||
{
|
||||
return pixels.height;
|
||||
}
|
||||
|
||||
override public function setBoss(param1:int) : void
|
||||
{
|
||||
boss = 2;
|
||||
bossHeight = param1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user