首页--> 计算机--> FLASH教程
 
由浅入深学习Flash制作高射炮游戏
http://www.xxqqss.com 学习轻松网 发布日期:2007/5/9 点击量:5248
 
主要是利用Flash Actionscript一步一步学习Flash高射炮简单游戏的制作过程,最终效果只是一个简单的演示,如果你有兴趣可以继续深入学习!开篇前,先把所有的演示动画的源程序提供给大家:点击这里下载本教程中所有演示动画的源文件

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

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;
    };

效果如下:



来源:网页教学网  作者:闪电儿


打印】 【关闭
免责声明 :本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请发送fiyeadwyv@163.com
【免费游戏赚钱网址导航】(站长QQ:9792414)多站号请误用相同密码 【站长信箱】幸运28交流群号:122287647
游戏赚钱平台
注册地址
企业/个人
企业
 有赚网与蹦蹦网是深度合作关系
企业
手机app端赚钱名称
下载安装后输入邀请码领额外红包
估计日赚收入(亲体验)
下载方式
闪电盒子
邀请码:413270540831
3元
 安卓手机各应用市场(推荐应用宝),苹果手机输入名称查找。
中青看点
邀请码:25741975
2元
趣头条
邀请码:A443657406
1元
 
健康游戏忠告:抵制不良游戏,拒绝盗版游戏;注意自我保护,谨防受骗上当;适度游戏益脑,沉迷游戏伤身;合理安排时间,享受健康生活。
本站声明不参与任何游戏网站经营事宜,如果你和第三方游戏网站产生纠纷事宜请自行协商解决,本站感谢你的支持和理解。
站长QQ:9792414