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

 赛车游戏我们总是遇到!今天给大家简单讲解一下。
先测试效果:
[url=http://www.webjx.com/download.php?url=http://www.webjx.com/upfiles/20070517/20070517114146_webjx_com_1.fla]
[color="#ff0000"][1b]点击这里下载源文件[/1b][/color]
[/url]
首先新建立一个赛车影片剪辑,由6个图层组成一个基本的赛车。放到舞台上的时候命名实例名为car1。
[img]/Files/BeyondPic/2007-5/17/20070517113158_01.gif[/img]
然后根据上面的车,制作一个赛车阴影影片剪辑。拖放到舞台上的时候命名实例名为shadow1。
[img]/Files/BeyondPic/2007-5/17/20070517113209_02.gif[/img]
然后建立一个新的空的影片剪辑。拖放到舞台上的时候命名实例名stepper。
[img]/Files/BeyondPic/2007-5/17/20070517113224_03.gif[/img]
然后选中该空影片剪辑输入下面代码:
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]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;
本文转自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/959.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值