为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

[练习]由浅入深学习Flash制作高射炮游戏

2017-09-21 10页 doc 34KB 10阅读

用户头像

is_963767

暂无简介

举报
[练习]由浅入深学习Flash制作高射炮游戏[练习]由浅入深学习Flash制作高射炮游戏 由浅入深学习Flash制作高射炮游戏 主要是利用Flash Actionscript一步一步学习Flash高射炮简单游戏的制作过程,最终效果只是一个简单的演示,如果你有兴趣可以继续深入学习~ 开篇前,先把所有的演示动画的源程序提供给大家: 点击这里下载本教程中所有演示动画的源文件(解压密码:www.webjx.com) 第一步:首先简单的制作一个鼠标动画,绘制一个鼠标的图,自己定。然后选择第一帧输入下面代码: Mouse.hide(); attachMovie("cros...
[练习]由浅入深学习Flash制作高射炮游戏
[练习]由浅入深学习Flash制作高射炮游戏 由浅入深学习Flash制作高射炮游戏 主要是利用Flash Actionscript一步一步学习Flash高射炮简单游戏的制作过程,最终效果只是一个简单的演示,如果你有兴趣可以继续深入学习~ 开篇前,先把所有的演示动画的源程序提供给大家: 点击这里下载本教程中所有演示动画的源文件(解压密码:www.webjx.com) 第一步:首先简单的制作一个鼠标动画,绘制一个鼠标的图,自己定。然后选择第一帧输入下面代码: Mouse.hide(); attachMovie("crosshair", "crosshair", 1); crosshair.onEnterFrame = function() { this._x = _xmouse; this._y = _ymouse; }; 效果如下: 第二步:绘制一个坦克,分成两部分,如下面: 把下面的命名实例名为tank 代码如下: 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; }; 效果(无角度限制): 第三步:我这里设置转动的一定的角度。 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; }; 效果如下: 然后是计算开火的目标: 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; }; 开火的制作: 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; }; 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}); } 效果如下: 开火出来炮弹: 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; }; 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); cannonball_fired = attachMovie("cannonball", "cannonball_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y}); cannonball_fired.dirx = Math.cos(angle*Math.PI/180)*firepower; cannonball_fired.diry = Math.sin(angle*Math.PI/180)*firepower; cannonball_fired.onEnterFrame = function() { this._x += this.dirx/50; this._y += this.diry/50; }; } 效果如下: 最后再加以详细的限制一下炮弹: Mouse.hide(); gravity = 2; 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; }; 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); cannonball_fired = attachMovie("cannonball", "cannonball_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y}); cannonball_fired.dirx = Math.cos(angle*Math.PI/180)*firepower; cannonball_fired.diry = Math.sin(angle*Math.PI/180)*firepower; cannonball_fired.onEnterFrame = function() { this.diry += gravity; this._x += this.dirx/50; this._y += this.diry/50; }; } 效果如下:
/
本文档为【[练习]由浅入深学习Flash制作高射炮游戏】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索