当前位置:首页>网络学院>网页制作>Flash教程>文章内容

由浅入深!Flash制作高射炮游戏

[ 来源:www.it55.com | 作者: | 时间:2007-07-12 | 收藏 | 推荐 ] 【

  主要是利用Flash Actionscript一步一步学习Flash高射炮简单游戏制作过程,最终效果只是一个简单的演示,如果你有兴趣可以继续深入学习!(教程最后页提供演示动画的源程序下载)
http://www.it55.com/

  第一步:首先简单的制作一个鼠标动画,绘制一个鼠标的图,自己定。然后选择第一帧输入下面代码: http://www.it55.com/

  Mouse.hide();
  attachMovie("crosshair", "crosshair", 1);
  crosshair.onEnterFrame = function() {
  this._x = _xmouse;
  this._y = _ymouse;
  };

www.it55.com


  效果如下: 免费资源www.it55.com


效果预览 45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn

  第二步:绘制一个坦克,分成两部分,如下面:

IT资讯之家 www.it55.com

由浅入深!Flash<a href='/html/xueyuan/wangyezhizuo'><u>制作</u></a>高射炮<a href='/html/mat/shenghuoyongpin/wanjuyouxi'><u>游戏</u></a>(图一)
绘制坦克

IT资讯之家 www.it55.com

  把下面的命名实例名为tank。代码如下: IT资讯之家 www.it55.com

  Mouse.hide();
  attachMovie("crosshair", "crosshair", 1);
  attachMovie("tank", "tank", 2, {_x:230, _y:350});
  crosshair.onEnterFrame = function() {
  this._x = _xmouse;
  this._y = _ymouse;
  };
  tank.onEnterFrame = function() {
  mousex = _xmouse-this._x;
  mousey = (_ymouse-this._y)*-1;
  angle = Math.atan(mousey/mousex)/(Math.PI/180);
  if (mousex<0) {
  angle += 180;
  }
  if (mousex>=0 && mousey<0) {
  angle += 360;
  }
  this.cannon._rotation = angle*-1;
  };
vd;k;l www.it55.com rdfg

45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn

  效果(无角度限制):

sflj www.it55.com kg^&fgd


效果预览

IT资讯之家 www.it55.com

  第三步:我这里设置转动的一定的角度。 IT资讯之家 www.it55.com

  Mouse.hide();
  attachMovie("crosshair", "crosshair", 1);
  attachMovie("tank", "tank", 2, {_x:230, _y:350});
  crosshair.onEnterFrame = function() {
  this._x = _xmouse;
  this._y = _ymouse;
  };
  tank.onEnterFrame = function() {
  mousex = _xmouse-this._x;
  mousey = (_ymouse-this._y)*-1;
  angle = Math.atan(mousey/mousex)/(Math.PI/180);
  if (mousex<0) {
  angle += 180;
  }
  if (mousex>=0 && mousey<0) {
  angle += 360;
  }
  if (angle>160) {
  angle = 160;
  }
  if (angle<20) {
  angle = 20;
  }
  this.cannon._rotation = angle*-1;
  };

www.it55.com

http://www.it55.com/

  效果如下:

45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn


效果预览

免费资源www.it55.com

  然后是计算开火的目标:

it55.com

  Mouse.hide();
  attachMovie("crosshair", "crosshair", 1);
  attachMovie("tank", "tank", 2, {_x:230, _y:350});
  crosshair.onEnterFrame = function() {
  this._x = _xmouse;
  this._y = _ymouse;
  };
  tank.onEnterFrame = function() {
  mousex = _xmouse-this._x;
  mousey = (_ymouse-this._y)*-1;
  angle = Math.atan(mousey/mousex)/(Math.PI/180);
  if (mousex<0) {
  angle += 180;
  }
  if (mousex>=0 && mousey<0) {
  angle += 360;
  }
  if (angle>160) {
  angle = 160;
  }
  if (angle<20) {
  angle = 20;
  }
  firepower = Math.sqrt(mousex*mousex+mousey*mousey);
  if (firepower>200) {
  firepower = 200;
  }
  this.cannon._rotation = angle*-1; http://www.it55.com/
  };
sflj www.it55.com kg^&fgd

http://www.it55.com/

  开火的制作vd;k;l www.it55.com rdfg


  Mouse.hide();
  attachMovie("crosshair", "crosshair", 1);
  attachMovie("tank", "tank", 2, {_x:230, _y:350});
  crosshair.onEnterFrame = function() {
  this._x = _xmouse;
  this._y = _ymouse;
  };
  tank.onEnterFrame = function() {
  mousex = _xmouse-this._x;
  mousey = (_ymouse-this._y)*-1;
  angle = Math.atan(mousey/mousex)/(Math.PI/180);
  if (mousex<0) {
  angle += 180;
  }
  if (mousex>=0 && mousey<0) {
  angle += 360;
  }
  if (angle>160) {
  angle = 160;
  }
  if (angle<20) {
  angle = 20;
  }
  firepower = Math.sqrt(mousex*mousex+mousey*mousey);
  if (firepower>200) {
  firepower = 200;
  } 45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn
  this.cannon._rotation = angle*-1;
  };
  function onMouseDown() {
  angle = tank.cannon._rotation-1
  start_ball_x = tank._x+48*Math.cos(angle*Math.PI/180);
  start_ball_y = tank._y+48*Math.sin(angle*Math.PI/180);
  attachMovie("cannonball", "cannonball", 3, {_x:start_ball_x, _y:start_ball_y});
  }

(阅读次数:

返回顶部
共2页: 上一页 1 [2] 下一页  

网友评论

[以下评论为网友观点,不代表本站。请自觉遵守互联网相关政策法规,所有连带责任均有评论者自负。]
[不超过250字]

热门文章