日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

由淺入深學習Flash制作高射炮游戲(續(xù))_Flash教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:入門:Flash制作圖片爆炸效果動畫
入門教程,非常簡單,只是讓大家知道Flash里面有時間軸特效,要學會應用��!動畫效果就是快速顯示幾張圖片,最后使他們一起散開,類似爆炸效果。效果如下。點

  接著上篇:我們制作一個完整的游戲。

  上篇講到了,可以設置一定角度發(fā)炮彈了!這時接著做,首先我們把炮彈去掉,只要炮彈出來舞臺左、右和下我們就將該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) {
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/30;
this._y = this.diry/30;
if ((this._x<0) or (this._x>500) or (this._y>350)) {
this.removeMovieClip();
}
};
}

  效果(速度明顯變快了):

  然后再繼續(xù)完善,設置同一時間開火的次數(shù)。

Mouse.hide();
gravity = 2;
fired = 0;
max_firepower = 3;
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() {
if (fired fired ;
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._y>350) {
this.removeMovieClip();
fired--;
}
};
}
}

  效果(你這時連續(xù)按鼠標試試!)

  在舞臺上加上一個地面。

Mouse.hide();
gravity = 2;
fired = 0;
max_firepower = 3;
attachMovie("crosshair", "crosshair", 1);
attachMovie("tank", "tank", 2, {_x:295, _y:255});
attachMovie("ground", "ground", 3, {_x:0, _y:200});
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() {
if (fired fired ;
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._y>350) or (ground.hitTest(this._x, this._y, true))) {
this.removeMovieClip();
fired--;
}
};
}
}

  效果如下:

  然后再加上一個敵人。

Mouse.hide();
gravity = 2;
fired = 0;
max_firepower = 3;
place_enemy();
attachMovie("crosshair", "crosshair", 1);
attachMovie("tank", "tank", 2, {_x:295, _y:255});
attachMovie("ground", "ground", 3, {_x:0, _y:200});
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() {
if (fired fired ;
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._y>350) or (ground.hitTest(this._x, this._y, true))) {
this.removeMovieClip();
fired--;
}
};
}
}
function place_enemy() {
enemy_placed = attachMovie("enemy", "enemy", _root.getNextHighestDepth(), {_x:0, _y:350});
enemy_placed.yspeed = 0;
enemy_placed.onEnterFrame = function() {
this.yspeed = gravity/10;
this._x ;
while (_root.ground.hitTest(this._x this._width/2, this._y this._height, true)) {
this._y--;
this.yspeed = 0;
}
if (!_root.ground.hitTest(this._x this._width/2, this._y this._height 1, true)) {
this._y = this.yspeed;
} else {
this.yspeed = 0;
}
if (this._x>500) {
this.removeMovieClip();
place_enemy();
}
};
}

  效果如下:

  最后完成。

Mouse.hide();
gravity = 2;
fired = 0;
max_firepower = 3;
place_enemy();
attachMovie("crosshair", "crosshair", 1);
attachMovie("tank", "tank", 2, {_x:295, _y:255});
attachMovie("ground", "ground", 3, {_x:0, _y:200});
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() {
if (fired fired ;
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._y>350) or (ground.hitTest(this._x, this._y, true))) {
this.removeMovieClip();
fired--;
}
if (enemy.hitTest(this._x, this._y, true)) {
this.removeMovieClip();
enemy.removeMovieClip();
fired--;
place_enemy();
}
};
}
}
function place_enemy() {
enemy_placed = attachMovie("enemy", "enemy", _root.getNextHighestDepth(), {_x:0, _y:350});
enemy_placed.yspeed = 0;
enemy_placed.onEnterFrame = function() {
this.yspeed = gravity/10;
this._x ;
while (_root.ground.hitTest(this._x this._width/2, this._y this._height, true)) {
this._y--;
this.yspeed = 0;
}
if (!_root.ground.hitTest(this._x this._width/2, this._y this._height 1, true)) {
this._y = this.yspeed;
} else {
this.yspeed = 0;
}
if (this._x>500) {
this.removeMovieClip();
place_enemy();
}
};
}

  最終簡單游戲:

  本教程中所用到所有源文件下載:點擊這里下載源文件

分享:Flash制作的好看的圖片效果動畫
看效果:代碼如下:varold:Number=1;//記錄上張顯示的圖片varoldGo:Boolean;varoldpos:Number=700;varpicNum:Number=9;//anliPath是用于加載

/所屬分類:Flash教程/更新時間:2008-03-05
相關Flash教程