欢迎大家光临【无师自通-教程网】您的到来是我们的荣幸。本站提供photoshop教程,ps教程,flash教程,cad教程,网页制作教程,excel教程,asp教程,vb教程,3d教程,c语言教程,html教程,coreldraw教程,dreamweaver教程,java教程,3dmax教程 等各种教程为主题的内容和服务,相信您会在这里找到您所需要的东东。无师自通伴您一生-谢谢您的光临!!
网站地图 设为首页
简繁切换 加入收藏
栏目待定 留言本站
您现在的位置: 无师自通-教程网 >> 多媒体动画 >> Flash教程 >> Flash游戏实例教程 >> 教程正文

  没有公告

教程: 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 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     
     
     
     

    3DsMAX实例制作:三维玻璃灯泡

    3dmax在线教程--蝴蝶

    3ds max时尚水晶鞋

    精彩Flash制作风吹草动效果动画

    教程: 3DS Max-设计实例-三维虚拟…

    3dmax7.0教程--火焰特效

    绘画技巧:Flash绘制人头造型

    3ds max 室内设计---室内效果图
    免责声明!本站资料大部分来自于互联网,其版权归原作者或其他合法者所有.如内容涉及或侵犯了您的权益,请通知本人,我将尽快处理!.欢迎您的光临。
    辽ICP备07003958号
    无师自通,伴你一生-教程网