当前位置: 首页 > 图文教程 > Flash动画 > Flash动画制作 > 高级游戏制作:Flash制作物体弹跳电脑游戏

Flash动画制作
Flash5键盘鼠标应用(二)
Freehand和Flash的结合应用(4)
Flash5 有声音的三眼狼(二)
Freehand和Flash的结合应用(7)
Freehand和Flash的结合应用(10)
Freehand和Flash的结合应用(12)
Flash5 位移操作(二)
Flash5制作水波倒影效果(二)
Flash5任意两点间随机画线(三)
Flash 神奇遮罩之原理篇(3)
Flash 神奇遮罩之动态篇
Flash 神奇遮罩之图片篇(1)
Flash MX 视频导入功能详解(5)
利用Flash MX模板制作XML动态菜单(1)
用动作脚本动态创建和控制文本框 (6)
FW MX和Flash MX的亲密合作(2)
FW MX和Flash MX的亲密合作(5)
Flash中音量和左右声道平衡的控制(2)
Flash MX的AS绘图和时间控制 下
Flash5 有声音的三眼狼(四)

Flash动画制作 中的 高级游戏制作:Flash制作物体弹跳电脑游戏


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-22   浏览: 112 ::
收藏到网摘: n/a

  Flash制作物体弹跳电脑游戏,这是一种背景不动的一个物体可以弹跳,可以左右走动的小游戏。比较基础的游戏。在文章的最后提供所有演示的Flash源文件。

看不到动画效果的朋友请去这里观看:http://bbs.ruanchen.com/"/upload/tech/20091121/20091121180433_5b8add2a5d98b1a652ea7fd72d942dac.gif">

  首先制作两个电影剪辑一个是背景,绘制一个矩形小块来当背景。加入AS为:stop(),让它开始就停止。

  另外一个是运动的物体,给大家截图如下。

回到主场景,我们用Actionscript来实现其它效果。在主场景的第一帧直接加入下面代码: 

xspeed = 0;
yspeed = 0;
max_yspeed = 16;
gravity = 1;
walk_speed = 4;
level = new Array();
_root.createEmptyMovieClip("lev", _root.getNextHighestDepth());
level[0] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
level[1] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[2] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[3] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[4] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[5] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1);
level[6] = new Array(1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[7] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[8] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[9] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[10] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[11] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[12] = new Array(1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[13] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
level[14] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
for (y=0; y<=14; y++) {
 for (x=0; x<=24; x++) {
  if (level[y][x] != 0) {
   place_brick = lev.attachMovie("block", "block_"+lev.getNextHighestDepth(), lev.getNextHighestDepth(), {_x:x*20+10, _y:y*20+10});
   place_brick.gotoAndStop(level[y][x]);
  }
 }
}
_root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:40, _y:40});
player.onEnterFrame = function() {
 yspeed += gravity;
 if (yspeed>max_yspeed) {
  yspeed = max_yspeed;
 }
 if (Key.isDown(Key.LEFT)) {
  xspeed = -walk_speed;
 }
 if (Key.isDown(Key.RIGHT)) {
  xspeed = walk_speed;
 }
 while (_root.lev.hitTest(this._x, this._y+this._height/2-1+yspeed, true)) {
  yspeed--;
 }
 while (_root.lev.hitTest(this._x-this._width/2+1+xspeed, this._y, true)) {
  xspeed++;
 }
 while (_root.lev.hitTest(this._x+this._width/2-1+xspeed, this._y, true)) {
  xspeed--;
 }
 this._y += yspeed;
 this._x += xspeed;
 xspeed = 0;
};

  上面代码实现的效果是会出现一幅不动的背景。效果如下。