Flash制作物体弹跳电脑游戏,这是一种背景不动的一个物体可以弹跳,可以左右走动的小游戏。比较基础的游戏。在文章的最后提供所有演示的Flash源文件。
看不到动画效果的朋友请去这里观看:http://bbs./thread-99274-1-1.html
启动Flash,首先修改文档属性。
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/flash/)首先制作两个电影剪辑一个是背景,绘制一个矩形小块来当背景。加入AS为:stop(),让它开始就停止。
另外一个是运动的物体,给大家截图如下。
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/flash/)回到主场景,我们用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 Am.tulaoshi.comrray(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 (yspeedmax_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;
};
[1] 200806/12956_2.html'>[2] 200806/12956_2.html'>下一页
上面代码实现的效果是会出现一幅不动的背景。效果如下。