436 lines
14 KiB
ActionScript
436 lines
14 KiB
ActionScript
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.AchievementSystem;
|
|
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 com.arc.flixel.ArcU;
|
|
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 EscapeMode extends PlayMode
|
|
{
|
|
|
|
protected static const ESCAPE_SPRITE:Class = EscapeMode_ESCAPE_SPRITE;
|
|
|
|
protected static const ESCAPE_OVERLAY_SPRITE:Class = EscapeMode_ESCAPE_OVERLAY_SPRITE;
|
|
|
|
protected static const LAVA_SPRITE:Class = EscapeMode_LAVA_SPRITE;
|
|
|
|
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 sourceOverlayPixels:BitmapData;
|
|
|
|
private var chunks:Array;
|
|
|
|
private var lavaStarted:Boolean;
|
|
|
|
private var lava:ArcSprite;
|
|
|
|
private var _gameOver:GameOver;
|
|
|
|
public function EscapeMode(param1:int)
|
|
{
|
|
super();
|
|
mode = ESCAPE_MODE;
|
|
this.sourcePixels = new ArcSprite(0,0,ESCAPE_SPRITE).pixels;
|
|
this.sourceOverlayPixels = new ArcSprite(0,0,ESCAPE_OVERLAY_SPRITE).pixels;
|
|
startHeight = param1;
|
|
_ch = ArcU.rand(1,7);
|
|
}
|
|
|
|
override public function create() : void
|
|
{
|
|
super.create();
|
|
Log.CustomMetric("EndlessStart","Modes");
|
|
spawnChance = 50;
|
|
this.lava = new ArcSprite(0,80,LAVA_SPRITE);
|
|
this.lava.y = player.y + 24;
|
|
this.lava.velocity.y = -5;
|
|
lavagroup.add(this.lava);
|
|
StoryMode.storyMusic(_ch);
|
|
}
|
|
|
|
override public function update() : void
|
|
{
|
|
var _loc2_:Boolean = false;
|
|
if(_complete)
|
|
{
|
|
this._gameOver.update();
|
|
showAchievement();
|
|
return;
|
|
}
|
|
super.update();
|
|
if(inMenu)
|
|
{
|
|
return;
|
|
}
|
|
var _loc1_:int = caveHeight;
|
|
if(_loc1_ >= 1)
|
|
{
|
|
if(_loc1_ < 1000)
|
|
{
|
|
spawnChance = 50 + 50 * (_loc1_ / 1000);
|
|
}
|
|
else
|
|
{
|
|
spawnChance = 100;
|
|
}
|
|
}
|
|
if(FlxG.keys.justPressed("R"))
|
|
{
|
|
FlxG.switchState(new EscapeMode(0));
|
|
}
|
|
if(this.lavaStarted)
|
|
{
|
|
if(_loc1_ < 50)
|
|
{
|
|
this.lava.velocity.y = -5;
|
|
}
|
|
else
|
|
{
|
|
this.lava.velocity.y = (_loc1_ - 50) / -30 - 5;
|
|
}
|
|
if(this.lava.velocity.y < -60)
|
|
{
|
|
this.lava.velocity.y = -60;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.lava.velocity.y = -5;
|
|
if(player.y < tilemap.height - 80 && Boolean(player.touching & FlxObject.DOWN))
|
|
{
|
|
this.lavaStarted = true;
|
|
}
|
|
}
|
|
if(this.lava.getScreenXY().y < -20)
|
|
{
|
|
this.lava.y = FlxG.camera.scroll.y - 20;
|
|
}
|
|
if(this.lava.y > player.y + LAVA_TELEPORT_DISTANCE)
|
|
{
|
|
this.lava.y = player.y + LAVA_TELEPORT_DISTANCE;
|
|
}
|
|
else if(this.lava.y < player.y)
|
|
{
|
|
if(Data.moltensuit == 0 || !player.lastHitLava)
|
|
{
|
|
player.invulnerable = 0;
|
|
}
|
|
_loc2_ = false;
|
|
if(!player.shielded)
|
|
{
|
|
if(Data.moltensuit == 0 || !player.lastHitLava)
|
|
{
|
|
player.invulnerable = 0;
|
|
}
|
|
_loc2_ = player.hit(100,false,true,false,true);
|
|
}
|
|
if(Data.hp <= 0)
|
|
{
|
|
AchievementSystem.lava();
|
|
}
|
|
if(_loc2_)
|
|
{
|
|
if(Data.moltensuit == 1)
|
|
{
|
|
player.invulnerable = 1.5;
|
|
}
|
|
else
|
|
{
|
|
player.invulnerable = 0;
|
|
}
|
|
}
|
|
player.inWater();
|
|
}
|
|
}
|
|
|
|
override protected function createLevel() : void
|
|
{
|
|
this.chunks = this.buildChunks();
|
|
tilemap = this.buildLevel();
|
|
tilemap.follow();
|
|
}
|
|
|
|
override public function die() : void
|
|
{
|
|
_complete = true;
|
|
inMenu = false;
|
|
SoundSystem.play(Sound.WIN);
|
|
this._gameOver = new GameOver(cdiamonds.toString(),caveHeight.toString() + "M",duration).setCallback(function():void
|
|
{
|
|
FlxG.mouse.hide();
|
|
FlxG.switchState(new EscapeMode(startHeight));
|
|
},function():void
|
|
{
|
|
FlxG.mouse.hide();
|
|
FlxG.switchState(new MainMenu(1));
|
|
});
|
|
Log.LevelAverageMetric("EndlessHeight",1,caveHeight);
|
|
++Data.deaths;
|
|
DataSerializer.save();
|
|
Data.kong();
|
|
Newgrounds.medals();
|
|
}
|
|
|
|
override public function reset() : void
|
|
{
|
|
}
|
|
|
|
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);
|
|
Data.hp = Data.hpm;
|
|
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 = calcTop(Config.SPAWN_PADDING);
|
|
spawnBottom = calcBottom(Config.SPAWN_PADDING);
|
|
despawnTop = player.y / Config.BLOCK_SIZE;
|
|
despawnBottom = player.y / Config.BLOCK_SIZE + 1;
|
|
}
|
|
|
|
private function buildLevel() : FlxTilemap
|
|
{
|
|
var waterFunction:Function;
|
|
var map:FlxTilemap = null;
|
|
var tileArray:Array = this.createRandomMap();
|
|
var tileCSV:String = 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
|
|
{
|
|
var _loc3_:int = 0;
|
|
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);
|
|
_loc3_ = ArcU.rand(0,100);
|
|
if(_loc3_ >= 80)
|
|
{
|
|
if(_loc3_ < 99)
|
|
{
|
|
addDiamonds(param1.x,param1.y,ArcU.rand(1,2 * _ch));
|
|
}
|
|
else
|
|
{
|
|
createHeart(param1.x,param1.y);
|
|
}
|
|
}
|
|
++Data.boxes;
|
|
SoundSystem.play(Sound.BOX,0.4);
|
|
AchievementSystem.boxes();
|
|
}
|
|
});
|
|
map.setTileProperties(53,FlxObject.ANY,function(param1:FlxTile, param2:FlxObject):void
|
|
{
|
|
var _loc3_:int = 0;
|
|
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);
|
|
_loc3_ = ArcU.rand(0,100);
|
|
if(_loc3_ >= 50)
|
|
{
|
|
if(_loc3_ < 99)
|
|
{
|
|
addDiamonds(param1.x,param1.y,ArcU.rand(1,2 * _ch));
|
|
}
|
|
else
|
|
{
|
|
createHeart(param1.x,param1.y);
|
|
}
|
|
}
|
|
++Data.boxes;
|
|
SoundSystem.play(Sound.STEELBOX);
|
|
AchievementSystem.boxes();
|
|
}
|
|
});
|
|
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_;
|
|
}
|
|
|
|
private function createRandomMap() : Array
|
|
{
|
|
var _loc10_:Array = null;
|
|
var _loc11_:Array = null;
|
|
var _loc12_:int = 0;
|
|
var _loc13_:int = 0;
|
|
var _loc14_:int = 0;
|
|
var _loc15_:int = 0;
|
|
var _loc16_:uint = 0;
|
|
var _loc1_:int = 0;
|
|
var _loc2_:int = 0;
|
|
var _loc3_:int = 0;
|
|
var _loc4_:int = ESCAPE_HEIGHT;
|
|
var _loc5_:int = 0;
|
|
var _loc6_:Array = new Array();
|
|
while(_loc5_ < _loc4_)
|
|
{
|
|
_loc11_ = this.chunks[ArcU.rand(0,this.chunks.length - 1)] as Array;
|
|
_loc6_.push(_loc11_);
|
|
_loc5_ += _loc11_[1] as int;
|
|
}
|
|
var _loc7_:int = _loc5_ + BOTTOM_PADDING + PLATFORM_SIZE;
|
|
var _loc8_:BitmapData = new BitmapData(ESCAPE_WIDTH,_loc7_,false);
|
|
var _loc9_:BitmapData = new BitmapData(ESCAPE_WIDTH,_loc7_,false);
|
|
for each(_loc10_ in _loc6_)
|
|
{
|
|
_loc12_ = _loc10_[0] as int;
|
|
_loc13_ = _loc10_[1] as int;
|
|
if(ArcU.rand(0,1) == 0)
|
|
{
|
|
_loc8_.copyPixels(this.sourcePixels,new Rectangle(1,_loc12_,ESCAPE_WIDTH,_loc13_),new Point(0,_loc1_));
|
|
}
|
|
else
|
|
{
|
|
_loc14_ = 0;
|
|
while(_loc14_ < _loc13_)
|
|
{
|
|
_loc15_ = 0;
|
|
while(_loc15_ <= ESCAPE_WIDTH)
|
|
{
|
|
_loc16_ = this.sourcePixels.getPixel(_loc15_,_loc14_ + _loc12_);
|
|
if(_loc16_ == 7766374)
|
|
{
|
|
_loc16_ = 5069370;
|
|
}
|
|
else if(_loc16_ == 5069370)
|
|
{
|
|
_loc16_ = 7766374;
|
|
}
|
|
_loc8_.setPixel(ESCAPE_WIDTH - _loc15_,_loc14_ + _loc1_,_loc16_);
|
|
_loc15_++;
|
|
}
|
|
_loc14_++;
|
|
}
|
|
}
|
|
_loc1_ += _loc13_;
|
|
}
|
|
_loc2_ = 2;
|
|
while(_loc2_ < ESCAPE_WIDTH - 2)
|
|
{
|
|
_loc3_ = _loc7_ - PLATFORM_SIZE;
|
|
while(_loc3_ < _loc7_)
|
|
{
|
|
_loc8_.setPixel(_loc2_,_loc3_,_loc3_ == _loc7_ - PLATFORM_SIZE ? 5228053 : 10052885);
|
|
_loc9_.setPixel(_loc2_,_loc3_,16777215);
|
|
_loc3_++;
|
|
}
|
|
_loc2_++;
|
|
}
|
|
return this.imageToTileArray(_loc8_,_loc9_);
|
|
}
|
|
|
|
private function buildChunks() : Array
|
|
{
|
|
var _loc4_:uint = 0;
|
|
var _loc1_:Array = new Array();
|
|
var _loc2_:int = -1;
|
|
var _loc3_:int = 0;
|
|
while(_loc3_ < this.sourcePixels.height)
|
|
{
|
|
_loc4_ = this.sourcePixels.getPixel(0,_loc3_);
|
|
if(_loc4_ == 16711920)
|
|
{
|
|
if(_loc2_ != -1)
|
|
{
|
|
_loc1_.push([_loc2_,_loc3_ - _loc2_]);
|
|
}
|
|
_loc2_ = _loc3_;
|
|
}
|
|
_loc3_++;
|
|
}
|
|
_loc1_.push([_loc2_,_loc3_ - _loc2_]);
|
|
return _loc1_;
|
|
}
|
|
|
|
override public function draw() : void
|
|
{
|
|
super.draw();
|
|
if(_complete && this._gameOver != null)
|
|
{
|
|
this._gameOver.draw();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|