 |
教程: Flash教程-Flash游戏实例教程-飞机游戏 |
 |
|
|
| 教程: Flash教程-Flash游戏实例教程-飞机游戏 |
|
|
|
|
点击浏览该文件 方向键 控制上下左右 ctrl-----发射键 dead后,按SPACE(空格键)重新开始。 //以下是游戏中所有的代码,就一针,至于元件都是自己涂的。元件都在库中,分别是子弹,飞机,敌人,火花。
init(); function init() function Var() { stage_width = 300; stage_height = 300; _root.createTextField("h_num", 1000, 5, 25, 100, 20); num_format = new TextFormat(); num_format.color = 0xb8e0f0; h_num.text = "击倒" 0; h_num.type = "dynamic"; h_num.border = true; h_num.borderColor = 0xffffff; h_num.color = 0xffffff; h_num.setTextFormat(num_format); h_num.autoSize = "left"; i = 1; fire_num = 1; hit_num = 0; life._xscale = 100; } function set_fly() { _root.attachMovie("fly", "fly", 0);//调库中的飞机 fly._xscale = fly._yscale=150; fly._x = 150; fly._y = 250; } function control() { if (Key.isDown(Key.LEFT)) { fly._x -= 5; } if (Key.isDown(Key.UP)) { fly._y -= 5; } if (Key.isDown(Key.RIGHT)) { fly._x = 5; } if (Key.isDown(Key.DOWN)) { fly._y = 5; } } function Range(mc) { if (mc._x<=mc._width/2) { mc._x = mc._width/2; } if (mc._x>=stage_width-mc._width/2) { mc._x = stage_width-mc._width/2; } if (mc._y>=stage_height-mc._height/2) { mc._y = stage_height-mc._height/2; } if (mc._y<=mc._height/2) { mc._y = mc._height/2; } } function shoot(arg) { if (fly != undefined) { bulletSpeed = 10; if (Key.isDown(Key.CONTROL)) { if (i>40) { i = 1; } down = 1; Bullet = _root.attachMovie("bullet", "bullet" i, i );//调库中的子弹 Bullet._x = fly._x; Bullet._y = fly._y-20; Bullet._rotation = 90-arg; arg = arg/180*Math.PI; Bullet.xinc = Math.cos(arg)*bulletSpeed; Bullet.yinc = Math.sin(arg)*bulletSpeed; Bullet.onEnterFrame = function() { for (k=1; k<=11; k ) { if (this.hitTest(_root["enemy" k])) { hit_num ; h_num.text = "击倒" hit_num; h_num.setTextFormat(num_format); Fire = _root.attachMovie("fire", "fire" fire_num, 2000 fire_num); if (fire>100) { fire = 1; } Fire._x = this._x; Fire._y = this._y; _root["enemy" k].removeMovieClip(); this.removeMovieClip(); delete this.onEnterFrame; } } if (this._y<0 or this._x<0 or this._x>stage_width) { removeMovieClip(this); delete this.onEnterFrame; } this._x = this.xinc; this._y -= this.yinc; }; } } } function Trans() { interval = 1; enemy_num = 1; enemy_speed = 5; enemy_time = 0; onEnterFrame = function () { control(); Range(fly); if ( enemy_time>15) { enemy_time = 0; if (enemy_num>10) { enemy_num = 1; } Enemy = _root.attachMovie("enemy", "enemy" enemy_num, 400 enemy_num ); //调库中的敌人 temp_fly_x = fly._x; temp_fly_y = fly._y; aa = x_y_random(); Enemy._x = aa[0]; Enemy._y = aa[1]; if (fly == undefined) { Enemy.radia = Math.atan2(300-Enemy._y, random(300)-Enemy._x); } else { Enemy.radia = Math.atan2(temp_fly_y-Enemy._y, temp_fly_x-Enemy._x); } Enemy.onEnterFrame = function() { this._rotation = 20; if (this.hitTest(fly.f_fly._fly)) { Fire = _root.attachMovie("fire", "fire" fire_num, 500 fire_num);//调库中的火花 Fire._xscale = Fire._yscale=50; Fire._x = this._x; Fire._y = this._y; this.removeMovieClip(); life._xscale -= 4; if (life._xscale<=0) fly.play(); } if (this._x<0 or this._x>stage_width or this._y>stage_height or this._y<0) { this.removeMovieClip(); delete this.onEnterFrame; } // this._rotation = 10; this._x = enemy_speed*Math.cos(this.radia); this._y = enemy_speed*Math.sin(this.radia); }; } if (down) { interval ; if (interval>10) { interval = 1; j = 50; while ((j = 15)<=130) } } else { j = 50; while ((j = 15)<=130) } }; } function x_y_random() { var s = []; var ran = random(3); switch (ran) { case 0 : s[0] = random(300); s[1] = 0; break; case 1 : s[0] = 0; s[1] = random(300); break; case 2 : s[0] = 300; s[1] = random(300); break; } return s; } function key_col() { _root.onKeyUp = function() { down = 0; }; _root.onKeyDown = function() { if (Key.isDown(Key.SPACE)) { if (fly == undefined) { for (var i = 1; i<=40; i ) Var(); set_fly(); Trans(); } } }; Key.addListener(_root); }
|
|
| 教程录入:admin 责任编辑:admin |
|
|
上一篇教程: 教程: Flash教程-Flash游戏实例教程-枪战游戏基础制作
下一篇教程: 教程: Flash教程-Flash游戏实例教程-一个简单的子弹跟踪弹算法 |
|
|
|
|
|
|
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|
|
|
|