由浅入深学习Flash制作高射炮游戏(2)

[1b]接上篇:[/1b]
[url=http://www2.flash8.net/teach/5990.htm][1b]由浅入深学习Flash制作高射炮游戏[/1b][/url]
[1b] ,我们来完成这个的游戏。[/1b]
上篇讲到了,可以设置一定角度发炮弹了!这时接着做,首先我们把炮弹去掉,只要炮弹出来舞台左、右和下我们就将该MC去掉。代码:
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 && mousey160) {
        angle = 160;
    }
    if (angle200) {
        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/30;
        this._y += this.diry/30;
        if ((this._x500) or (this._y>350)) {
            this.removeMovieClip();
        }
    };

 
效果(速度明显变快了):
然后再继续完善,设置同一时间开火的次数。
Mouse.hide();
gravity = 2;
fired = 0;
max_firepower = 3;
本文转自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/970.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值