シューティングゲームを作る5


今回はステージ選択をできるようにしてみました。
ちなみに今回はFlexで作りました。


こんな感じ


ステージ選択を簡単にするために各Stageクラスを新たに作りました。


Flexではステージの選択と、それに対応したステージをSWFLoaderを使って表示させています。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>
		<![CDATA[
			import __AS3__.vec.Vector;
			private var current_stage:B_Stage;
			
			private function init():void{
				var diff:uint = uint(difficult_group.selectedValue);
				
				if(loader.numChildren > 0){
					current_stage.remove();
					loader.removeChild(current_stage);
				}

				switch(select_stage.selectedIndex){
					case 0:
					current_stage = new Stage_Nway(diff); //引数で難易度指定
					loader.addChild(current_stage);
					break;
					
					case 1:
					current_stage = new Stage_AimNway(diff);
					loader.addChild(current_stage);
					break;
					
					case 2:
					current_stage = new Stage_RandomNway(diff);
					loader.addChild(current_stage);
					break;
					
					case 3:
					current_stage = new Stage_RollingNway(diff);
					loader.addChild(current_stage);
					break;
					
					case 4:
					current_stage = new Stage_WavingNway(diff);
					loader.addChild(current_stage);
					break;
					
					default:
				}
			}
		]]>
	</mx:Script>
	<mx:Canvas x="200" y="0" width="600" height="800" backgroundColor="0x000000">
		<mx:SWFLoader id="loader" x="0" y="0" width="100%" height="100%"/>
	</mx:Canvas>
	<mx:ComboBox x="10" y="10" width="182" id="select_stage" text="Stage Select">
		<mx:dataProvider>
			<mx:Array>
				<mx:Object label="Nway"/>
				<mx:Object label="Aim_Nway"/>
				<mx:Object label="Random_Nway"/>
				<mx:Object label="Rolling_Nway"/>
				<mx:Object label="Waving_Nway"/>
			</mx:Array>
		</mx:dataProvider>
	</mx:ComboBox>
	<mx:Button x="64" y="598" label="Start" width="128" id="start_btn" click="init()"/>
	<mx:RadioButtonGroup id="difficult_group"/>
	<mx:RadioButton x="10" y="40" label="EASY" groupName="difficult_group" selected="true" value="0"/>
	<mx:RadioButton x="10" y="66" label="NORMAL" groupName="difficult_group" value="1"/>
	<mx:RadioButton x="10" y="92" label="HARD" groupName="difficult_group" value="2"/>
</mx:Application>


ソース