点击这里给我发消息 点击这里给我发消息
首页 > 行业资讯 > flash>详细内容

关于《推箱子》游戏用flash实现的关键技术

添加时间:2010-1-5
    相关阅读: 技术 程序 flash
关于推箱子游戏很多地方都有,尤其是手机游戏。本人是非常想把这个游戏移植到flash中,但是有些关键技术还是没有摸到思路。



这是游戏中某一关的示意图:
按此在新窗口浏览图片

首先要包含:箱子、推箱子者、箱子可移动的区域、箱子要到达的目的地,这几个基本要素。

我觉得关键要解决的几点就是:
1.在程序中描述可移动区域的边界,并判断箱子和推动者是否已到达了边界。
2.判断推箱子者是否已经碰到了箱子。
3.使推箱子者移动的同时让挨着它的箱子一起移动(完成推动效果)。
4.当箱子被推到了指定地点时和再次被推离指定地点时要做出响应(全部到位是即过关)。
5.记录操作者前三步操作所移动的目标坐标,以供玩家可以及时撤销前一次失误的操作。


==本人总结了实现的关键技术就是数组地图问题==

[布局示意图]
按此在新窗口浏览图片
[至于那些墙和箱子等等可以任意画]

首先,在游戏开始时在一关键帧中书写一下代码:

// 定义变量
// 已到达目标数、步数、分数、时间、过关需要到位的箱子数、关数
onit = 0;
step = 0;
time = 60;
win = 3;
guan = 1;
// 主角所在的数组地图位置
mx = 2;
my = 1;
// 3个箱子分别所在的数组地图位置
// 箱子排列顺序按照:先上后下、先左后右
b1x = 3;
b1y = 2;
b2x = 2;
b2y = 5;
b3x = 5;
b3y = 6;
// 设置数组地图(0 空、1 墙、2 目的地、3 箱子、4 已经就位的箱子)
// 数组地图排列规则:a[位于第几列][位于第几行]!(靠!tmd和常理有些区别,节选自《网易动画站》2001年作品,这帮变态!)
// 创建二维数组
a = new Array();
i = 0;
while (7>=i) {
   a[i] = new Array("0", "0", "0", "0", "0", "0", "0", "0");
   i++;
}
// 勾勒地图边界
i = 0;
while (7>=i) {
   a[i][0] = "1";
   a[i][7] = "1";
   a[0][i] = "1";
   a[7][i] = "1";
   i++;
}
// 描绘地图形态(0 空、1 墙、2 目的地、3 箱子、4 已经就位的箱子)
a[1][1] = "1";
a[1][2] = "1";
a[1][3] = "1";
a[1][4] = "2";
a[1][5] = "2";
a[1][6] = "2";
a[2][1] = "0";
a[2][2] = "0";
a[2][3] = "1";
a[2][4] = "1";
a[2][5] = "3";
a[2][6] = "0";
a[3][1] = "0";
a[3][2] = "3";
a[3][3] = "0";
a[3][4] = "0";
a[3][5] = "0";
a[3][6] = "0";
a[4][1] = "1";
a[4][2] = "0";
a[4][3] = "1";
a[4][4] = "1";
a[4][5] = "0";
a[4][6] = "0";
a[5][1] = "1";
a[5][2] = "0";
a[5][3] = "0";
a[5][4] = "0";
a[5][5] = "1";
a[5][6] = "3";
a[6][1] = "1";
a[6][2] = "1";
a[6][3] = "0";
a[6][4] = "0";
a[6][5] = "0";
a[6][6] = "0";
man_x = getProperty(man, _x);
man_y = getProperty(man, _y);
box1_x = getProperty(box1, _x);
box1_y = getProperty(box1, _y);
box2_x = getProperty(box2, _x);
box2_y = getProperty(box2, _y);
box3_x = getProperty(box3, _x);
box3_y = getProperty(box3, _y);
好,至此大功告成,剩下的就是添加四个按钮,用来监测按下“上、下、左、右”时根据不同状态做出判断、移动就OK了。

