每天學習多一點flash(36) as2.0 遊戲設計筆記

來源:互聯網
上載者:User

 

//定義個水果
var num:Number=20;
var number:Number=0;
_root.applemark=0;//標記蘋果分數
_root.orangemark=0;//標記橙分數

function creatorange(){
name="orange"+num;
attachMovie("orange",name,num);
_root[name]._x=Math.random()*700;
_root[name]._rotation=Math.random()*4;

num++;
}///產生大量的橙

function creatapple(){
name="apple"+number;
attachMovie("apple",name,number);
_root[name]._x=Math.random()*700;
_root[name]._rotation=Math.random()*4;
number++;
}

a=setInterval(creatorange,3000);
b=setInterval(creatapple,2000);

//背景音樂///
var b_music:Sound=new Sound();
b_music.attachSound("blackgroudmusic");
b_music.start(0,10000000);

 

/////////////////////設定魚兒動作//////////////
var t:Number=1;
fish.onEnterFrame=function(){
 if(fish._y<411)
 {t=-1;}
 if(fish._y>611)
 {t=1;}
 
if(fish.hitTest(player))
{player._x-=25;}
 
 
}
var tt:Number=1;
fish2.onEnterFrame=function(){
 if(fish2._y<468)
 {tt=-1;}
 if(fish2._y>611)
 {tt=1;}
 
}
var ttt:Number=1;
fish3.onEnterFrame=function(){
 if(fish3._y<400)
 {ttt=-1;}
 if(fish3._y>611)
 {ttt=1;}
 
}
 
 
 

///////////////墨魚//////////////
var yu_speed:Number=1;
moyu.onEnterFrame=function(){
 
 if(moyu._x>652)
 {
  
   yu_speed=-1;
 }
 
 if(moyu._x<542)
 {
  
   yu_speed=1;
 }
 
}  

 

部分的代碼。其中包括怎樣產生大量物體的語句,例如

function creatapple(){
name="apple"+number;
attachMovie("apple",name,number);
_root[name]._x=Math.random()*700;
_root[name]._rotation=Math.random()*4;
number++;
}

b=setInterval(creatapple,2000);//利用時間間隔來產生這一個大量物體的過程。

在使用這些語句的時候在庫裡面選擇串連,勾選第一幀輸出,賦予一個id 號:

其次 就是賦予物體動作:以及發生碰撞的時候 會發生什麼的狀況,如分數增加,血瓶減少,聲音產生,物體撤銷,狀態改變等等狀況。

onClipEvent (enterFrame) {
 this._y+=4;
 
 if(this.hitTest(_root.player))
 {
  
  _root.applemark+=1;
  var p:Sound=new Sound();
  p.attachSound("aa");
  p.start(0,1);
  removeMovieClip(_parent);}
}

之後就需要對主角賦予一些操作的動作。

onClipEvent (load)
{
    function move(x, y)
    {
        setProperty("", _x, _x + Math.cos(_rotation * 3.141593E+000 / 180) * x);
        setProperty("", _y, _y + Math.sin(_rotation * 3.141593E+000 / 180) * x);
        if (!_root.map.hitTest(_x, _y + y, true))
        {
            setProperty("", _y, _y + y);
        }
    }
  
}
onClipEvent (enterFrame)
{
    if (Key.isDown(Key.UP) && !jump)
    {
       
        jump = true;
        vy = -13;
    }
    if (jump)
    {
        move(0, -5);
        move(0, vy++);
        if (vy ==18)
        {
            jump = false;
        } // end if
    } // end if
    if (1)
    {
        move(0, 5);
    
    } // end else if
    if (Key.isDown(Key.RIGHT))
    {
       
            move(5, 0);
        } // end if
     
 
    if (Key.isDown(Key.LEFT))
    {
    
            move(-5, 0);
        } // end if
   
   
}
演算法 可以參考馬里奧的flash 遊戲來產生,這些都是很好練習,但如果把這些放到一個類去 應該會很好很好。

之後再設定 設定陷阱 加強啊遊戲的好玩度。。 最後先做美工啦

源檔案:

http://dl2.csdn.net/down4/20080210/10180244169.rar 

希望可以協助大家對大家有點啟發,寫得不好,望能見諒!菜鳥 ————+夏天的樹人上

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.