二維動畫課程設(shè)計_第1頁
二維動畫課程設(shè)計_第2頁
二維動畫課程設(shè)計_第3頁
二維動畫課程設(shè)計_第4頁
二維動畫課程設(shè)計_第5頁
已閱讀5頁,還剩39頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

《二維動畫課程設(shè)計》

課程設(shè)計報告

基于AS3.0的嬉戲設(shè)計

一、序言

1課程設(shè)計目標

二維動畫課程設(shè)計旨在教授學(xué)生基本的設(shè)計原理和思路,并能發(fā)

揮學(xué)生的個人創(chuàng)意實力,運用Flash軟件和一些常用協(xié)助軟件,設(shè)計

制作flash動閩作品,并特殊強調(diào)學(xué)生的創(chuàng)新實力和動手實力。本課

程設(shè)計要求學(xué)生在接受課堂理論學(xué)問學(xué)習(xí)之后,能嫻熟利用Flash軟

件制作相關(guān)的動畫.

2、設(shè)計主題

1.基于AS3.0制作一個打飛機小嬉戲。

2.主要運用FlashCS4軟件和PhotoShopCS3圖片處理軟件。

3、嬉戲簡介

這是利用flashcs4基于AS3.0代碼設(shè)計的一款簡潔的打飛機

嬉戲,這款嬉戲借鑒了經(jīng)典的打鴨子嬉戲的一些做法,再結(jié)合自己

的一些想法設(shè)計出來的。用AdobeFlashPlayer打開嬉戲后,按

起先鍵,我們會看到:敵機在空中來回飛行,按左右上下箭頭鍵限

制飛機炮在空中左右上下移動,按下空格鍵放射子彈,擊中敵機后,

敵機爆炸。當被敵機遇到后,飛機爆炸,嬉戲結(jié)束,或是當擊落的

敵機達到100架后,嬉戲結(jié)束。

ASASAS

|{}(){}

AAGunAirAirRaidBullet

AirRaid,fla主文件,程序界面與元件,綁定了文檔

類AirRaid,as。

AirRaid,as文檔類,程序的入口,限制整個程序的邏

輯依次,邏輯結(jié)構(gòu)關(guān)系。

AAGun.as綁定庫中的火炮的類,限制火炮

AirPlane,as綁定庫中的敵機的類,限制飛機

Bullet,as綁定庫中的子彈的類,限制子彈

3、嬉戲中各圖層名稱與作用

嬉戲中的主文件AirRaid,fla文件,分為7個圖層4幀,幀上有代碼,

綁定了文檔類

2、背景層:在其次幀嬉戲起先時顯示下雨效果。

3、成果顯示層:得分:動態(tài)文本,實例名showScore;

剩余子彈:動態(tài)文本,實例名showShots;

級別:動態(tài)文本,實例名稱showjbo

4、按鈕與提示層:第1幀:起先按鈕與說明,按鈕實例名:

startButtono

第3幀:重新起先按鈕與結(jié)束提示,按鈕實例名

playAgainButtorio

第4幀:重新起先按鈕與結(jié)束提示,按鈕實例名

playAgaino

5、as(代碼)層:4幀每幀都有代碼,詳細代碼將在下面說明。

6、背景音樂層:在嬉戲起先時播放背景音樂。

7、標簽層:第1幀:標簽名稱intro;第2幀:標簽名稱play;

第3幀:標簽名稱gameover;第4幀:標簽名稱gamewin。

三、設(shè)計步驟

1、制作嬉戲必需的素材和打算工作

首先按前面嬉戲結(jié)構(gòu)中說明的那樣,建好五個文件分別為:

AirRaid,fla^AirRaid.as>

AAGun.as>AirPlane,as>Bullet,asoAirRaid,fla文件與文檔類

AirRaid,as綁定,在AirRaid.fla

文件

中新建9個影片剪輯分別為:

AAgun:在里面制作飛機炮并將類名命名為AAgun,與外面的AAgun.as

