|
|
一个方向控制射击小游戏的代码分析!(AS1.0) |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
今天看到到一个小游戏,就将它分析了一下...(原文地址: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发送键,看是不是可以了.... 还没发现哪里可以放源代码的,要的话,可以给我说一声,[email protected]
|
|
相关文章:相关软件: |
|