宇宙飞船失踪儿童子弹as3

时间:2015-12-29 15:36:47

标签: actionscript-3

我不能得到的是我得到了一个叫做射线的符号,这是我太空飞船的子弹,当太空被触发时我不会把子弹放在舞台上  有人可以帮我这个吗?你可以看到我在一堂课上写作,所以如果你知道一种可能的方法让我的宇宙飞船射出一条光线,那就太棒了。

包{

import flash.display.MovieClip;
import flash.events.*
import flash.ui.Keyboard;

public class SpaceInvaders extends MovieClip {
    var left: Boolean;
    var right: Boolean;
    var shoot: Boolean;
    var upKey: Boolean;
    var downKey: Boolean;
    var player: Player;
    var ray: Ray;

    public function SpaceInvaders() {
        player = new Player();
        ray = new Ray();
        spawn();
        fireSpawn();
        left = false;
        right = false;
        shoot = false;
        upKey = false;
        downKey = false;

        stage.addEventListener(Event.ENTER_FRAME, update);
        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
        stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
    }

    public function spawn() {
        trace("ree");
        player.x = 95;
        player.y = 200;
        this.stage.addChild(player);



    }
    public function fireSpawn(players) {
        trace("fireshoot");

    }


    public function update(e: Event) {
        if (left) {
            player.x -= 10;
            trace("left");
        }
        if (right) {
            player.x += 10;
            trace("right");
        }
        if (shoot) {
            addChild(ray);
            trace("shoot");
        }
        if (upKey) {
            player.y += 10;
            trace("up");
        }
        if (downKey) {
            player.y -= 10;
            trace("down")
        }
    }
    public function keyDownHandler(event: KeyboardEvent): void {
        switch (event.keyCode) {
            case Keyboard.LEFT:
                left = true;
                break;

            case Keyboard.RIGHT:
                right = true;
                break;

            case Keyboard.SPACE:
                shoot = true;
                break;
            case Keyboard.UP:
                upKey = true;
                 break;
            case Keyboard.DOWN:
                downKey = true;
                break;
            default:
                break;
        }
    }

    public function keyUpHandler(event: KeyboardEvent): void {
        switch (event.keyCode) {
            case Keyboard.LEFT:
                left = false;
                break;

            case Keyboard.RIGHT:
                right = false;
                break;

            case Keyboard.SPACE:
                shoot = false;
                break;

            case Keyboard.UP:
                upKey = false;
                break;

            case Keyboard.DOWN:
                downKey = false;
                break;

            default:
                break;
        }
    }
}

}

0 个答案:

没有答案