╋艺 镇╋╋网站网络|程序语言|Flash╋┣◇FLASH交流 → 男人就撑100秒教程1


  共有14319人关注过本帖树形打印复制链接

主题:男人就撑100秒教程1

美女呀,离线,留言给我吧!
admin
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 司令 亲民勋章
等级:管理员 帖子:3027 积分:27515 威望:0 精华:7 注册:2003/12/30 16:34:32
  发帖心情 Post By:2008/6/20 11:12:19 [显示全部帖子]

  4实现部分的关键代码(AS2)
       4.1粒子类:
      
 import SMotion.*
import SColDet.*
 
class SPhy.CSPhyMc extends MovieClip
{
       public var m:Number=0;//mass
       
       public var g:Number=0;//gravity
       
       public var pF:Number=0;//Positive forces,attention here UpCase!!!!!!!
       //Because the compiler was not so perfect as you think ,add a p here to prepare for the case.
       public var r:Number =0;//when it become a ball---radius.
       
       public var v :Number=0;//1 demision Velocity or together Velocity of vx ,vy
       public var vx:Number=0;
       public var vy:Number=0;
       
       public var f :Number=0;//fraction forces.
       public var fx:Number=0;
       public var fy:Number=0;
       
       public var a :Number=0;//acclerate v
       public var ax:Number=0;
       public var ay:Number=0;
       
       //plane game use;
       public var bigFire:Number=0;
       
       private static var DEAD:Number=0;
       private static var LIVED:Number=1;
       private var life:Number;
       
       private var mMotionCom:RCSMove;
       private var mColDetCom:RCSColDet;
       
       private static var thisP:Object;
              
       public function setLife(lifeValue:Number):Void
       {
              life=lifeValue;
       }
       
       public function getLife():Number
       {
              return life;
       }
       
       public function isLived():Boolean
       {
                     return life==LIVED;
       }
       
       public function init():Void
       {
              thisP=this;      
              this.vx=0;
              this.vy=0;
              this.v=3+random(3);
              
              this._width=10;
    this._height=10;
              this.r=5;
              
              this.initCom();
       }
       
       
       
       public function initPos(targetPlane:CSPhyMc):Void
       {
                 var randNum:Number=random(100);
                 //set init positoin:down,left,up,right
                 if(randNum<25)
                 {
                                 this._x=random(Stage.width);
                                 trace("Width"+Stage.width+"Height"+Stage.height);
                          
                                 this._y=Stage.height;
                 }
                 else if(randNum<50)
                 {
                                 thisP._x=_root.gStageLeft;
                                 this._y=random(Stage.height);
                 }
                 else if(randNum<75)
                 {
                                 this._x=random(Stage.width);
                                 thisP._y=_root.gStageTop;
                 }
                 else
                 {
                                 this._x=Stage.width;
                                 this._y=random(Stage.height);
                 }
                 
                 this.CalVx_Vy(this,targetPlane);
       }
       
       private  function GetDis(mc1:CSPhyMc, mc2:CSPhyMc):Number
       {
                            return Math.sqrt((mc1._x-mc2._x)*(mc1._x-mc2._x)+(mc1._y-mc2._y)*(mc1._y-mc2._y));
       }
       
       private function CalVx_Vy(mcChase:CSPhyMc, mcAim:CSPhyMc):Void 
       {
                            var len:Number= GetDis(mcChase, mcAim);
                            mcChase.vx=(mcAim._x-mcChase._x)/len*mcChase.v;
                            mcChase.vy=(mcAim._y-mcChase._y)/len*mcChase.v;
  }  
       
       public function initCom():Void
       {
              mMotionCom=new RCSMove();
              mColDetCom=new RCSColDet();
       }
       
       public function outDetect():Boolean
       {
         var offset:Number=25;
              return mColDetCom.particleOutDet(this,0-offset,0-offset,Stage.width+2*offset,Stage.height+2*offset);
       }
       
       public function move_show():Void
       {
              mMotionCom.Move2D(this,this.vx,this.vy);
       }
       
       public function collideDect(targetPlane:CSPhyMc):Boolean
       {
              if(_root.mcLibPlaneName=="ball")
                     return mColDetCom.TwoBall(targetPlane,this);
              //return this.hitTest(targetPlane.getBounds(_root).xMin,targetPlane.getBounds(_root).yMax,false);
       }
}


  
“艺镇”官方站:www.zyzsky.com QQ群:1221854  回到顶部
美女呀,离线,留言给我吧!
admin
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 司令 亲民勋章
等级:管理员 帖子:3027 积分:27515 威望:0 精华:7 注册:2003/12/30 16:34:32
  发帖心情 Post By:2008/6/20 11:12:58 [显示全部帖子]

4.2游戏主调度类
class ChaseAim
{      
       static private var thisP:Object;
       private var staturs:Number;//gaming 1,failure 0
      private var speed:Number;
       private var bulletNum:Number=20;
       private var start:Number=0;
       private var end:Number=0;
       public function init():Void
       {   thisP=this;
            staturs=1;
            speed=3;
           bulletNum=20;
            for(var i=0;i<11;i++)
              {
                _root.createTextField("txt"+i,i,0,(i-1)*25,500,25);
             }
               
             _root.attachMovie("ball","ball1",11);
             _root.ball1._x=250;
             _root.ball1._y=200;
             _root.ball1.r=20;
             
             for(var i=0;i<bulletNum;i++)
              {
                _root.attachMovie("bullet","bullet"+i,20+i);
              _root["bullet"+i].vx=0;
              _root["bullet"+i].vy=0;
              _root["bullet"+i].v=3+random(3);
              _root["bullet"+i].r=5;
              _root["bullet"+i]._width=10;
                _root["bullet"+i]._height=10;  
              
              GenBullet(_root["bullet"+i]);
             }
             start=getTimer();
             
             setInterval(EffectF,100);
       }
        
