在Flash中用二维数组建地图的迷宫游戏

  • 来源: 互联网 作者: 小希   2008-03-18/09:07
  • 效果如下:

    //----------右键菜单------------------------------------

    function f1() { //右键菜单函数
    getURL("http://game.tmxk.net/flasher");
    }
    function f2() {
    gotoAndPlay(8);
    }
    var m1 = new ContextMenu(); //建新菜单
    m1.hideBuiltInItems();
    m1.customItems.push(new ContextMenuItem("我的站点", f1, true));//右键菜单项
    m1.customItems.push(new ContextMenuItem("重新开始", f2, true));
    _root.menu = m1;
    //------------------------
    var str; //用数组建地图,0表示空,也是方块能移到的地方,65表示墙
    str = [[0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 65, 65, 65, 65, 65], [65, 65, 65, 65, 65, 65, 0, 0, 0, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0, 65, 0, 65, 65, 0, 65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65], [65, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 0, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0, 65, 0, 65, 65, 0, 65, 65, 0, 65, 65, 65, 0, 0, 0, 0, 0], [65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 0, 0, 65, 65, 65, 65, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 65, 0, 65, 0, 65, 0, 0, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65], [65, 0, 65, 0, 0, 0, 0, 0, 0, 65, 0, 65, 0, 0, 0, 65, 0, 65, 0, 65, 0, 65, 65, 65, 65, 65, 0, 65, 0, 65, 0, 65, 0, 65, 0, 65, 0, 0, 0, 0, 0, 0, 0, 65, 65], [65, 0, 65, 0, 65, 65, 65, 65, 0, 65, 0, 65, 65, 65, 0, 65, 0, 65, 0, 65, 0, 0, 0, 0, 0, 0, 0, 65, 0, 65, 0, 65, 0, 65, 0, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65], [65, 0, 65, 0, 65, 65, 0, 65, 0, 65, 65, 65, 65, 65, 0, 65, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65], [0, 0, 65, 0, 0, 65, 0, 65, 0, 65, 0, 0, 65, 65, 0, 65, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65], [65, 0, 65, 0, 0, 65, 0, 65, 0, 65, 0, 0, 0, 0, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 65], [65, 0, 65, 65, 0, 65, 0, 65, 0, 65, 0, 65, 65, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 65, 0, 65, 65, 65, 65, 65, 0, 65, 0, 65, 65, 0, 65, 65], [65, 0, 65, 65, 0, 65, 0, 65, 0, 65, 0, 65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0, 0, 0, 65, 65, 0, 65, 65], [65, 0, 0, 0, 0, 65, 0, 65, 0, 65, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65], [0, 0, 65, 0, 65, 65, 0, 65, 0, 0, 0, 65, 65, 0, 65, 65, 65, 0, 0, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 0, 0, 65, 65, 65, 65, 65, 0, 0, 65, 65, 65, 0, 0, 0], [0, 65, 65, 0, 65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0], [0, 65, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 65, 65, 65, 65, 65, 0, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 65, 65], [0, 0, 0, 0, 65, 65, 65, 0, 0, 0, 0, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 65, 65, 0, 65, 0, 65, 0, 65, 65], [65, 65, 65, 0, 65, 65, 65, 65, 0, 65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 0, 0, 0, 65, 65, 0, 0, 65, 0, 65, 0, 0, 65], [65, 0, 65, 0, 0, 0, 65, 65, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 0, 65, 65, 0, 65, 65, 0, 0, 65, 0, 65], [65, 0, 65, 0, 65, 0, 65, 0, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 65, 0, 65, 65, 0, 65, 65, 65, 0, 65, 0, 65], [0, 0, 65, 0, 65, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 0, 0, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0, 65, 65, 0, 65, 0, 0, 0, 65, 0, 65], [0, 65, 65, 0, 65, 0, 65, 0, 65, 0, 0, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 65, 65, 0, 65, 65, 0, 65, 0, 65, 0, 65, 0, 65], [0, 65, 65, 0, 65, 0, 65, 0, 0, 65, 65, 0, 0, 0, 0, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 0, 0, 0, 65, 0, 0, 65, 65, 0, 65, 0, 65, 0, 65, 0, 65], [0, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 0, 65, 0, 65, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 65, 0, 0, 0, 65, 65, 65, 0, 65, 0, 65, 0, 65, 0, 65], [0, 0, 0, 0, 0, 0, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 0, 0, 65, 0, 65, 0, 65, 0, 0], [0, 65, 65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 0, 65, 65, 65, 0, 65], [0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 65, 0, 0, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 65], [0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 65, 0, 65, 65, 0, 0, 0, 65, 65, 65, 0, 65, 65, 65, 65, 0, 65, 0, 0, 0, 0, 65, 65, 65, 65, 65, 65, 0, 65], [0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 0, 65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 65, 0, 65, 0, 65, 0, 65, 65, 0, 65, 0, 0, 65, 0, 65, 0, 65], [0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 0, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 65, 0, 65, 65, 0, 65, 65, 0, 65, 0, 65, 0, 65], [0, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 65, 65, 0, 65, 65, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 65, 0, 0, 0, 65, 65, 0, 65, 65, 0, 0, 0, 65, 0, 65], [0, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 65, 65, 0, 65, 65, 0, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 65, 0, 65, 65, 0, 65, 65, 65, 0, 0, 65, 65, 65, 65, 65, 65, 0, 65], [65, 0, 0, 0, 0, 0, 65, 65, 65, 65, 0, 65, 65, 0, 65, 0, 0, 65, 65, 65, 65, 65, 0, 65, 0, 0, 0, 65, 0, 65, 65, 0, 65, 65, 0, 0, 0, 65, 65, 0, 0, 0, 0, 0, 65], [65, 0, 65, 65, 65, 0, 0, 0, 0, 0, 0, 65, 65, 0, 65, 0, 65, 65, 0, 0, 0, 65, 0, 65, 0, 65, 65, 0, 0, 65, 0, 0, 65, 65, 0, 65, 0, 65, 65, 0, 65, 65, 65, 0, 65], [65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 65, 65, 65, 65, 0, 0, 0, 65, 0, 65, 65, 0, 0, 0, 0, 65, 0, 0, 0, 65, 0, 65, 65, 0, 0, 0, 65, 0, 65], [65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 65, 65, 65, 65, 0, 0, 65, 65, 65, 0, 65, 65, 65, 65, 0, 65, 0, 65], [0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 0, 0, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 65, 0, 65], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 0, 0, 65, 65, 0, 65, 65, 0, 65, 0, 0, 65], [65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 0, 0, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 0, 0, 0, 0, 65, 65, 65, 65, 0, 65, 0, 65, 65], [65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 0, 0, 65, 65, 0, 65, 65, 65, 0, 65, 65, 65, 65, 0, 65, 65, 0, 0, 65, 65, 0, 65, 0, 65, 65, 65, 0, 65, 65, 65], [65, 65, 0, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 0, 65, 65, 65, 65, 0, 0, 0, 0, 65, 65, 65, 0, 65, 0, 65, 0, 0, 65, 0, 0, 0], [65, 65, 0, 65, 65, 65, 0, 0, 0, 0, 0, 65, 65, 0, 65, 65, 65, 0, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0], [65, 65, 0, 0, 0, 0, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 0, 0, 0, 0, 0, 65, 65, 0, 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 65, 0, 65, 65, 65, 0], [65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 0, 65, 65, 65, 0, 65, 65, 65, 0, 0, 0, 65, 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 0, 65, 0, 65, 65, 65, 0], [65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 0, 65, 0, 0, 0, 0, 0, 65, 65, 65, 0, 0, 0, 0, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0]];
    //
    adx = 0; //方块的横坐标
    ady = 0; //方块的纵坐标
    //----画边框----------------
    lineStyle(3);
    moveTo(0, 0);
    lineTo(450, 0);
    lineTo(450, 450);
    lineTo(0, 450);
    lineTo(0, 0);
    //------------填充方块----------
    for (var i = 0; i<45; i++) {
    for (var j = 0; j<45; j++) {
    if (str[i][j] != 0) {
    var num = i*45+j;
    _root.attachMovie("blue", "b"+num, num+1);
    eval("b"+num)._x = j*10;
    eval("b"+num)._y = i*10;
    }
    }
    }
    _root.attachMovie("red", "r", 2800);//在目的地画一红色块。
    eval("r")._x = 44*10;
    eval("r")._y = 44*10;
    _root.ba.duplicateMovieClip("ball", 1); //建立小方块
    ball._x = 0;
    ball._y = 0;//设初始位置
    onEnterFrame = function () { //方向控制
    if (Key.isDown(Key.UP)) {
    if (ady>0) {
    if (str[ady-1][adx] == 0) {
    ady = ady-1;
    ball._y = ball._y-10;
    }
    }
    }
    if (Key.isDown(Key.DOWN)) {
    if (ady<44) {
    if (str[ady+1][adx] == 0) {
    ady = ady+1;
    ball._y = ball._y+10;
    }
    }
    }
    if (Key.isDown(Key.RIGHT)) {
    if ((adx+1)%45 != 0) {
    if (str[ady][adx+1] == 0) {
    adx = adx+1;
    ball._x = ball._x+10;
    }
    }
    }
    if (Key.isDown(Key.LEFT)) {
    if (adx%45 != 0) {
    if (str[ady][adx-1] == 0) {
    adx = adx-1;
    ball._x = ball._x-10;
    }
    }
    }
    if (ball._x == 440 && ball._y == 440) {//结束
    delete this.onEnterFrame;
    gotoAndStop(10);
    }
    };
    stop();

    //我还制了一个专门画地图的文件,可以输入数组的值。


    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多