主要是利用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 第二步:绘制一个坦克,分成两部分,如下面:
IT资讯之家 www.it55.com

绘制坦克
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
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
然后是计算开火的目标:
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}); }
(阅读次数:)
Copyright © Www.IT55.Com Powered By 易网发科技有限公司
中国信产部备案号:陇ICP备05004709号
重构支持QQ:47902882
|