Link:INB Home|INB English| INB русский язык|INB العربية|INB Türkiye|INB فارسی|INB Español|INB Français|INB Português|INB Deutsch|INB 國語|INB 中文|INB 日本语|INB 한국어|INB ภาษาไทย|INB tiếng Việt||FL 教程Flash 由淺入深學習Flash設計高射炮游戲(續)
INB 國語論壇
歡迎光臨(工業與草根研究員)對工業時代充滿了戰鬥精神,你和我都通過網絡空間與當地草根精神研究員來到瘋狂實驗室。家inbforum.com,永久名稱:tw-inbforum.forums2u.com
INB 國語論壇
歡迎光臨(工業與草根研究員)對工業時代充滿了戰鬥精神,你和我都通過網絡空間與當地草根精神研究員來到瘋狂實驗室。家inbforum.com,永久名稱:tw-inbforum.forums2u.com
INB 國語論壇

歡迎光臨(工業與草根研究員)對工業時代充滿了戰鬥精神,你和我都通過網絡空間與當地草根精神研究員來到瘋狂實驗室。家inbforum.com,永久名稱:tw-inbforum.forums2u.com


您沒有登錄。 請登錄註冊

《《《《《《《上一页INBforum   向下

上一页INBforum》》》》》》》上一篇主題 下一篇主題 向下  內容 [第1頁(共1頁)]

1FL 教程Flash 由淺入深學習Flash設計高射炮游戲(續) Empty FL 教程Flash 由淺入深學習Flash設計高射炮游戲(續) 周四 3月 03, 2011 7:04 pm

Admin

Admin
Admin
接著上篇:我們設計一個完整的游戲。

  上篇講到了,可以設置一定角度發炮彈了!這時接著做,首先我們把炮彈去掉,只要炮彈出來舞臺左、右和下我們就將該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();
}
};
}

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








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


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--;
}
};
}
}

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








  在舞臺上加上一個地面。


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();
}
};
}

  最終簡單游戲:








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

http://tw.inbforum.com

2FL 教程Flash 由淺入深學習Flash設計高射炮游戲(續) Empty 回復: FL 教程Flash 由淺入深學習Flash設計高射炮游戲(續) 周二 3月 10, 2015 12:20 am

tutuqwe


溪頭大富華森林會館
[您必需注冊登錄才能查看本鏈接。]
1.溪頭民宿,溪頭住宿推薦
[您必需注冊登錄才能查看本鏈接。]
2.妖怪村民宿,妖怪村住宿
[您必需注冊登錄才能查看本鏈接。]
3.妖怪村客房介紹
[您必需注冊登錄才能查看本鏈接。]
4.妖怪村民宿環境設施
[您必需注冊登錄才能查看本鏈接。]
5.妖怪村住宿地圖導覽
[您必需注冊登錄才能查看本鏈接。]
6.溪頭熱門旅游景點介紹
[您必需注冊登錄才能查看本鏈接。]

氬焊機
堆高機
電動車
推高機
拖板車
物料架
料架
led招牌
字幕機
電視牆
跑馬燈
廣告招牌
花蓮民宿
花蓮民宿
金門租車
金門旅遊
超音波熔接機
超音波熔接機
台北搬家
台北搬家]

http://www.songf.com.tw

上一页INBforum   向下

上一页INBforum上一篇主題 下一篇主題 回頂端  內容 [第1頁(共1頁)]

這個論壇的權限:
無法 在這個版面回復文章

Copyright ©2009-2010 LTD Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

IT:SINGLESERVGoogle谷歌翻译TranslateFORUMSOFTLAYERGoogle谷歌广告联盟AdSenseAsia

 

Free forum | 汽車 | Tuning | ©phpBB | 免費論壇互助中心 | 違法舉報 | Latest discussions