Flash游戏制作:点击可弹动的小球

来源:        2008-03-29 15:49:47        评论
源文件下载(zip压缩文件,6K)。 大家可以看一看一个曾经很流行的成品游戏: 《是男人就点一百下》 这个是简单的弹性效果的延伸。…
 源文件下载(zip压缩文件,6K)。

  大家可以看一看一个曾经很流行的成品游戏:《是男人就点一百下》

  这个是简单的弹性效果的延伸。主体基本全是用as来实现的。下面讲解一下制作过程。

  1. 在flash中新一个MC,在此MC上分别建三层来放圆,按钮,还有as命令。如图所示:

  在此,as命令为:

stop();


  2. 回到主场景,在第一帧上加入as命令。

_root.createEmptyMovieClip("ball", 69);

//创建一个空的MC,命名为ball

ball.lineStyle(60, 0xFFFFFF, 100);

//设定ball的线条样式为60粗,白色,alpha为100

ball.lineTo(1, 0);

//使用当前线条样式从当前绘画位置向 (x, y) 绘制线条

vars = new Array("xspeed", "yspeed", "leftedge", "rightedge", "bottomedge", "gravity", "friction", "bounce", "widthBall", "heightBall", "maxaffiche", "forceDribble", 6, 0, -30, (Stage.width)+(_root.ball._width/4), (Stage.height)+(_root.ball._width/4), 2.4, 0.982, 0.7, _root.ball._width/2, _root.ball._height/2, 10, 22);

//建立数组

for (i=0; i<(vars.length/2); i++) {
this[vars[i]] = vars[i+(vars.length/2)];
}

//初始数组的取值

//-----------------------------------------

//ball点击时,改变数组中xspeed,yspeed的值

ball.onPress = function() {
_root.xspeed -= (_root._xmouse-this._x)/2;
_root.yspeed = -_root.forceDribble;
};
//---------------------------------------

//设置ball的反弹,
ball.onEnterFrame = function() {
this._x = this._x+xspeed;
this._y = this._y+yspeed;
if (this._x+widthBall>rightedge || this._x-widthBall xspeed = -xspeed*bounce;
this._x = (this._x+widthBall>rightedge) ? (rightedge-widthBall) : (leftedge+widthBall);
}
if (this._y+heightBall>bottomedge) {
yspeed = -yspeed*bounce;
this._y = bottomedge-heightBall;
}
yspeed = (yspeed*friction)+gravity;
xspeed = xspeed*friction;
};

评论: Flash游戏制作:点击可弹动的小球


昵称  密码    匿名
热门
相关