0

生成されたグリッドをキーボードで移動しようとしています... .swf ファイルを試してみると、実行されますが、キーボードです... これはマリオのようなプラットフォーム ゲーム用なので、そこに認識されていないコード行を修正する必要があります、しかし、私は彼らがすることを保証します!

だから、これは私のASです:

var map:Array = [
                 [1,1,1,1,1,1,10,0,0,11,1,1,1,1,1,1,1,1,1,1],
                 [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,1],
                 [1,0,0,0,0,0,6,1,0,0,4,4,4,4,0,0,6,1,0,1],
                 [1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,0,0,0,1,6,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,0,0,0,0,6,0,0,1,0,0,1,0,0,1,0,0,1,2,1],
                 [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
                 [1,1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,3,1],
                 [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
                 ];

var stock:Array = [
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
             [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
             ];

function createMap():void{
    for (var i:int=0; i<20; i++){                               
        for (var j:int=0; j<15; j++){                           

            var T:int = 32
            var dT:int = T*.5
            var f:int = map[j][i]

            if(f>0) {
                var t:Block = new Block()
                t.x= i*T;       
                t.y= j*T;       
                t.gotoAndStop(f)        
                grid.addChild(t)
            }
        }
    }
}

var grid:MovieClip = new MovieClip();   

addChild(grid);

createMap();

stage.addEventListener(KeyboardEvent.KEY_DOWN, pushin);
stage.addEventListener(KeyboardEvent.KEY_UP, pushout);      

var right:Boolean=false;
var left:Boolean=false;
var up:Boolean=false;
var down:Boolean=false;

var lateral:Boolean = false;            
var saute:Boolean = false ;             
var none:Boolean = true                 

function paramMap():void {

    grid.sens = int(right)-int(left);           
    grid.up = int(up)-int(down)             
    grid.jump = -int(up)*11                 
    none = !right && !left && !up && !down  
    lateral = right || left;                        



function movingGrid():void{

    var L:int                                                               
    var C:int                                                               
    var Ls:int                                                              
    var Cs:int                                                              
    var A:Object
    var B:Object
    var Y:Number
    var P:Array

    with(grid){

        x += vit*sens;

        L =  y/T;
        C =  x/T;
        Ls = (y+T-1)/T;         
        Cs = (x+vit*sens)/T;

        P =  checkLateral(grid,L,Cs,vit*2,(y-dT)/T)

        L =  P[0]
        Cs = P[1]
        A =  stock[L][C]
        B =  stock[Ls][C]
        Y =  (L-1)*T    

        y += gravite; 

        if (gravite++>T) gravite=T
    }
}


}

function pushin(event:KeyboardEvent):void {
    if (event.keyCode == 38) up = true; 
    if (event.keyCode == 40) down = true;
    if (event.keyCode == 39) right = true;
    if (event.keyCode == 37) left = true;
}

function pushout(event:KeyboardEvent):void {
    if (event.keyCode == 38) up = false;
    if (event.keyCode == 40) down = false;              
    if (event.keyCode == 39) right = false;             
    if (event.keyCode == 37) left = false;              
}

ありがとうございました !

4

1 に答える 1

0

現在、いくつかの問題があります。

  • paramMapそしてその内部関数movingGridは誰にも呼び出されません。それらをイベントリスナーにフックするENTER_FRAMEか、ユーザーがキーを押したときに呼び出すことができます。

  • vitとのT属性はgridコードのこの部分にないため、ReferenceErrorテストすると がスローされます。についても同様checkLateralです。

これらの問題が解決されると、グリッド オブジェクトは正しく移動します。しかし、これは空のムービークリップであるため、実際にはまだ見ることができません。可視の子を追加するか、既存のオブジェクトを移動する必要があります。削除されたコードは次のとおりです。正しくgrid左右に移動します。

var grid:MovieClip = new MovieClip();

addChild(grid);

stage.addEventListener(KeyboardEvent.KEY_DOWN, pushin);
stage.addEventListener(KeyboardEvent.KEY_UP, pushout);

var right:Boolean = false;
var left:Boolean = false;
var up:Boolean = false;
var down:Boolean = false;

var lateral:Boolean = false;
var saute:Boolean = false;
var none:Boolean = true;

function paramMap():void
{

    grid.sens = int(right) - int(left);
    grid.up = int(up) - int(down);
    grid.jump =  -  int(up) * 11;
    none = ! right && ! left && ! up && ! down;
    lateral = right || left;


    var L:int;
    var C:int;
    var Ls:int;
    var Cs:int;
    var A:Object;
    var B:Object;
    var Y:Number;
    var P:Array;

    with (grid)
    {
        x +=  sens;
        L = y;
        C = x;
        Ls = (y - 1);
        Cs = (x + sens);
    }
}



function pushin(event:KeyboardEvent):void
{
    if (event.keyCode == 38)
    {
        up = true;
    }
    if (event.keyCode == 40)
    {
        down = true;
    }
    if (event.keyCode == 39)
    {
        right = true;
    }
    if (event.keyCode == 37)
    {
        left = true;
    }

    paramMap();
    trace(grid.x, grid.y);
}

function pushout(event:KeyboardEvent):void
{
    if (event.keyCode == 38)
    {
        up = false;
    }
    if (event.keyCode == 40)
    {
        down = false;
    }
    if (event.keyCode == 39)
    {
        right = false;
    }
    if (event.keyCode == 37)
    {
        left = false;
    }
}
于 2012-11-20T23:14:26.093 に答える