I'm in the middle of writing my own little bullet shooter game much in the style of Touhou. Everything works fine so far but I'm disliking certain aspects of my code. Take this function for showing and unshowing the title screen:
private function runIntro() : void
{
if (introFadeInTitle_ && aliceIntroTxt.alpha < 1)
aliceIntroTxt.alpha += 0.02;
else if (introFadeInTitle_)
{
var timer : Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, function() {
timer.stop();
introFadeInBtns_ = true;
});
timer.start();
introFadeInTitle_ = false;
}
else if (introFadeInBtns_ && startBtn.alpha < 1)
{
startBtn.alpha += 0.02;
optionsBtn.alpha += 0.02;
}
else if (introFadeInBtns_)
{
introFadeInBtns_ = false;
gameState = GameState.READY;
}
if (introFadeOutBtns_ && startBtn.alpha > 0)
{
startBtn.alpha -= 0.02;
optionsBtn.alpha -= 0.02;
}
else if (introFadeOutBtns_)
{
var timer : Timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, function() {
timer.stop();
introFadeOutTitle_ = true;
});
timer.start();
introFadeOutBtns_ = false;
}
else if (introFadeOutTitle_ && aliceIntroTxt.alpha > 0)
aliceIntroTxt.alpha -= 0.02;
else if (introFadeOutTitle_)
{
var timer : Timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, function() {
timer.stop();
introFadeOutBg_ = true;
});
timer.start();
introFadeOutTitle_ = false;
}
else if (introFadeOutBg_ && introBg.alpha > 0)
introBg.alpha -= 0.02;
else if (introFadeOutBg_)
{
introFadeOutBg_;
gameState = GameState.RUNNING;
}
}
At a glance, it's just a bunch of if-else-if statements that check whether or not a given object has faded out and what the current state of the animation is. I feel that this if-else-if chain is alright for a rather short function like this, but I do have more complicated states that I wish to show (for example a ready-set-go splash before the fight begins) that would just balloon this kind of structure into an unholy mess.
What is the best way to deal with this code?