文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | firefox | WPS | 杀毒软件 | Picasa
清风网络
首 页 软件下载 网络学院 数码学院
QQ 电脑入门 游戏 操作系统 图形图像 办公软件 媒体动画 精文荟萃 常用软件 网页编程 技术开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络学院媒体动画FlashFlash贪吃蛇游戏AS代码翻译
精品推荐
特别推荐
·由浅入深学习Flash制作高射炮游戏
·由浅入深学习Flash制作高射炮游戏(续)
·遮照及文字遮照的几个概念和事例
·创建一个实用Flash站点的十大技巧
·Flash动画制作实例:小野人玩摇滚
·Flash技术在电子杂志设计制作应用
·用js+flash实现网页中复制数据功能
·教你如何去掉网页上的Flash动画虚线框
·让Flash动画适应任何分辨率的网页
·基础:flash9.ocx 加载错误解决方法
·Flash AS基础精典教程
·Flash AS教程之四 动态文本的编写以及外部文本的载入
·flash载入外部文本设置颜色的问题
·Flash制作漂亮的三重卷动相册特效动画
·关于网页中Flash弹出网页窗口的详细讲解
·用FLASH遮罩效果做图片切换效果
·实例技巧:Flash与HTML实现交互的实例
·Macromedia Flex 教程: Flex入门教程
·高级游戏制作:Flash制作物体弹跳电脑游戏
·技巧:用Flash制作动画的经典问题问答
热点TOP10
·FLASH制作一个可以伸缩的导航条
·flash声音特效实例--架子鼓(图)
·由浅入深学习Flash制作高射炮游戏
·Flash动画制作实例:小野人玩摇滚
·Flash 图片轮换效果
·高级游戏制作:Flash制作物体弹跳电脑游戏
·用FLASH遮罩效果做图片切换效果
·将数码照片做成自动放映的Flash
·用Flash MX模板制作幻灯片效果
·Flash教程:制作随机画圆弧动画
·轻松做出精美3D效果 浅析Flash 3D动画制作
·Flash遮罩特效实例--放大镜(图)
·Photoshop 7.0制作一杯热茶
·Macromedia Flex 教程: Flex入门教程
·Flash联合粒子特效软件打造超酷浪漫动画特效
·Flash制作漂亮的三重卷动相册特效动画
·精彩推荐:全Flash网站制作实例
·Flash8 字体特效
·Flash AS基础精典教程
·Flash心形按钮

Flash贪吃蛇游戏AS代码翻译

日期:2008年1月24日 作者: 查看:[大字体 中字体 小字体]


今天翻译了一段经典的贪吃蛇代码,译后感觉还有很多地方不太妥当,很多不妥的地方希望大家多指教

原文:

Word-WRAP: break-word" bgColor=#fdfddf>//--- Flash MX Snake Game 1Kb by Strille. Version 2.2, 746 bytes
//--- Paste this code on frame 1 and set scene size to 512x280 and Frame Rate to 16
//--- The code is not written with speed in mind, only small file size. Not that it is slow :-)
createTextField("t", 1, 1, 255, 511, 32); // create a text field to write score and instrUCtions
t.text = "Snake Game\t-\tPress SPACE"; // show start text
beginFill(0xeeeeee); lineStyle(1); lineTo(511, 0); lineTo(511, 256); lineTo(0, 256); endFill(); // draw background with border
Key.addListener(t); // use an existing object as key listener (we don't waste bytes by creating a new object)
t.onKeyDown = function() { // define an anonymous method to execute when a key is pressed
    c = Key.getCode()-37; // get key code (c is a variable used "locally" several times)
    if (!(c>>2)) { // arrow keys pressed (c = 0, 1, 2 or 3)
        if (c != q[0]) // only add to the queue if it is a new direction
            q.unshift(c);
        return; // save the turn in the queue and exit method
    }
    // SPACE or another key other than an arrow key has been pressed
    x = 32*8 + 32*520; // snake start pos (left and right side of + can be viewed as x and y coord
    q = []; // a queue to store key presses (so that x number of key presses during one frame are spread over x number of frames)
    m = []; // create an array to store food pos and snake
    createEmptyMovieClip("s", w=0); // create MC to store the snake and the food MC and reset snake counter(w)
    e = 2*(m[x-520] = 2*(r=1)); // set erase counter (e) to 4, set current direction (r) to up (1) and set food on the position the snake will be over the first time to place food
    onEnterFrame = function () { // MAIN function
        c = q.pop(); // pick the next turn in the queue (may be undefined if queue is empty)
        if (c%2 != r%2) // and check that it is not undefined and not a 180 degree turn (annoying to be able to turn into the snake with one key press)
            if (c != undefined)
                r = c; // change current direction to the new value
        x += [-1, -65, 1, 65][r]*8; // move the snake to a new x position (-1 = left, -65 = up, 1 = right, 65 = down)
            lineTo(-7, 0); lineTo(-7, -7); lineTo(0, -7); endFill(); // draw a square
        }
        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 Game\t-\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;
            // 改变当前方向为新的方向
        x += [-1, -65, 1, 65][r]*8;
       // 移动蛇到一个新的X位置 (-1 = left, -65 = up, 1 = right, 65 = down)
        }
        e++;
       // 将蛇的擦除计数器加一
    }
}

(出处:http://www.viphot.com)






上一篇:网页设计从业者必看的职业规划

下一篇:伪装下载器使杀软失效下载病毒

Flash贪吃蛇游戏AS代码翻译 相关文章:
·RedHat linux 8.0下内核编译步骤和说明
·各领域下最好的一些免费软件(翻译)
·免费在线翻译网
·深入解析最强Flash反编译工具
·在线翻译!近百个免费在线翻译网站(值得收藏)
·VMware中Linux内核2.6.14.4编译全过程
·Linux 内核编译 全功略
·免费英语在线翻译
·在线翻译谁更厉害——四大流行系统对比
·一网打尽网页在线即时翻译
Flash贪吃蛇游戏AS代码翻译 相关软件:
·金山快译 V2007绿色精简试用版
·破译圣经
·汉译世界学术名著丛书(德国卷)V1.0
·金山快译 2003 专业版
·金山快译 2005专业版
·Dr.eye 译典通 v8.0 (豪华版)
·英语高级口译资格证书考试口语教程
·06《译林》小说全编
·Dr.eye 译典通 v8.0 (专业版)
·《战国策》译析

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.viphot.com
| 帮助(?) | 版权声明 | 友情连接 | 关于我们 | 信息发布
Copyright 2007 www.viphot.com All Rights Reserved. 鄂ICP备05000083号Powered by:vipcn