綁定。

Airplane:1-5幀每幀一個飛機圖形。第6-9幀爆炸圖形并添加爆炸

聲音,有標簽:explode

第10幀有代碼parent.removeChiId(this);stop();(說

明:parent是父容器

this是自身removeChild是移除。這句代碼的意思是通知

父容器把它從顯示界面移除。就是說當子彈擊中敵機,敵機

播放爆炸效果。播放到第10幀時,就通知它的父容器把它從

屏幕上移除。),類名為Airplane。

bullet:繪制子彈,類名為bullet。

yudi:制作下雨動畫;先制作好一個雨滴,將類名命名為ydjnc,在

代碼層寫

varbl;

varsj:Timer=newTimer(Math,random()*500+500,10);

sj.addEventListener(TimerEvent.TIMER,sjcd);

sj.start();

functionsjcd(event:TimerEvent){

for(varb=0;b<5;b++){

varyd:yd_mc=newydmc();

addChiIdAt(yd,bl);

yd.x=Math.random()*550;

yd.y=Math.random()*100;

bl++;

)

begin:制作嬉戲起先時的說明,在按鈕與斃示層第一幀拖到主場景,

并命名為p3_mco

fail:制作嬉戲失敗時的說明,在按鈕與禿示層第三幀拖到主場景,

并命名為pl_mco

win:制作嬉戲成功時的說明。在按鈕與提示層第四幀拖到主場景,

并命名為p2_mco

dfj:制作打飛機嬉戲的圖片。在按鈕與提示層第一幀拖到主場景,

并命名為p4_mco

sy:導(dǎo)入背景音樂,在背景音樂層其次幀布到主場景。

然后再制作一個按鈕命名為BasicButton,到這里只要再把須要的背

景圖片和聲音導(dǎo)入,制作嬉戲所須要的素材全部制作好了。

2、嬉戲中各圖層中的一些代碼的書寫和說明

在前面嬉戲結(jié)構(gòu)中已經(jīng)說明白主場景中各圖層的作用和關(guān)系,現(xiàn)

在就嬉戲中各圖層中的一些代碼的書寫進行說明并說明。

(1)、as(代碼)層的每幀代碼與說明:

第1幀代碼:

importflash,events.MouseEvent;

stop();

startButton.addEventListener(MouseEvent.CLICK,clickStart.);

functionclickStart(event:MouseEvent){

gotoAndStop(/,play,/);

)

說明:給startButton注冊了鼠標點擊事務(wù),用clickStart方法來

實現(xiàn),點擊startButton

按鈕就把影片轉(zhuǎn)到第2幀上嬉戲的進行界面。

第2幀代碼:

stopO;

startAirRaidO;

說明:調(diào)用文檔類的startAirRaid方法,執(zhí)行這個方法,就會生成

敵機,火炮,接受用戶

的鍵盤操作事務(wù)來生成子彈等一系列操作。

第3幀代碼:

playAgainButton.addEventListener(MouseEvent.CLICK,clickPlay

Again);

functionclickPlayAgain(event:MouseEvent){

gotoAndStop(,,play,/);

)

說明:給playAgainButton注冊了鼠標點擊事務(wù),用clickPlayAgain

方法實現(xiàn),點擊

playAgainButton按鈕跳轉(zhuǎn)到第2幀。

第4幀代碼:

playAgain.addEventListener(MouseEvent.CLICK,clickPlay);

functionclickPlay(event:MouseEvent){

gotoAndStop(/zplay/z);

)

說明:給playAgain注冊了鼠標點擊事務(wù),用clickPlayAgain方法

實現(xiàn),點擊跳轉(zhuǎn)playAgain

按鈕到第2幀。

(2)、按鈕與提示層的各幀代碼與說明:

第1幀代碼

importfl.transitions.*;

importfl.transitions,easing.

TransitionManager.start(p3_mc,{type:Fade,

direction:Transition.IN,

duration:3,

easing:None.easeNone});

TransitionManager.start(p4_mc,{type:PixelDissolve,

direction:Transition.IN,

duration:6,

easing:None.easeNone,

xSections:100,

ySections:50));

說明:用淡入的效果顯示p3_mc影片剪輯看,用像素溶解的效果顯示

p4_mc影片剪輯。

第3幀代碼

importfl.transitions.*;

importfl.transitions,easing.

TransitionManager.start(plme,{type:PixeiDissolve,

direction:Transition.IN,

duration:2,

easing:None.easeNone,

xSections:100,

ySections:50));

說明:用像素溶解的效果顯示pl_mc影片剪輯。

第4幀代碼

importfl.transitions.

importfl.transitions,easing.

TransitionManager.start(p2me,{type:Zoom,

direction:Transition.IN,

duration:2,

easing:Elastic.easoOut});

說明:用彈性縮放的效果顯示p2_mc影片剪輯。

(3)、嬉戲制作中各腳本類的編寫和作用

編寫AirRaid,as類

AirRaid類是嬉戲的限制器,綁定AirRaid.fla。負責(zé)生成界面上

的飛機、飛機炮、子彈。顯

示得分、子彈的剩余數(shù)量和級別。注冊了鍵盤按下,釋放偵聽器,接

收用戶的鍵盤操作。注

冊了進入幀事務(wù)偵聽器,進行碰撞檢測。定義一個飛機計時器,隨機

生成飛機。檢測剩余子

彈的數(shù)目,當子彈數(shù)為零或飛機炮敵機相撞時嬉戲結(jié)束,移除界面上

的飛機,火炮,跳轉(zhuǎn)到

嬉戲失敗界面,當擊落的敵機數(shù)為100時嬉戲結(jié)束,移除界面上的飛

機,火炮,跳轉(zhuǎn)到游

戲成功界面。(代碼如下)

package{

import

flash.display.MovieClip;

import

flash,display.SimpleButton;

import

flash,events.KeyboardEvent;

importflash,utils.Timer;

import

flash,events.TimerEvent;

importflash,text.TextField;

importflash,events.Event;

publicclassAirRaidextends

MovieClip{

privatevarspeed:Number;

privatevaraagun:AAGun;//

飛機炮

privatevar

airplanes:Array;〃飛機數(shù)組

privatevar

bullets:Array;〃子彈數(shù)組

publicvar

leftArrow,rightArrow,upArrow,

downArrow:Boo1ean;

privatevar

nextPlane:Timer;〃不定時生成

飛機的計時器

privatevar

shotsLeft:int;〃得分文本

privatevarshotsHit:int;//

子彈數(shù)文本

privatevarjibie:int;〃得

分文本

publicfunction

startAirRaid(){

//初始化得分數(shù)、子彈數(shù)

和級別

jibie=l;

shotsLeft=300;

shotsHit=0;

showGameScore();

//生成飛機炮加入到舞臺

aagun=newAAGun();

addChiId(aagun);

//生成飛機、子彈數(shù)組

airplanes=newArray();

bullets=newArray();

//鍵盤按下、釋放事務(wù)偵

聽器

stage.addEvontListoner(KeyboardEvcnt.KEYDOWN,koyDownFun

ction);

stage.addEventListener(KeyboardEvent.KEYUP,keyUpFunctio

n);

//進入幀事務(wù)偵聽器,檢測子彈

擊中飛機和敵機飛機炮的碰撞檢

測。

addEventListener(Event.ENTERFRAME,checkForllits);

addEventListener(Event.ENTER

FRAME,checkForllit);

//生成下一架飛機

setNextPlane();

}

〃依據(jù)級別的不同不定時生成

飛機

publicfunction

setNextPlane(){

if((shotsHit<=10)){

//1000毫秒至2000毫

秒之間生成一架飛機

nextPlane=new

Timor(1000+Math.random()*1000

,1);

nextPlane.ciddEventListener(TimerEvent.TIMERCOMPLETE,new

Plane);

nextPlane.start();

}elseif(shotsHit>10

&&shorsHit<=20){

jibie=2;

//800毫秒至1600毫秒

之間生成一架飛機

nextPlane=new

Timer(800+Math.random()*800,1

);

showGameScore();

nextPlane.addEventListener(TimerEvent.TIMERCOMPLETE,new

Plane);

nextPlane.start();

}elseif(shotsHit>20

&&shorsHit<=30){

jibie=3;

//600亳秒至1200亳秒

之間生成一架飛機

nextPlane=new

Timer(600+Math.random()*600,1

);

showGameScore();

nextPlane.addEventListener(TimerEvent.TIMERCOMPLETE,new

Plane);

nextPlane.start();

}elseif(shotsHit>30

&&shotsHit<=40){

jibie=4;

//400毫秒至800毫秒

之間生成一架飛機

nextPlane=new

Timer(400+Math.random()*400,1

);

showGameScore();

nextPlane.addEventListener(TimerEvent.TIMERCOMPLETE,newPla

ne);

nextPlane.start();

}elseif(shotsHit>40

&&shotsHit〈=50){

jibie=5;

//200毫秒至400毫秒

之間生成一架飛機

nextPlane=new

Timer(200+Math.random()*200,1

);

showGameScore();

nextPlane.addEventListener(TimerEvent.TIMERCOMPLETE,new

Plane);

nextPlane.start();

}elseif(shotsHit>50

&&shorsHit<=60){

jibie=5;

//100毫秒至200毫秒

之間生成一架飛機

nextPlane=new

Timer(100+Math.random()*100,1

);

showGameScore();

nextPlane.addEventListener(TimerEvent.TIMERCOMPLETE,new

Plane);

nextPlane.start();

}elseif(shotsHit>60

&&sho二sHit?70){

jibie=6;

//90毫秒至180毫秒之

間生成一架飛機

nextPlane=new

Timer(90+Math.random()*90,1);

showGameScore();

nextPlane.addEventListener(TimerEvent.TIMER_COMPLETE,new

Plane);

nextPlane.start();

}elseif(shotsllit>70

&&shotsHit<=80){

jibie=7;

//80毫秒至160毫秒之

間生成一架飛機

nextPlane=new

Timer(80+Math.random()*80,1);

showGameScore();

nextPlane.addEventListener(TimerEvent.TIMERCOMPLETE,new

Plane);

nextPlane.start();

}elseif(shotsHit>80

&&shorsHit<=90){

jibie=8;

//70毫秒至140毫杪之

間生成一架飛機

nextPlane=new

Timer(70+Math.random()*70,1);

showGameScore();

nextPlane.addEventListener(TimcrEvent.TIMERCOMPLETE,new

Plane);

nextPlane.start();

}elseif(shotsHit>90

&&shoisHit<=100){

jibie=9;

//60毫秒至120毫秒之

間生成一架飛機

nextPlane=new

Timer(70+Math.random()*70,1);

showGcimeScore();

nextPlane.addEventListener

(TimerEvent.TIMER_COMPLETE,ne

wPlane);

nextPlane.start();

publicfunction

newPlane(event:TimerEvent){

//隨機的邊、速度和高度

if(Math,random()>.5){

var

side:String=,zleft,z;

}else{

side=〃right〃;

]

var

altitude:Number=Math.random()

*50+20;

〃依據(jù)級別的不同,敵機的飛行速度的設(shè)定

if(jibie<=2){

speed=Math,random()*150+15

0;

}elseif

(jibie>2&ajibie<=4){

speed=Math.random()*175+17

5;

}elseif

(jibie>4&&jibie<=6){

speed=Math.random()*200+20

0;

}elseif(jibie>6){

speed=Math,random()*225+22

5;

i

J

//生成飛機

varp:Airplane=new

Airplane(side,speed,altitude)

*

9

addChild(p);

airplanes,push(p);

setNextPlaneO;

//敵機和飛機炮的碰撞檢測

publicfunction

checkForllit(event:Event){

for(var

airplaneNum:int=airplanes,len

gth-1;airplaneNum>=0;

airplaneNum--){

if

(aagun.hitTestObject(airplane

s[airplaneNum])){

airplanes[airplaneNum].pla

neHit();

endGame();

)

J

)

//子彈和敵機的碰撞檢測

publicfunction

checkForHits(event:Event){

for(var

bulletNum:int=bullets.length-

1;bulletNum>=0;bulletNuni--)

(

for(var

airplaneNum:int=airplanes.len

gth-l;airplaneNum>=0;

airplaneNum--){

if

(bullers[bulletNum],hitTestOb

ject(airplanes[airplaneNum]))

(

airplanes[airplaneNum].pla

neHit();

bullets[bulletNum].deleteB

ullet();

shotsllit++;

showGameScore();

break;

}

)

〃當擊落的敵機數(shù)位100時?,嬉戲成功,結(jié)束

if((shotsllit==100)){

winGcime();

]

〃當子彈為零時,嬉戲失敗,結(jié)束

if((shotsHit!=100)&&(shotsLeft==0)){

endGame();

/

)

//按下鍵盤

publicfunction

keyDownFunction(event:Keyboar

dEvent){

if(event.keyCode==37){

1eftArrow二true;

}elseif(event.keyCode

==39){

rightArrow=true;

}elseif(event.keyCode

=38){

upArrow=true;

}elseif(event.keyCode

==40){

downArrow=true;

}elseif(event.keyCode

=32){

fireBullet();

)

}

//釋放鍵盤

publicfunction

keyUpFunction(event:KeyboardE

vent){

if(event.keyCode==37){

leftArrow=false;

}elseif(event.keyCode

=39){

rightArrow=false;

}elseif(event.keyCode

=38)

upArrow=false;

}elseif(event.keyCode

==40){

downArrow=false;

!

)

//生成新的子彈

publicfunctionfireBullet()

(

if(shotsLeft<=0){

return;

/

varb:Bullet=new

Bullet(aagun.x,aagun.y,-300);

varkq:zidan=new

zidan();

kq.play();

addChild(b);

bullets,push(b);

shotsLeft―;

showGameScore();

}

publicfunction

showGameScore(){

showScore.text=String(,z

得分:*+shotsHit);

showShots.text=String(〃

剩余子彈:〃+shotsLeft);

showjb.text=String(〃級

別:〃+jibie);

//從數(shù)組獲得飛機

publicfunction

removePlane(plane:Airplane){

for(variinairplanes)

(

if

(airplanes[i]==plane){

airplanes.splice(i,1);

break;

)

)

}

//獲得數(shù)組的一個子彈

publicfunction

removeBullet(bullet:Bullet){

for(variinbullets){

if

(bullets[i]==bullet){

bullets.splice(i,1);

break;

)

)

//嬉戲結(jié)束,移除界面上的東

西。

publicfunctionendGame(){

//移除飛機

for(var

i:int=airplanes.length-1;

i>=0;i—){

airplanes[i].deletePlane()

airplanes二nuH;

aagun.deleteGun();

aagun=null;

//移除偵聽器

stage.removeEventListener(KeyboardEvent.KEYDOWN,keyDown

Function);

stage.removeEventListener(KeyboardEvent.KEY_UP,keyUpFunc

tion);

removeEventListener(Event.ENTERFRAME,checkForllits);

removeEventListener(Event.ENTERFRAME,checkForHit);

nextPlane.stopO;

nextPlane=null;

gotoAndStop(/,gameover,/);

)

publicfunctionwinGame(){

//移除飛機

for(var

i:int=airplanes,length-1;

i>=0;i―){

airplanes[i].deletePlaneO

airplanes=null;

aagun.deleteGunO;

aagun=null;

//移除偵聽器

stage.removeEventListener(KeyboardEvent.KEYDOWN,keyDown

Function);

stage.removeEventListener(KeyboardEvent.KEYUP,keyUpFunc

tion);

romovcEvontListoner(Event.

ENTER_FRAME,checkForllits);

removeEventListener(Event.

ENTERFRAME,checkForHit);

nextPlane.stop();

nextPlane=null;

gotoAndStop("gamewin");

}

}

)

編寫AAGun.as類

AAGun類:邦定庫中的飛機炮元件,限制飛機炮的初始位置和向左、

向右、向上、向下移

動,檢測邊界,飛機炮的消毀。(代碼如下)

package{

importflash,display.

importflash,events.*;

importflash,utils.getTimer;

publicclassAAGunextends

MovieClip{

staticconst

speed:Number=150.0;

privatevarlastTime:int;//

限制移動的Timer

publicfunctionAAGun(){

//飛機炮的初始位置

this.x=275;

this.y=340;

〃運動

addEventListener(Event.ENT

ERFRAME,moveGun);

publicfunction

moveGun(event:Event){

//得到時差

var

timePassed:int=getTimer()-las

tTime;

lastTime+=timePassed;

//現(xiàn)在的位置

varnewx=this.x;

varnewy=this.y;

//移動到左邊

if

(MovieClip(parent).leftArrow)

newx-=speed*timePassed/100

0;

)

//移動到右邊

if

(MovieClip(parent).rightArrow)

(

newx+=speed*timePassed/100

0;

/

//移動到上邊

if

(MovieClip(parent).upArrow){

newy-=5;

i

J

//移動到下邊

if

(MovieClip(parent).downArrow)

newy+=5;

//檢測邊界

if(newx<10){

newx=10;

!

if(newx>540){

newx=540;

]

if(newy<10){

newy=10;

;

if(newy>380){

newy=380;

//更新位置

rhis.x=newx;

rhis.y=newy;

)

//移除屏幕上的飛機炮和事

務(wù)

publicfunctiondeleteGun()

parent.removeChild(this);

removeEventListener(Event.

ENTERFRAME,moveGun);

)

}

)

編寫Airplane,as類

Airplane類:邦定庫中的飛機元件。隨機產(chǎn)生飛機,隨機的速度,

產(chǎn)生5種飛機樣式,檢測

是否飛出邊界,檢測被子彈擊中。自動毀滅和爆炸效果。(代碼如下)

package{

importflash.display.MovieClip;

importflash,events.TimerEvent;

importflash,utils.Timer;

importflash,utils.getTimer;

importflash,events.Event;

publicclassAirplaneextendsMovieClip{

privatevardx:Number;//飛機的速度、方向

privatevar

dy:Number;

privatevarlastTime:int;//限制移動的Timer

〃左右移動

publicfunctionAirplane(side:String,

speed:Number,altitude:Number)

(

varbl;

if(side二二"left"){

this,x=-50;//starttothe

left

for(varb=0;

b<5;b++){

this.y=Math.random()*400;

if(this.y>300){

dy

=-l/3*Math.random0*speed;}

else(dy

=-l/3*Math.random()*speed;}

dx二speed;

bl++;

this.scaleX=-1;//reverse

)

}elseif(side

二二"right"){

this,x=600;//starttothe

right

for(vara=0;

a<5;a++){

this,y二Math,random()*400;

if(this.y>300){

dy

=-l/3*Math.random()*speed;}

else{dy

=-l/3*Math.random0*speed;}

dx二-speed;

bl++;

this.scaleX=1;

)

}

this.gotoAndStop(Math,floor(M

ath.random()*5+1));

addEventListener(Event.ENTER_

FRAME,movePlane);

lastTime=getTimer();

〃檢測邊界

publicfunctionmovePlane(event:Event){

vartimePassed:i

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論