       private function EffectF():Void
             {
                   if(thisP.staturs!=0)
                  {               
                    for(var i=0;i<thisP.bulletNum;i++)
                     {
                      if (thisP.CheckOutBounds(_root["bullet"+i])) thisP.GenBullet(_root["bullet"+i]);
                    if(thisP.TwoBallCol(_root.ball1,_root["bullet"+i]))thisP.staturs=0;
                    thisP.Move2D(_root["bullet"+i]);
                    //_root.txt3.text=_root["bullet"+i].vx;
                   //_root.txt4.text=_root["bullet"+i].vy;
                          
                    }    
                   
                   
                    if( Key.isDown(Key.LEFT))_root.ball1._x -= thisP.speed;
                     if( Key.isDown(Key.RIGHT))_root.ball1._x += thisP.speed;
                     if( Key.isDown(Key.UP))_root.ball1._y -= thisP.speed;
                   if( Key.isDown(Key.DOWN))_root.ball1._y += thisP.speed;    
                    if(thisP.staturs==0)
                    {
                      _root.txt0.text="you failure";
                     thisP.end=getTimer();
                     var tmp:Number=thisP.end-thisP.start;
                     _root.txt1.text="你共坚持了"+tmp/1000+"秒";
                           //delete this.onEnterFrame;
                    }
                    }
              }
       
       private function GenBullet(tmpMc:CSPhyMc):Void
       {      var left:Number;
              var top:Number;
              if(random(2))
              {
                     left=random(7)*100-100;
                      top=random(2)*400;
              }
              else 
              {
                     left=random(2)*600;
                      top=random(6)*100-100;
              }
              tmpMc._x=left;
              tmpMc._y=top;
              CalVx_Vy(tmpMc, _root.ball1);
       }
       
       private function CheckOutBounds(tmpMc:CSPhyMc):Boolean
       {
              if(tmpMc._x<-10||tmpMc._x>510||tmpMc._y<-10||tmpMc._y>410)
                          return true;
              else      return false;
       }
       
       private  function TwoBallCol(ball1:CSPhyMc,ball2:CSPhyMc):Boolean
       {   
              if(Math.sqrt((ball1._x-ball2._x)*(ball1._x-ball2._x)+(ball1._y-ball2._y)*(ball1._y-ball2._y))<=(ball1.r+ball2.r))
                     return true;
              else
                     return false;
       }
       
       private  function GetDis(mc1:CSPhyMc, mc2:CSPhyMc):Number
       {
                            return Math.sqrt((mc1._x-mc2._x)*(mc1._x-mc2._x)+(mc1._y-mc2._y)*(mc1._y-mc2._y));
       }
       
       private function CalVx_Vy(mcChase:CSPhyMc, mcAim:CSPhyMc):Void 
       {
                            var len:Number= GetDis(mcChase, mcAim);
                            mcChase.vx=(mcAim._x-mcChase._x)/len*mcChase.v;
                            mcChase.vy=(mcAim._y-mcChase._y)/len*mcChase.v;
  }  
       
       private function Move2D(mc:CSPhyMc):Void
       {
              mc._x+=mc.vx;
              mc._y+=mc.vy;
       }

        


  
平面设计、网站建设、三维动画、视频制作 联系QQ:114103945  回到顶部
美女呀,离线,留言给我吧!
admin
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 司令 亲民勋章
等级:管理员 帖子:3027 积分:27515 威望:0 精华:7 注册:2003/12/30 16:34:32
  发帖心情 Post By:2008/6/20 11:15:05 [显示全部帖子]

 4.3核心运行函数:
       function mainLoop():Void
{
       UserPlaneControl();
       if(_root.gRunFlag)
       {
                //trace("yes");
                     for(var i:Number=0;i<_root.gBulletNum;i++)
                     {
                            //trace("yes");
                       if(!_root[mcUserBulletName+i].isLived())        
                                                 {
                                                        //trace("relife:"+i);
                                                        _root[mcUserBulletName+i].setLife(LIVED);
                                                        _root[mcUserBulletName+i].init();
                                                        _root[mcUserBulletName+i].initPos(_root[mcUserPlaneName]);
                                                 }
                            else if(_root[mcUserBulletName+i].outDetect())
                            {
                                                 //trace("outDetect:"+i);
                                                 _root[mcUserBulletName+i].setLife(DEAD);
                            }
                       else 
                       {
                                    _root[mcUserBulletName+i].move_show();
                                    
                                    if(_root[mcUserBulletName+i].collideDect(_root[mcUserPlaneName]))
                                        _root.gRunFlag=false;
                       }
                     }
       }
       else
       {
         var timeCount:Number=0;
         //clear the main game scence
              clearInterval(_root.gIntervalID);
              /*for(var i:Number=0;i<_root.gBulletNum;i++)
                     _root[mcUserBulletName+i].removeMovieClip();
              _root[mcUserPlaneName].removeMovieClip();
         */
         _root.gTimeEnd=getTimer();    
              timeCount=_root.gTimeEnd-_root.gTimeStart;
              trace("you last:"+String(timeCount)+"secs.");
              trace2("You lasted:"+String(timeCount)/1000+"secs.");
              /*start the end mc
              _root.gNextScence=0;
              _root.gIntervalID=setInterval(showEnd,_root.fps,_root.mcEndName,_root.result);
              */
       }
}5实验结论:
       通过该模型,实现了一个粒子系统的基本运作模式,该运作模式同样适用于其它的粒子系统,只要在最关键的运动及显示部分加以变换即可.


  
平面设计、网站建设、三维动画、视频制作 联系QQ:114103945  回到顶部