例如按下“右”键后的处理流程应该是:



 

on (keyPress "<Right>") {
                      if ((a[mx + 1][my] == "0") || (a[mx + 1][my] == "2")) {
                      setProperty("man", _x , getProperty(man, _x) + 30);
                      mx = mx + 1;
                      step = step + 1;
          } else if (a[mx + 1][my] == "3") {
                      if (a[mx + 2][my] == "0") {
                                  a[mx + 1][my] = "0";
                                  a[mx + 2][my] = "3";
                                  setProperty("man", _x , getProperty(man, _x) + 30);
                                  mx = mx + 1;
                                  if ((b1x == mx) && (b1y == my)) {
                                              setProperty("box1", _x , getProperty(box1, _x) + 30);
                                              b1x = b1x + 1;
                                  }
                                  if ((b2x == mx) && (b2y == my)) {
                                              setProperty("box2", _x , getProperty(box2, _x) + 30);
                                              b2x = b2x + 1;
                                  }
                                  if ((b3x == mx) && (b3y == my)) {
                                              setProperty("box3", _x , getProperty(box3, _x) + 30);
                                              b3x = b3x + 1;
                                  }
                                  step = step + 1;
                      } else if (a[mx + 2][my] == "2") {
                                  a[mx + 1][my] = "0";
                                  a[mx + 2][my] = "4";
                                  setProperty("man", _x , getProperty(man, _x) + 30);
                                  mx = mx + 1;
                                  if ((b1x == mx) && (b1y == my)) {
                                              setProperty("box1", _x , getProperty(box1, _x) + 30);
                                              b1x = b1x + 1;
                                  }
                                  if ((b2x == mx) && (b2y == my)) {
                                              setProperty("box2", _x , getProperty(box2, _x) + 30);
                                              b2x = b2x + 1;
                                  }
                                  if ((b3x == mx) && (b3y == my)) {
                                              setProperty("box3", _x , getProperty(box3, _x) + 30);
                                              b3x = b3x + 1;
                                  }
                                  onit = onit + 1;
                                  step = step + 1;
                      }
          } else if (a[mx + 1][my] == "4") {
                      if (a[mx + 2][my] == "0") {
                                  a[mx + 1][my] = "2";
                                  a[mx + 2][my] = "3";
                                  setProperty("man", _x , getProperty(man, _x) + 30);
                                  mx = mx + 1;
                                  if ((b1x == mx) && (b1y == my)) {
                                              setProperty("box1", _x , getProperty(box1, _x) + 30);
                                              b1x = b1x + 1;
                                  }
                                  if ((b2x == mx) && (b2y == my)) {
                                              setProperty("box2", _x , getProperty(box2, _x) + 30);
                                              b2x = b2x + 1;
                                  }
                                  if ((b3x == mx) && (b3y == my)) {
                                              setProperty("box3", _x , getProperty(box3, _x) + 30);
                                              b3x = b3x + 1;
                                  }
                                  onit = onit - 1;
                                  step = step + 1;
                      } else if (a[mx + 2][my] == "2") {
                                  a[mx + 1][my] = "2";
                                  a[mx + 2][my] = "4";
                                  setProperty("man", _x , getProperty(man, _x) + 30);
                                  mx = mx + 1;
                                  if ((b1x == mx) && (b1y == my)) {
                                              setProperty("box1", _x , getProperty(box1, _x) + 30);
                                              b1x = b1x + 1;
                                  }
                                  if ((b2x == mx) && (b2y == my)) {
                                              setProperty("box2", _x , getProperty(box2, _x) + 30);
                                              b2x = b2x + 1;
                                  }
                                  if ((b3x == mx) && (b3y == my)) {
                                              setProperty("box3", _x , getProperty(box3, _x) + 30);
                                              b3x = b3x + 1;
                                  }
                                  step = step + 1;
                      }
          }
}

   

至此,基本功能就可以实现了,至于怎么控制过关,和过了关的动画效果就随便啦。
本文作者:
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册