由浅入深学习Flash制作赛车游戏教程-Flash教程

来源:网页教学网 作者:闪电儿 更新时间:2008-03-04 点击:

赛车游戏我们总是碰到!今天给大家简单讲解一下。

先测试效果:

点击这里下载源文件

首先新建立一个赛车影片剪辑,由6个图层组成一个基本的赛车。放到舞台上的时候命名实例名为car1。

由浅入深学习Flash制作赛车游戏教程

然后根据上面的车,制作一个赛车阴影影片剪辑。拖放到舞台上的时候命名实例名为shadow1。

由浅入深学习Flash制作赛车游戏教程

然后建立一个新的空的影片剪辑。拖放到舞台上的时候命名实例名stepper。

由浅入深学习Flash制作赛车游戏教程

然后选中该空影片剪辑输入下面代码:

onClipEvent(load){
speed1 = 0;
}
onClipEvent(enterFrame){
_root.step(1);
}

然后新建立一个层Action,输入下面代码:

function step(who) {
//check to see if the car in question is controlled by the player or by the computer
if (_root[\"car\" who].code == \"player\") {
//we will constantly decrease speed by multiplying it with a number below 1
if (this[\"speed\" who]>0.3) {
this[\"speed\" who] *= _root.speedDecay;
} else {
this[\"speed\" who] = 0;
}
//the car will react to certain keys
//accelerate
if (Key.isDown(Key.UP) && this[\"speed\" who]<_root.maxSpeed) {
this[\"speed\" who] = _root.acceleration;
}
//brake (reverse)
if (Key.isDown(Key.DOWN)) {
this[\"speed\" who] -= _root.backSpeed;
}
//steer left
if (Key.isDown(Key.LEFT) && this[\"speed\" who]>0.3) {
_root[\"car\" who]._rotation -= _root.rotationStep*(this[\"speed\" who]/_root.maxSpeed);
}
//steer right
if (Key.isDown(Key.RIGHT) && this[\"speed\" who]>0.3) {
_root[\"car\" who]._rotation = _root.rotationStep*(this[\"speed\" who]/_root.maxSpeed);
}
this[\"rotation\" who] = _root[\"car\" who]._rotation;
//we calculate the two components of speed (X axis and Y axis)
this[\"speedx\" who] = Math.sin(this[\"rotation\" who]*(Math.PI/180))*this[\"speed\" who];
this[\"speedy\" who] = Math.cos(this[\"rotation\" who]*(Math.PI/180))*this[\"speed\" who]*-1;
//apply the components on the actual position of the car
_root[\"car\" who]._x = this[\"speedx\" who];
_root[\"car\" who]._y = this[\"speedy\" who];
//position the shadow of the car
_root[\"shadow\" who]._x = _root[\"car\" who]._x-4;
_root[\"shadow\" who]._y = _root[\"car\" who]._y 2;
_root[\"shadow\" who]._rotation = _root[\"car\" who]._rotation;
}
if (_root[\"car\" who].code == \"computer\") {
}
}

  然后再建立一个层,输入下面代码(用于初始化变量)

car1.code = \"player\";
acceleration = 0.4;
speedDecay = 0.96;
rotationStep = 10;
maxSpeed = 10;
backSpeed = 1;

  测试了!今天快下班了!!明天接着给大家把这个游戏弄的更加完整!后面还有两个步骤,大家通过测试上面的动画会发现车没有场地限制!之后我们将给它限定一定的路线。期望!
相关Flash教程:
最新评论:
loading.. 评论加载中....
发表评论:不能超过250字节,请自觉遵守互联网相关政策法规.
  • 昵称: 验证:

最新Flash教程