AS3基本射击游戏中的摇滚乐运动

时间:2015-11-13 05:30:11

标签: actionscript-3 flash game-physics

我需要一些摇滚运动的帮助...我对这些编码很新,并且几乎不知道我在做什么...

我的岩石每一个方向移动......我想要的是它们在左边的一个设定边界内开始并移动到右边的一个设定边界。

如果他们被击中,我希望他们爆炸而不是分裂成另外两块岩石。在电影中,我有多个岩石(大,中,小)和一个叫做爆炸的框架,但我试图从另一个代码改编的脚本似乎不适用于它。

    public function planeHit() {
        removeEventListener(Event.ENTER_FRAME,movePlane);
        MovieClip(parent).removePlane(this);
        gotoAndPlay("explode");
    }

当所有错误消失(从被拍摄或离开屏幕)时,我想要开始新浪潮......

这是我用于放置和移动岩石的脚本......

你能给予的任何帮助都会很棒!

    // ROCKS        

    // create a single rock of a specific size
    public function newRock(x,y:int, rockType:String) {

        // create appropriate new class
        var newRock:MovieClip;
        var rockRadius:Number;
        if (rockType == "Big") {
            newRock = new Rock_Big();
            rockRadius = 35;
        } else if (rockType == "Medium") {
            newRock = new Rock_Medium();
            rockRadius = 20;
        } else if (rockType == "Small") {
            newRock = new Rock_Small();
            rockRadius = 10;
        }


        // choose a random look
        newRock.gotoAndStop(Math.ceil(Math.random()*3+1));

        // set start position
        newRock.x = x;
        newRock.y = y;

        // set random movement and rotation

        var dx:Number = Math.random()*2.0;
        var dy:Number = Math.random()*2.0-1.0;

        // add to stage and to rocks list
        gameObjects.addChild(newRock);
        rocks.push({rock:newRock, dx:dx, dy:dy, rockType:rockType, rockRadius: rockRadius});
    }

    // create four rocks
    public function nextRockWave(event:TimerEvent) {
        rocks = new Array();
        newRock(100,100,"Big");
        newRock(200,100,"Big");
        newRock(450,100,"Big");
        newRock(350,100,"Big");
        gameMode = "play";
    }

    // animate all rocks
    public function moveRocks(timeDiff:uint) {
        for(var i:int=rocks.length-1;i>=0;i--) {

            // move the rocks
            var rockSpeed:Number = rockSpeedStart + rockSpeedIncrease*gameLevel;
            rocks[i].rock.x += rocks[i].dx*timeDiff*rockSpeed;
            rocks[i].rock.y += rocks[i].dy*timeDiff*rockSpeed;


            // wrap rocks
    if ((rocks[i].dx > 0) && (x <-50)) {
            gameObjects.removeChild;
            rocks.splice(); 
        }
            else if ((rocks[i].dx < 0) && (x > 350)) {
            gameObjects.removeChild;
            rocks.splice();         
        }


        }
    }

    public function rockHit(rockNum:uint) {
        // create two smaller rocks
        if (rocks[rockNum].rockType == "Big") {
            newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Medium");
            newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Medium");
        } else if (rocks[rockNum].rockType == "Medium") {
            newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Small");
            newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Small");
        }
        // remove original rock
        gameObjects.removeChild(rocks[rockNum].rock);
        rocks.splice(rockNum,1);
    }

1 个答案:

答案 0 :(得分:0)

要使用您发布的代码使对象动画直线移动,您有两种选择。

<强> 1。更改摇滚定义

像这样更改你的摇滚代码:

var dx:Number = Math.random()*2.0;
var dy:Number = 0;

// add to stage and to rocks list
gameObjects.addChild(newRock);
rocks.push({rock:newRock, dx:dx, dy:dy, rockType:rockType, rockRadius: rockRadius});

然后当你为岩石设置动画时,你不会对y - 坐标进行任何更改,因此它会在移动时保持在同一条线上。

<强> 2。更改动画代码

只需删除动画岩石的y值的行:

// move the rocks
var rockSpeed:Number = rockSpeedStart + rockSpeedIncrease*gameLevel;
rocks[i].rock.x += rocks[i].dx*timeDiff*rockSpeed;

// wrap rocks
...

然后你的循环中没有任何东西改变y - 坐标,所以它们会保持在同一条线上。