快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

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

  效果如下:

« Full Screen »

点击这里下载源文件

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

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;//设初始位置
onEnter

Frame = 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();

//我还制了一个专门画地图的文件,可以输入数组的值。
愿共同交流,提宝贵意见。因时间关系,地图制作简朴了。




返回类别: Flash教程
上一教程: Flash MX 2004实例制作视频教程:《火影忍者》动画片头制作(5)
下一教程: 动感水珠,Flash制作的步骤

您可以阅读与"在Flash中用二维数组建地图的迷宫游戏"相关的教程:
· 在Flash中用数组建地图的贪吃蛇游戏
· Flash游戏制作:点击可弹动的小球
· Flash游戏开发系列一:游戏中的敌人(2)
· Flash制作出色的空战游戏
· 精品热门FLASH游戏作品
    微笑服务 优质保证 索取样品