this.z=this.z+m_nSpeedZ;
}
public function adjustZ(sz:int)
{
this.z=this.z-sz;
if(this.z>1000)
this.visible=false;
else
this.visible=true;
}
}
}
(3) PlayerCar类的代码
PlayerCar类用于管理玩家赛车,它派生于CarBase,是一个特殊的赛车类。PlayerCar需要做的知识对用户输入控制赛车这一方面做一个处理即可,具体代码如下所示:
package classes{
import flash.display.MovieClip;
import flash.ui.Keyboard;
public class PlayerCar extends CarBase {
public function PlayerCar() {
}
public function Input(keys:Array) {
for each (var key in keys) {
switch (key) {
case Keyboard.UP :
m_nSpeedZ=m_nSpeedZ+2;
if (m_nSpeedZ>25) {
m_nSpeedZ=25;
}
break;
case Keyboard.LEFT :
m_nSpeedX=-12;
break;
case Keyboard.RIGHT :
m_nSpeedX=12;
break;
case Keyboard.DOWN :
m_nSpeedZ=m_nSpeedZ-2;
if (m_nSpeedZ<0) {
m_nSpeedZ=0;
}
break;
} Flash CS4三维游戏设计(赛车)(14):http://www.751com.cn/jisuanji/lunwen_294.html