用户名: 密码: 验证码: QQ--程序群:31736530 动画群:38836599
闪无忧
 
首 页 业界新闻 业界杂谈 Flash教程 Flash源码 Flash图书 Flash酷站 Flex & AIR 供求信息
   本栏目通告:   有意向写收费精品教程的朋友,请联系本站合作
当前位置 :首页>flash教程>Flash应用开发>列表

俄罗斯方块(游戏制作)

[来源:闪客无忧 | 作者:闪灵凶猛 | 时间:2008-03-28 | 点击:  | 收藏本文  【 】]

这里,主要为游戏定义几个函数,它们共同实现了方块游戏的基本功能。其中,函数hitothers用于判断下落的方块是否与已经落下的方块接触,如果接触,就需要停止下落。函数attachsquares用在当方块停止下落时将库中的“square”元件附加到适当的位置。函数judgescore判断方块停止下落并附加小方块后是否得分,它是通过分析与方块对应位置的数组元素的值完成判断的。
(2)选中主时间轴的第2帧,在其“动作”面板中添加如下代码:

stop();

_root.restart.removeMovieClip();
_root.currentshape = 0;
_root.iii = 1;
_root.fall = true;
_root.wait = 0;
_root.v = 6-Number(_root.top.v);
_root.hit = false;
_root.top.duplicateMovieClip("top", 99999);
_root.top.score = 0;
_root.ran1 = random(7)+1;
_root.box = new Array();
for (var i = 0; i<=29; i++) {
_root.box[i] = new Array();
for (var j = 0; j<=15; j++) {
_root.box[i][j] = 0;
}
}
Key.addListener(_root);
_root.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
_root.currentmove._x -= 10;
hitothers(_root.currentmove._x, _root.currentmove._y, _root.ran, _root.currentmove._rotation);
if (_root.currentmove.hitTest(_root.left) || _root.hit == true) {
_root.currentmove._x += 10;
}
} else if (Key.getCode() == Key.RIGHT) {
_root.currentmove._x += 10;
hitothers(_root.currentmove._x, _root.currentmove._y, _root.ran, _root.currentmove._rotation);
if (_root.currentmove.hitTest(_root.right) || _root.hit == true) {
_root.currentmove._x -= 10;
}
} else if (Key.getCode() == Key.DOWN) {
_root.fall = false;
_root.currentmove._y += 10;
hitothers(_root.currentmove._x, _root.currentmove._y, _root.ran, _root.currentmove._rotation);
if (_root.currentmove.hitTest(_root.base) || _root.hit == true) {
_root.currentmove._y -= 10;
attachsquares(_root.currentmove._x, _root.currentmove._y, _root.ran, _root.currentmove._rotation);
removeMovieClip(_root.currentmove);
_root.currentshape = 0;
}
_root.fall = true;
} else if (Key.getCode() == Key.UP) {
_root.currentmove._rotation += 90;
hitothers(_root.currentmove._x, _root.currentmove._y, _root.ran, _root.currentmove._rotation);
if (_root.currentmove.hitTest(_root.right) || _root.currentmove.hitTest(_root.left) || _root.hit == true) {
_root.currentmove._rotation -= 90;
}
}
};
_root.onEnterFrame = function() {
if (_root.currentshape == 0) {
_root.ran = _root.ran1;
_root.attachMovie("shape"+_root.ran, "currentmove", 100);
_root.currentmove._x = 120;
_root.currentmove._y = 40;
_root.currentshape = _root.ran;
_root.currentmove.onEnterFrame = function() {
if (_root.fall == true) {
if (_root.wait == _root.v) {
this._y += 10;
_root.wait = 0;
} else {
_root.wait++;
}
}
};
_root.ran1 = random(7)+1;
_root.attachMovie("shape"+_root.ran1, "nextmove", 100001);
_root.nextmove._x = 200;
_root.nextmove._y = 20;
}
hitothers(_root.currentmove._x, _root.currentmove._y, _root.ran, _root.currentmove._rotation);
if ((_root.hit == true || _root.currentmove.hitTest(_root.base)) && (_root.fall == true)) {
_root.currentmove._y -= 10;
attachsquares(_root.currentmove._x, _root.currentmove._y, _root.ran, _root.currentmove._rotation);
removeMovieClip(_root.currentmove);
_root.currentshape = 0;
}
};

这一帧实现游戏的运行,通过定义事件处理函数分析键盘动作,以实现用方向键对方块进行控制。在方块下落过程,适时地调用第1帧中定义的函数,保证了游戏的严密性。

(3)双击第2帧中的“界面”元件,进入其元件层级,选中“加速”按钮,在其“动作”面板中添加如下代码:

 

on (release) {

if (_root.top.v<6) {
_root.top.v = Number(_root.top.v)+1;
}
_root.wait = 0;
_root.v = 6-Number(_root.top.v);
}

上一页 1 2 34 下一页
文章如果有错误或者缺少文件,请发邮件提交给我们
上一篇:flash游戏中动态加载地图的问题
下一篇:flash游戏组件的创建、打包和运用全过程
Tags:     制作 游戏 罗斯 _root.iii /10 _root xx-40 330-yy ._y
>>> 最新评论:(共有 0 位网友发表了评论)      查看所有评论
  发表评论
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
·本站发布内容均为客观表达作者观点,不代表闪无忧立场,请勿攻击和漫骂
·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为
  教程分类
  基础操作   动画特效
  应用开发   组件学习
  As程序   动画教程
  Flash cs3   AS 3.0
  FCS/FMS教程   Loading教程
  Flash与Web   Flash教程连载
  相关文章
·Rectangle对象在flash游戏开发中
·Flash的Socket和AMF3的研究心得
·Flash的Socket和AMF3来开发web游
·制作有视角的迷宫游戏+碰撞
·项目外包, 诚要天下FLASH有能之
·flash小游戏制作:月饼消消看
·Flash Player10功能SaveBitmap直
·面向对象法制作贪吃蛇小游戏
·flash里键盘控制人物行走的另个
·flash中图形位置的半像素渲染问
  热门文章
·Flash进度条的制作详细讲解(组图)
·flash幻灯片网页效果
·Flex 3 AdvancedDataGrid的使用(第二
·全Flash动画网站实现的基础教学
·flash水影效果字
·Flash打造简单的飘雪动画视觉特效
·FLASH+XML相册(附源码)
·超酷flash光晕移动效果
·Flash旋转拖尾文字效果的制作教程
·Flash制作大雪纷飞效果动画
·flash春雷闪电效果
关于我们 - 免责声明 - 网站地图 - 商务服务 - 联系我们 - RSS地图
©CopyRight 2006-2008, 5UFlash.COM, Inc. All Rights Reserved
鲁ICP备06034971号