アクションゲームのテンプレート作成のための作業中。今日の成果は「配列で指定したとおりにブロックを表示する」ところまで。配列を外部から読み込めるようにすれば、そこそこ汎用的か。今回は汎用性はどうでもいいんだけど。
そろそろフラッシュをここに埋め込んで外部から確認できるようにしたいな。swfを何処に置くかが問題だ。
明日は「ドットの移動とブロックの衝突処理」あたりをやる予定。
しばらくは1ファイルで全部やるつもり。
//mxmlc Main.as //author Show=O=Healer package { //Common import flash.display.*; import flash.events.*; //Class public class Main extends Sprite { //Common private var m_Container : Sprite; //Param private const GRAVITY:Number = 10.0; //Constructor public function Main():void { {//Init Common //リサイズ対応 stage.addEventListener(Event.RESIZE, onStageResize); //定期的にupdateを呼ばせる addEventListener(Event.ENTER_FRAME, update); } addChild(new BlockManager()); } //=Common= private function update( event:Event ):void { } private function onStageResize(event:Event):void { m_Container.x = stage.stageWidth / 2; m_Container.y = stage.stageHeight / 2; } } } //=Local Class= import flash.display.*; var BLOCK_DATA:Array = [ [0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 1, 0], [0, 0, 0, 1, 1], [0, 1, 0, 1, 1], [0, 1, 1, 1, 1], [1, 1, 1, 1, 1] ]; //BLOCK_DATAをもとにBlockを生成 class BlockManager extends Sprite { public function BlockManager():void { BLOCK_DATA.forEach( function(innerArray:Array, indexY:int, array:Array):void{ innerArray.forEach( function(val:int, indexX:int, array2:Array):void{ if(val == 1){ CreateBlock(indexX, indexY); } } ); } ); } //指定箇所にブロックを作成 public function CreateBlock(x:int, y:int):void{ var block:Block = new Block(); block.x = 0.5*10 + 10 * x; block.y = 0.5*10 + 10 * y; addChild(block); } } //ブロックの描画 class Block extends Sprite { //Param private const W:int = 10; private const H:int = 10; public function Block():void { var sp:Sprite = new Sprite(); sp.graphics.lineStyle(1, 0x4b2503, 1.0); sp.graphics.beginFill(0x8b4513); sp.graphics.drawRect(-0.5*W, -0.5*H, W, H); sp.graphics.endFill(); addChild(sp); } }
参考
- http://labs.anthill.jp/2008/01/as3array.html
- forEachなどの使い方
- AS3で1ファイルに複数のクラスを定義する方法 - てっく煮ブログ 跡地
- 一つのファイルに複数のクラスを入れる方法