308 lines
10 KiB
ActionScript
308 lines
10 KiB
ActionScript
package com.arc.dh.state
|
|
{
|
|
import com.arc.dh.menu.MenuTooltip;
|
|
import com.arc.dh.menu.OptionsMenu;
|
|
import com.arc.dh.util.Data;
|
|
import com.arc.dh.util.DataSerializer;
|
|
import com.arc.dh.util.ParticleSystem;
|
|
import com.arc.dh.util.Sound;
|
|
import com.arc.dh.util.SoundSystem;
|
|
import com.arc.flixel.ArcButton;
|
|
import com.arc.flixel.ArcGroup;
|
|
import com.arc.flixel.ArcParticleSystem;
|
|
import com.arc.flixel.ArcSprite;
|
|
import com.arc.flixel.ArcU;
|
|
import flash.ui.Mouse;
|
|
import org.flixel.FlxG;
|
|
import org.flixel.FlxState;
|
|
|
|
public class MainMenu extends FlxState
|
|
{
|
|
|
|
private static const titleSprite:Class = MainMenu_titleSprite;
|
|
|
|
private static const titleGlowSprite:Class = MainMenu_titleGlowSprite;
|
|
|
|
private static const buttonPlay:Class = MainMenu_buttonPlay;
|
|
|
|
private static const buttonHelp:Class = MainMenu_buttonHelp;
|
|
|
|
private static const soundButton:Class = MainMenu_soundButton;
|
|
|
|
protected static const BACKGROUND_SPRITE3:Class = MainMenu_BACKGROUND_SPRITE3;
|
|
|
|
protected static const BACKGROUND_SPRITE2:Class = MainMenu_BACKGROUND_SPRITE2;
|
|
|
|
protected static const BACKGROUND_SPRITE1:Class = MainMenu_BACKGROUND_SPRITE1;
|
|
|
|
protected var bg3:ArcSprite;
|
|
|
|
protected var bg2:ArcSprite;
|
|
|
|
protected var bg1:ArcSprite;
|
|
|
|
protected var title:ArcSprite;
|
|
|
|
protected var titleGlow:ArcSprite;
|
|
|
|
protected var titleFadeIn:Boolean = false;
|
|
|
|
protected var emitters:ArcGroup = new ArcGroup();
|
|
|
|
protected var screen:MenuScreen;
|
|
|
|
public var mainScreen:MenuScreen;
|
|
|
|
public var storyScreen:MenuScreen;
|
|
|
|
public var escapeScreen:MenuScreen;
|
|
|
|
public var bossScreen:MenuScreen;
|
|
|
|
public var helpScreen:MenuScreen;
|
|
|
|
public var creditsScreen:MenuScreen;
|
|
|
|
public var minigamesScreen:MenuScreen;
|
|
|
|
public var _startScreen:int;
|
|
|
|
public var options:OptionsMenu;
|
|
|
|
public var inOptions:Boolean = false;
|
|
|
|
protected var fader:ArcSprite;
|
|
|
|
protected var faderStatus:int = 0;
|
|
|
|
public var tooltip:Tooltip;
|
|
|
|
public var hovering:Boolean = false;
|
|
|
|
public function MainMenu(param1:int = 0)
|
|
{
|
|
super();
|
|
this._startScreen = param1;
|
|
}
|
|
|
|
override public function create() : void
|
|
{
|
|
this.mainScreen = new MainScreen(this);
|
|
this.storyScreen = new StoryScreen(this);
|
|
this.escapeScreen = new EscapeScreen(this);
|
|
this.bossScreen = new BossScreen(this);
|
|
this.helpScreen = new HelpScreen(this);
|
|
this.creditsScreen = new CreditsScreen(this);
|
|
this.minigamesScreen = new MinigameScreen(this);
|
|
this.bg3 = new Background(0,0,BACKGROUND_SPRITE3);
|
|
this.bg3.scrollFactor.x = this.bg3.scrollFactor.y = 0.4;
|
|
this.add(this.bg3);
|
|
this.add(this.emitters);
|
|
this.bg2 = new Background(0,0,BACKGROUND_SPRITE2);
|
|
this.bg2.scrollFactor.x = this.bg2.scrollFactor.y = 0.6;
|
|
this.add(this.bg2);
|
|
this.bg1 = new Background(0,0,BACKGROUND_SPRITE1);
|
|
this.bg1.scrollFactor.x = this.bg1.scrollFactor.y = 0.8;
|
|
this.add(this.bg1);
|
|
this.titleGlow = new ArcSprite(4,4,titleGlowSprite);
|
|
this.titleGlow.scrollFactor.x = this.titleGlow.scrollFactor.y = 0;
|
|
this.add(this.titleGlow);
|
|
this.title = new ArcSprite(4,4,titleSprite);
|
|
this.title.scrollFactor.x = this.title.scrollFactor.y = 0;
|
|
this.add(this.title);
|
|
ParticleSystem.initialize();
|
|
this.emitters.add(ArcParticleSystem.emitters);
|
|
switch(this._startScreen)
|
|
{
|
|
case 0:
|
|
this.switchScreen(this.mainScreen);
|
|
break;
|
|
case 1:
|
|
this.switchScreen(this.escapeScreen);
|
|
break;
|
|
case 2:
|
|
this.switchScreen(this.bossScreen);
|
|
break;
|
|
case 3:
|
|
this.switchScreen(this.storyScreen);
|
|
break;
|
|
case 4:
|
|
this.switchScreen(this.mainScreen);
|
|
}
|
|
this.options = new OptionsMenu(function():void
|
|
{
|
|
inOptions = false;
|
|
});
|
|
this.fader = new ArcSprite(0,0);
|
|
this.fader.makeGraphic(FlxG.width,FlxG.height,4278190080);
|
|
this.fader.scrollFactor.x = this.fader.scrollFactor.y = 0;
|
|
this.fader.visible = false;
|
|
this.add(this.fader);
|
|
this.faderStatus = 1;
|
|
Mouse.hide();
|
|
FlxG.mouse.show();
|
|
super.create();
|
|
SoundSystem.music(Sound.TITLE_MUSIC,0.5);
|
|
Data.kong();
|
|
Newgrounds.medals();
|
|
}
|
|
|
|
override public function update() : void
|
|
{
|
|
var _loc1_:Array = null;
|
|
var _loc2_:Array = null;
|
|
var _loc3_:int = 0;
|
|
var _loc4_:ArcButton = null;
|
|
var _loc5_:Array = null;
|
|
if(this.faderStatus == 1)
|
|
{
|
|
this.fader.alpha -= FlxG.elapsed * 3;
|
|
if(this.fader.alpha <= 0)
|
|
{
|
|
this.faderStatus = -1;
|
|
}
|
|
return;
|
|
}
|
|
if(ArcU.rand(0,15) == 5)
|
|
{
|
|
ArcParticleSystem.emit(this.emitters,"diamonds",ArcU.rand(0,360),0,1,1,5,0,0,0,100,300);
|
|
}
|
|
if(this.titleFadeIn)
|
|
{
|
|
this.titleGlow.alpha += FlxG.elapsed;
|
|
if(this.titleGlow.alpha >= 1)
|
|
{
|
|
this.titleGlow.alpha = 1;
|
|
this.titleFadeIn = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.titleGlow.alpha -= FlxG.elapsed;
|
|
if(this.titleGlow.alpha <= 0)
|
|
{
|
|
this.titleGlow.alpha = 0;
|
|
this.titleFadeIn = true;
|
|
}
|
|
}
|
|
Data.time += FlxG.elapsed;
|
|
this.parallax();
|
|
SoundSystem.update();
|
|
super.update();
|
|
if(this.inOptions)
|
|
{
|
|
if(FlxG.keys.justPressed("ESCAPE"))
|
|
{
|
|
FlxG.keys.unJustPressed("ESCAPE");
|
|
this.inOptions = false;
|
|
DataSerializer.save();
|
|
}
|
|
this.options.update();
|
|
_loc1_ = [this.options.mouse,this.options.kb1,this.options.kb2,this.options.reset];
|
|
_loc2_ = [["Mouse Controls","Use A/D or LEFT/RIGHT to move, W or SPACE or UP to jump, MOUSE to aim, MOUSE BUTTON to shoot."],["Keyboard Controls","Use A/D to move, W or SPACE to jump, ARROWS to aim and shoot."],["Inverse Keyboard","Use LEFT/RIGHT to move, UP or SPACE to jump, A/S/D/W to aim and shoot."],["Reset All Data","This will clear all your saved data and restart you from scratch. Hold shift and click this button to clear data."]];
|
|
_loc3_ = 0;
|
|
while(_loc3_ < _loc1_.length)
|
|
{
|
|
_loc4_ = _loc1_[_loc3_] as ArcButton;
|
|
_loc5_ = _loc2_[_loc3_] as Array;
|
|
if(_loc4_.hover())
|
|
{
|
|
if(this.tooltip == null || this.tooltip.source != _loc4_)
|
|
{
|
|
this.tooltip = new MenuTooltip(_loc4_.x + _loc4_.width / 2,_loc4_.y,_loc5_[0],_loc5_[1]);
|
|
this.tooltip.source = _loc4_;
|
|
}
|
|
this.hovering = true;
|
|
}
|
|
_loc3_++;
|
|
}
|
|
if(!this.hovering && this.tooltip != null)
|
|
{
|
|
this.tooltip = null;
|
|
}
|
|
this.hovering = false;
|
|
return;
|
|
}
|
|
if(this.screen == this.helpScreen)
|
|
{
|
|
this.title.alpha = 0;
|
|
this.titleGlow.alpha = 0;
|
|
}
|
|
else
|
|
{
|
|
this.title.alpha = 1;
|
|
}
|
|
this.screen.update();
|
|
if(!this.hovering && this.tooltip != null)
|
|
{
|
|
this.tooltip = null;
|
|
}
|
|
this.hovering = false;
|
|
}
|
|
|
|
override public function draw() : void
|
|
{
|
|
super.draw();
|
|
this.screen.draw();
|
|
if(this.inOptions)
|
|
{
|
|
this.options.draw();
|
|
if(this.tooltip != null)
|
|
{
|
|
this.tooltip.draw();
|
|
}
|
|
return;
|
|
}
|
|
if(this.faderStatus == 1)
|
|
{
|
|
this.fader.draw();
|
|
}
|
|
if(this.tooltip != null)
|
|
{
|
|
this.tooltip.draw();
|
|
}
|
|
}
|
|
|
|
protected function parallax() : void
|
|
{
|
|
var _loc1_:ArcSprite = null;
|
|
var _loc2_:int = 0;
|
|
for each(_loc1_ in [this.bg1,this.bg2,this.bg3])
|
|
{
|
|
_loc1_.y += FlxG.elapsed * 20 * _loc1_.scrollFactor.y;
|
|
_loc2_ = _loc1_.getScreenXY().y;
|
|
if(_loc2_ < -420)
|
|
{
|
|
_loc1_.y = FlxG.camera.scroll.y * _loc1_.scrollFactor.y + (_loc2_ > 0 && _loc2_ < 1000 ? _loc2_ : 0);
|
|
}
|
|
else if(_loc2_ > 0)
|
|
{
|
|
_loc1_.y = FlxG.camera.scroll.y * _loc1_.scrollFactor.y - 420 + (_loc2_ > 0 && _loc2_ < 1000 ? _loc2_ : 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function switchScreen(param1:MenuScreen) : void
|
|
{
|
|
if(this.screen == this.mainScreen)
|
|
{
|
|
(this.mainScreen as MainScreen).unbindPegas();
|
|
}
|
|
else if(param1 == this.mainScreen)
|
|
{
|
|
(this.mainScreen as MainScreen).bindPegas();
|
|
}
|
|
if(this.screen == this.creditsScreen)
|
|
{
|
|
(this.creditsScreen as CreditsScreen).unbindPegas();
|
|
}
|
|
else if(param1 == this.creditsScreen)
|
|
{
|
|
(this.creditsScreen as CreditsScreen).bindPegas();
|
|
}
|
|
this.screen = param1;
|
|
}
|
|
}
|
|
}
|
|
|