新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 网络学院 > 媒体动画 > Flash教程 > 正文:Flash AS 制作生化危机游戏的简单尝试

Flash AS 制作生化危机游戏的简单尝试

新客网 XKER.COM 2007-10-17 来源:网页教学网 闪电儿 收藏本文

这个教程先给大家做一个游戏中的场景,只是简单的尝试着做做!

新客网友情提醒:由于该教程中演示Flash动画较多,所以打开本页后速度会慢些甚至影响浏览器!请关闭其它所有程序尝试!在教程的最后提供了所有演示的Fla源文件。

首先布置地图,并且做一个角色。

Flash AS 制作生化危机游戏的简单尝试

引入一幅地图当作背景,转换为元件。

Flash AS 制作生化危机游戏的简单尝试

角色的建立

Flash AS 制作生化危机游戏的简单尝试

做好了上面的就可以了!下面我们开始添加代码。回到第一帧,添加如下代码。

walk_speed = 3;
radius = 8;
_root.attachMovie("ground", "ground", _root.getNextHighestDepth());
_root.attachMovie("environment", "environment", _root.getNextHighestDepth());
_root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:250, _y:200});
_root.createEmptyMovieClip("light", _root.getNextHighestDepth());
player.onEnterFrame = function() {
 if (Key.isDown(Key.LEFT)) {
  this._x -= walk_speed;
 }
 if (Key.isDown(Key.RIGHT)) {
  this._x += walk_speed;
 }
 if (Key.isDown(Key.UP)) {
  this._y -= walk_speed;
 }
 if (Key.isDown(Key.DOWN)) {
  this._y += walk_speed;
 }
 while (_root.environment.hitTest(this._x, this._y+radius, true)) {
  this._y--;
 }
 while (_root.environment.hitTest(this._x, this._y-radius, true)) {
  this._y++;
 }
 while (_root.environment.hitTest(this._x-radius, this._y, true)) {
  this._x++;
 }
 while (_root.environment.hitTest(this._x+radius, this._y, true)) {
  this._x--;
 }
 dist_x = this._x-_root._xmouse;
 dist_y = this._y-_root._ymouse;
 angle = -Math.atan2(dist_x, dist_y);
 this._rotation = angle/(Math.PI/180);
};

测试效果,这时有地图和角色了。

我们再继续修改代码。

torch_power = 100;
torch_step = 100;
torch_angle = 60;
torch_angle_step = 20;
walk_speed = 3;
radius = 8;
_root.attachMovie("ground", "ground", _root.getNextHighestDepth());
_root.attachMovie("environment", "environment", _root.getNextHighestDepth());
_root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:250, _y:200});
_root.createEmptyMovieClip("light", _root.getNextHighestDepth());
player.onEnterFrame = function() {
 if (Key.isDown(Key.LEFT)) {
  this._x -= walk_speed;
 }
 if (Key.isDown(Key.RIGHT)) {
  this._x += walk_speed;
 }
 if (Key.isDown(Key.UP)) {
  this._y -= walk_speed;
 }
 if (Key.isDown(Key.DOWN)) {
  this._y += walk_speed;
 }
 while (_root.environment.hitTest(this._x, this._y+radius, true)) {
  this._y--;
 }
 while (_root.environment.hitTest(this._x, this._y-radius, true)) {
  this._y++;
 }
 while (_root.environment.hitTest(this._x-radius, this._y, true)) {
  this._x++;
 }
 while (_root.environment.hitTest(this._x+radius, this._y, true)) {
  this._x--;
 }
 dist_x = this._x-_root._xmouse;
 dist_y = this._y-_root._ymouse;
 angle = -Math.atan2(dist_x, dist_y);
 this._rotation = angle/(Math.PI/180);
 light.clear();
 light.lineStyle(1, 0xffffff);
 for (x=0; x<=torch_angle; x += (torch_angle/torch_angle_step)) {
  light.moveTo(this._x, this._y);
  ray_angle = angle/(Math.PI/180)-90-(torch_angle/2)+x;
  ray_angle = ray_angle*(Math.PI/180);
  light.lineTo(this._x+(torch_power)*Math.cos(ray_angle), this._y+(torch_power)*Math.sin(ray_angle));
  light.lineTo(this._x, this._y);
 }
};

共3页: 上一页 [1] [2] [3] 下一页
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