一个方向控制射击小游戏的代码分析!(AS1.0)
2004-12-01 01:57
453 查看
今天看到到一个小游戏,就将它分析了一下...(原文地址:http://www.gotoandplay.it/_articles/2003/10/shoot.php)
我把主要功能做了下,你可以下载程序研究研究!
准备工作:在舞台上放做一些影片剪辑!如图示
好丑,暂且容忍下,技术为先吧!
ball上面的代码是:
onClipEvent (load) {
dirRight = 1;//将来子弹的飞行方向
speed = 5;//运行速度
d = 0;//第一个子弹的影片的深度...
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
dirRight = 1;
this._xscale = 70;
this._x += speed;
} else if (Key.isDown(Key.LEFT)) {
dirRight = 0;
this._xscale = -70;
this._x -= speed;
}//基本的运动控制,不懂的可以看看我的上一篇...<运动的控制>
if (Key.isDown(Key.SPACE)) {
//trace(Key.isDown(Key.SPACE))
//按下空格键
//a是为了按键不放将不会连续的发弹...设置的一个标志位
if(!a){
d++;
bulletDepth = (d%100);//100年一个轮回哦
duplicateMovieClip(_parent.bullet, "new"+bulletDepth, bulletDepth);//复制子弹罗...
if (dirRight == 1) {
_parent["new"+bulletDepth].speed = 20;
_parent["new"+bulletDepth].stepx = 40;
}//设置子弹的方向以及stepx是在ball的前方的距离,这可以在bullet的代码中看到_root.bullet._x=_root.ball._x+stepx;
if (dirRight == 0) {
_parent["new"+bulletDepth].speed = -20;
_parent["new"+bulletDepth].stepx = -40;
}//同上
a = true;//标志位哦,按一下就停一下}
} else {
a = false;//同样标志位!
}
}
bullet(子弹的代码)
onClipEvent (load) {
manNum = 4;//一共几个人
if (_name != bullet) {
this._x = _root.ball._x+stepx*2;
this._y = _root.ball._y;//在ball中设置的数据哦!
mySound=new Sound();
mySound.attachSound("zap");//加载声音
}
}
onClipEvent (enterFrame) {
if (_name != bullet) {
this._x += speed;
}
//赋予子弹速度!
for (i=0; i<manNum; i++) {
if (_root["man"+i].hitTest(this)) {
_root["man"+i].gotoAndStop(2);
mySound.start();
removeMovieClip(this);
//检测碰撞,假如是碰撞的话,人当然是牺牲了罗,跳到第二帧;
//人的影片剪辑有两帧,第二帧为空(stop)
}
}
}
人的代码:没一帧一个stop();
第二帧为空就哦!
然后按qq发送键,看是不是可以了....
还没发现哪里可以放源代码的,要的话,可以给我说一声,zhonglixunni@163.com
我把主要功能做了下,你可以下载程序研究研究!
准备工作:在舞台上放做一些影片剪辑!如图示
好丑,暂且容忍下,技术为先吧!
ball上面的代码是:
onClipEvent (load) {
dirRight = 1;//将来子弹的飞行方向
speed = 5;//运行速度
d = 0;//第一个子弹的影片的深度...
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
dirRight = 1;
this._xscale = 70;
this._x += speed;
} else if (Key.isDown(Key.LEFT)) {
dirRight = 0;
this._xscale = -70;
this._x -= speed;
}//基本的运动控制,不懂的可以看看我的上一篇...<运动的控制>
if (Key.isDown(Key.SPACE)) {
//trace(Key.isDown(Key.SPACE))
//按下空格键
//a是为了按键不放将不会连续的发弹...设置的一个标志位
if(!a){
d++;
bulletDepth = (d%100);//100年一个轮回哦
duplicateMovieClip(_parent.bullet, "new"+bulletDepth, bulletDepth);//复制子弹罗...
if (dirRight == 1) {
_parent["new"+bulletDepth].speed = 20;
_parent["new"+bulletDepth].stepx = 40;
}//设置子弹的方向以及stepx是在ball的前方的距离,这可以在bullet的代码中看到_root.bullet._x=_root.ball._x+stepx;
if (dirRight == 0) {
_parent["new"+bulletDepth].speed = -20;
_parent["new"+bulletDepth].stepx = -40;
}//同上
a = true;//标志位哦,按一下就停一下}
} else {
a = false;//同样标志位!
}
}
bullet(子弹的代码)
onClipEvent (load) {
manNum = 4;//一共几个人
if (_name != bullet) {
this._x = _root.ball._x+stepx*2;
this._y = _root.ball._y;//在ball中设置的数据哦!
mySound=new Sound();
mySound.attachSound("zap");//加载声音
}
}
onClipEvent (enterFrame) {
if (_name != bullet) {
this._x += speed;
}
//赋予子弹速度!
for (i=0; i<manNum; i++) {
if (_root["man"+i].hitTest(this)) {
_root["man"+i].gotoAndStop(2);
mySound.start();
removeMovieClip(this);
//检测碰撞,假如是碰撞的话,人当然是牺牲了罗,跳到第二帧;
//人的影片剪辑有两帧,第二帧为空(stop)
}
}
}
人的代码:没一帧一个stop();
第二帧为空就哦!
然后按qq发送键,看是不是可以了....
还没发现哪里可以放源代码的,要的话,可以给我说一声,zhonglixunni@163.com
相关文章推荐
- QQ商业化,如何实现从0到1的破局?
- 我是运营,我没有假期
- 谁来关心我们这些程序员
- 我的应聘总结!
- Microsoft Visual Studio .NET 2003制作安装程序
- 今天很高兴!
- 我的发现!
- 赋诗一首!——《秋》
- 在线等,一个十万火急的问题
- 独具量身定做特色的管理软件--数据大师
- 新思创OA功能列表
- VB五子棋问题,请高手赐教
- 请教高手:猜数字游戏(用delphi)
- 紧急求救(求ADPCM播放控件或者开发接口)
- 引用一个人的说法看中国软件需求基础
- 4年程序员感悟
- 日子一天天过........
- 怎样为任何控件和区域添加提示信息:用自己封装的CTip类
- 非对称加密算法中求解大正整数模大正整数的余数的快速计算法