}
if (m_nSpeedZ>0) {
m_nSpeedZ--;
}
if (m_nSpeedZ<0) {
m_nSpeedZ++;
}
if (m_nSpeedX>0) {
m_nSpeedX-=4;
}
if (m_nSpeedX<0) {
m_nSpeedX+=4;
}
}
}
}
(4) RacingGame类的代码
RacingGame类对应游戏的舞台,该类代码如下所述:
package classes
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class RacingGame extends MovieClip
{
private var m_aKeys:Array=[-1,-1,-1,-1];
public function RacingGame()
{
T_Road.stop();
T_Tree.stop();
T_Rock.stop();
this.stop();
T_PlayButton.addEventListener(MouseEvent.MOUSE_UP,OnMouseUp);
}
public function OnMouseUp(e:MouseEvent):void
{
T_Title.visible=false;
T_PlayButton.visible=false;
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyboardDown);
this.stage.addEventListener(KeyboardEvent.KEY_UP,onKeyboardUp);
var myTimer:Timer=new Timer(100,0);
myTimer.addEventListener("timer",timerHandler);
myTimer.start();
}
public function onKeyboardDown(e:KeyboardEvent):void
{
for(var i:int=0;i<m_aKeys.length;i++)
{
if(m_aKeys[i]==e.keyCode)
return;
}
for(i=0;i<m_aKeys.length;i++)
{
if(m_aKeys[i]==-1)
m_aKeys[i]=e.keyCode;
break; Flash CS4三维游戏设计(赛车)(15):http://www.751com.cn/jisuanji/lunwen_294.html