0

ActionScript 3.0 でバブル シューター ゲームを作成していますが、バブルを正しく配置できません。次のようになります。

00000000
 00000000
00000000
 00000000

しかし、私は現時点で1行目と3行目を配置しているだけで、何が間違っているのかわかりません..これまでのコードは次のとおりです。

bubble_mc: (これは私の泡です。6 つの異なる泡があります)

package  {
    import flash.display.MovieClip;
    public class bubble_mc extends MovieClip {
        public function bubble_mc(val:uint,row:uint,col:uint) {
            gotoAndStop(val+1);
            name=row+"_"+col;
            x=50+col*36;
            y=40+row*36;
        }

    }

}

主要:

package  {
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    public class Main extends Sprite {
        private const ROT_SPEED:uint=2;
        private const R:uint=18;
        private const D:Number=R*Math.sqrt(3);
        private var bubbleArr:Array=new Array();
        private var cannon:cannon_mc;
        private var bubble:bubble_mc;
        private var left:Boolean=false;
        private var right:Boolean=false;
        private var bubCont:Sprite;
        public function Main() {
            placeContainer();
            placeCannon();
            stage.addEventListener(KeyboardEvent.KEY_DOWN,onKDown);
            stage.addEventListener(KeyboardEvent.KEY_UP,onKUp);
            addEventListener(Event.ENTER_FRAME,onEFrame);
        }
        private function placeCannon():void {
            cannon=new cannon_mc();
            addChild(cannon);
            cannon.y=385.5;
            cannon.x=320;
        }
        private function onKDown(e:KeyboardEvent):void {
            switch(e.keyCode) {
                case 37 :
                    left=true;
                    break;
                case 39 :
                    right=true;
                    break;
            }
        }
        private function onKUp(e:KeyboardEvent):void {
            switch(e.keyCode) {
                case 37 :
                    left=false;
                    break;
                case 39 :
                    right=false;
                    break;
            }
        }
        private function onEFrame(e:Event):void {
            if (left) {
                cannon.rotation-=ROT_SPEED;
            }
            if (right) {
                cannon.rotation+=ROT_SPEED;
            }
        }
        private function placeContainer():void {
            bubCont=new Sprite();
            addChild(bubCont);
            bubCont.graphics.lineStyle(1,0xffffff,1);
            for (var i:uint=0; i<4; i++) {
                if (i%2==0) {
                    for (var j:uint=0; j<15; j++) {
                        bubbleArr[i]=new Array();
                        bubbleArr[i][j]=Math.floor(Math.random()*6);
                        bubble = new bubble_mc(bubbleArr[i][j],i,j);
                        bubCont.addChild(bubble);
                    }
                } else {
                        if (j<14) {
                            bubbleArr[i][j]=Math.floor(Math.random()*6);
                            bubble = new bubble_mc(bubbleArr[i][j],i,j);
                            bubble.x=68+i*36;
                            bubCont.addChild(bubble);
                        }
                }
            }
        }
    }
}
4

1 に答える 1

0

私はそれを解決しました!誰かが同じ問題を抱えている場合に備えて、これが私が解決したコードです! (x座標に加えた変更は問題ではありません..)

bubble_mc:

package  {
    import flash.display.MovieClip;
    public class bubble_mc extends MovieClip {
        public function bubble_mc(val:uint,row:uint,col:uint) {
            gotoAndStop(val+1);
            name=row+"_"+col;
            x=59+col*36;
            y=40+row*36;
        }
    }
}

主要

package  {
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    public class Main extends Sprite {
        private const ROT_SPEED:uint=2;
        private const R:uint=18;
        private const D:Number=R*Math.sqrt(3);
        private var bubbleArr:Array=new Array();
        private var cannon:cannon_mc;
        private var bubble:bubble_mc;
        private var left:Boolean=false;
        private var right:Boolean=false;
        private var bubCont:Sprite;
        public function Main() {
            placeContainer();
            placeCannon();
            stage.addEventListener(KeyboardEvent.KEY_DOWN,onKDown);
            stage.addEventListener(KeyboardEvent.KEY_UP,onKUp);
            addEventListener(Event.ENTER_FRAME,onEFrame);
        }
        private function placeCannon():void {
            cannon=new cannon_mc();
            addChild(cannon);
            cannon.y=385.5;
            cannon.x=320;
        }
        private function onKDown(e:KeyboardEvent):void {
            switch(e.keyCode) {
                case 37 :
                    left=true;
                    break;
                case 39 :
                    right=true;
                    break;
            }
        }
        private function onKUp(e:KeyboardEvent):void {
            switch(e.keyCode) {
                case 37 :
                    left=false;
                    break;
                case 39 :
                    right=false;
                    break;
            }
        }
        private function onEFrame(e:Event):void {
            if (left) {
                cannon.rotation-=ROT_SPEED;
            }
            if (right) {
                cannon.rotation+=ROT_SPEED;
            }
        }
        private function placeContainer():void {
            var iRow:Boolean=false;
            bubCont=new Sprite();
            addChild(bubCont);
            bubCont.graphics.lineStyle(1,0xffffff,1);
            for (var i:uint=0; i<4; i++) {
                if (! iRow) {
                    for (var j:uint=0; j<15; j++) {
                        bubbleArr[i]=new Array();
                        bubbleArr[i][j]=Math.floor(Math.random()*6);
                        bubble = new bubble_mc(bubbleArr[i][j],i,j);
                        bubCont.addChild(bubble);
                        iRow=true;
                    }
                } else {
                    for (j=0; j<15; j++) {
                        bubbleArr[i]=new Array();
                        bubbleArr[i][j]=Math.floor(Math.random()*6);
                        bubble = new bubble_mc(bubbleArr[i][j],i,j);
                        bubble.x=77+j*36;
                        bubCont.addChild(bubble);
                        iRow=false;
                    }
                }
            }
        }
    }
}
于 2012-07-13T12:50:50.580 に答える