天天看點

flash飛機遊戲

方向鍵 控制上下左右 ctrl-----發射鍵 dead後,按SPACE(空格鍵)重新開始。

-------------如果轉載請注明“寒冰制作”----------

--------------雖然很垃圾,但是也是我的心血

//以下是遊戲中所有的代碼,就一針,至于元件都是自己塗的。元件都在庫中,分别是子彈,飛機,敵人,火花。

init();function init() {

black.swapDepths(4000);

Var();

set_fly();

Trans();

key_col();

}

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=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._y40) {

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; k100) {

fire = 1;

}

Fire._x = this._x;

Fire._y = this._y;

_root["enemy"+k].removeMovieClip();

this.removeMovieClip();

delete this.onEnterFrame;

}

}

if (this._ystage_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._xscalestage_width or this._y>stage_height or this._y10) {

interval = 1;

j = 50;

while ((j += 15)

本文轉自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/851.html

繼續閱讀