Flash贪吃蛇游戏AS代码翻译

2019-10-08 18:23:14丽君

}
m[x] = 1; // set current pos as "occupied" by a snake block
if (m[x] == 3) { // check if there is a food block on the new pos
t.text = "Score: " (w-(e-=5)-2)*2; // delay erase counter with 5 (the snake will grow 5 blocks each time), calculate and type score ( 10p for a food block)
do {} while (m[c = (s[0]._x = 8 random(64)*8) (s[0]._y = 8 random(32)*8)*65]); // pick a free spot to place the food, save that number, place the food MC
m[c] = 2; // set the position picked on the line above to 2
}
if (e) { // if not food MC (s[0]) then erase last snake MC and entry in array m
c = s[e]; // get last MC
delete m[c._x 65*c._y]; removeMovieClip(c); // delete the value in the array m and delete the MC
}
e ; // increase erase snake counter
}
}
翻译:
//--- Flash MX 贪吃蛇游戏(1Kb) 制作Strille. 版本 2.2, 共计 746 字节
//--- 复制以下代码在主场景的第一帧场景大小为 512x280 , FPS 16
createTextField("t", 1, 1, 255, 511, 32);
// create a text field to write score and instructions
// 创建一个文本框用于输出成绩和指示
t.text = "Snake Gamet-tPress SPACE";
// 显示开始信息
beginFill(0xeeeeee); lineStyle(1); lineTo(511, 0); lineTo(511, 256); lineTo(0, 256); endFill();
// 沿边框绘制背景
Key.addListener(t);
// 使用一个已存在的Object 作键盘帧听 (就样就不用再创建新Obejct,从而节约了空间)
t.onKeyDown = function() {
// 当键盘按下后,去执行自定义的这个方法
c = Key.getCode()-37;
// 获得按键的ASCII码 (变量 c 每次获取相对的ASCII码)
if (!(c>>2)) {
// 方向键的表示 (c = 0, 1, 2 or 3)
if (c != q[0])
// 只将新的方向键存入队列 q
q.unshift(c);
return;
// 在队列中保存,并结束该方法(函数)
}
// 空格或其它键不同于按下的方向键
x = 32*8 32*520;
// 蛇的起点坐标( 左边 右边:可被视为 x、y 坐标)
q = [];
// 用于存储按键的队列(因此改变在一帧中的X坐标对于所有帧中的X坐标都起作用)
m = [];
// 创建一个数组用于存储食物的坐标和蛇
createEmptyMovieClip("s", w=0);
// 创建一个空影片用于存储蛇和食物的影片剪辑,并重置蛇的计数器(w)
e = 2*(m[x-520] = 2*(r=1));
// 设置擦除计数器(e) to 4, 设置当前方向(r)为向上(1),当蛇经过食物后立即设置食物位置为当前设置的位置
onEnterFrame = function () {
// 主函数
c = q.pop();
// 在队列中提取出下一轮变换(当队列为空时,提取数是undefined的)
if (c%2 != r%2)
// 检查其不属于undefined和180度旋转(避免任意按下一个键后就改变蛇的方向)
if (c != undefined)
r = c;
// 改变当前方向为新的方向