2012-07-11 93 views
0

我正在ActionScript 3.0中製作泡泡射擊遊戲,並且在放置泡泡時遇到問題。它應該是這個樣子:如何爲氣泡射擊遊戲放置氣泡? AS3.0

00000000 
00000000 
00000000 
00000000 

,但我只是將第一個和第三排的那一刻,我不知道我做錯了什麼。這裏是我到目前爲止的代碼:

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); 
         } 
       } 
      } 
     } 
    } 
} 
+0

有什麼問題嗎? – Florent 2012-07-11 09:30:39

+0

我已經解決了!如果有人遇到同樣的問題,請輸入以下代碼: – JNeander 2012-07-11 09:31:53

+0

您應該將您的解決方案作爲答案添加,然後接受您自己的答案。這樣,它就會顯示爲回答並接受尋找as3問題的其他人。 – Ribs 2012-07-12 20:46:30

回答

0

我已經解決了!如果有人有同樣的問題,這裏是我解決它的代碼! (我對x座標進行的更改事.. doesnh't)

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; 
        } 
       } 
      } 
     } 
    } 
}