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

王朝other·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

新年将到,在这里先向大家拜个早年,祝大家在鸡年里,flash的水平节节高。 好,现在进入正题,大家先看一下效果。

源文件下载(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;

};

注:此例仅供学习使用,请勿用于商业用途!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航