0

我正在为我在大学的课程制作一个 Flash 游戏,我一直在学习一个教程,但为了我自己的缘故一直在把它改掉。我撞到的一堵墙是,当我发射一颗子弹时,它只会向右侧发射,上下移动一点,我一直试图修复它一段时间,但没有任何反应,也没有任何作用。

包裹 {

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

public class Wizard extends MovieClip {

    private var dx:Number;
    private var dy:Number;
    private var Bulletspeed:int;
    public var Angle:Number;
    public var newAngle:Number;
    var shotCoolDown:int;
    const MAX_COOLDOWN=20;
    public function Wizard() {
        //constructor
        //Shot cool down
        shotCoolDown=MAX_COOLDOWN;
        addEventListener(Event.ENTER_FRAME, update);
        //set up an event listener for when the turret is added to stage
        addEventListener(Event.ADDED_TO_STAGE, initialise);




    }
    function initialise(e:Event) {
        //reduce shot cool down by one
        shotCoolDown=shotCoolDown-1;

        //add a click listener to the stage
        stage.addEventListener(MouseEvent.CLICK, fire);
    }
    function fire(m:MouseEvent) {
        //Able to shoot
        if (shotCoolDown<=0) {
            //resets cool down
            shotCoolDown=MAX_COOLDOWN;
            //spawn bullet
            var B = new Bullet();
            //set position and rotation of the bullet
            B.rotation=rotation;
            B.x=x;
            B.y=y;
            //add the bullet the the wizard
            parent.addChild(B);
        }
    }

    function update():void {
        //Shot cool down
        shotCoolDown--;
        //Make the Wizard face the mouse
        if (parent!=null) {
            dx=stage.mouseX-this.x;
            dy=stage.mouseY-this.y;
            Math.abs(dx);
            Math.abs(dy);
            var Angle=Math.atan2(dy,dx);
            var newAngle = Angle * (180 / Math.PI);

            if ((0 < newAngle) && (newAngle <= 90)) {
                gotoAndPlay("Right");
            } else if ((90 < newAngle) && (newAngle <= 180)) {
                gotoAndPlay("Down");
            } else if ((-180 < newAngle) && (newAngle <= -90)) {
                gotoAndPlay("Left");
            } else if ((-90 < newAngle) && (newAngle <= 0)) {
                gotoAndPlay("Up");
            }

            this.rotation=Angle;

        }
    }
}

}

那是我的玩家类的代码,包括子弹发射等等。我想我知道问题所在,我需要将其链接到向导更新的其余部分。但我不知道如何,如果需要,这是我的子弹课。

包裹 {

import flash.display.Sprite;
import flash.events.Event;

public class Bullet extends Sprite {

    private var speed:int;
    private var myCharacter:Wizard;



    public function Bullet() {
        //constructor
        speed = 10;
        addEventListener(Event.ENTER_FRAME, update);


    }



    function update (e:Event) {
            //Move in the direction the bullet is facing
        x=x+Math.cos(rotation/180*Math.PI)*speed;
        y=y+Math.sin(rotation/180*Math.PI)*speed;
        //Clears bullet once it leaves the stage
        if (x<0 || x>500 || y<0 || y>500) {
            //removes the update listner
            removeEventListener(Event.ENTER_FRAME, update);

            parent.removeChild(this);




        }
    }
}

}

4

1 回答 1

0

您将Wizard's设置rotationAngle,以弧度表示;然后将旋转传递给Bullet,它期望其旋转以度为单位。最好this.rotation=newAngle;在 末尾设置update(),因为UIComponent该类期望以度为单位的值并将其用于旋转其绘图。

于 2012-06-22T19:20:15.480 回答