我正在使用 ActionScript 3.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);
}
}
}
}
}
}