精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程
返回建站学首页
导航:
建站首页 | 网站设计 | 网站开发 | 网站运营 | 网页软件 | 建站指南 | 搜索优化 | 图像处理 | 视频教程 | 书籍教程 | 建站专题
当前位置:首页>网页软件>FLASH教程>正文

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


来源:网页教学网 时间:07-10-17 点击: 点击这里收藏本文
做好了上面的就可以了!下面我们开始添加代码。回到第一帧,添加如下代码。

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);
}
};

效果如下。

9 7 3 1 2 3 4 4 8 :

  把此文章收藏到:          
广而告之
文章搜索
  • Google JZxue.Com

关于我们 | 联系我们 | 友情链接 | 网站地图
Copyright © 2005 - 2006 建站学 All rights reserved.