台灣最大程式設計社群網站
線上人數
2046
 
會員總數:246319
討論主題:189850
歡迎您免費加入會員
討論區列表 >> CSS/HTML5/Bootstarp >> flash cs5 接水果遊戲改寫問題?
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
flash cs5 接水果遊戲改寫問題?
價值 : 10 QP  點閱數:3465 回應數:4
樓主

213
門外漢
0 1
27 2
發送站內信

接水果遊戲改寫

新增水果計分功能

例如接到香蕉5分 接到蘋果10分 顯示在遊戲上面 只要分數累計就好 不需個別分數

下面是程式碼和檔案

請問如何改寫

var fruitArray:Array = new Array(Apple,Strawberry,Pear,Banana,Orange);
var fruitsOnstage:Array = new Array();
var fruitsCollected:int = 0;
var fruitsLost:int = 0;

for (var i:int = 0; i<20; i++) {
var pickFruit = fruitArray[int(Math.random() * fruitArray.length)];
var fruit:MovieClip = new pickFruit();
addChild(fruit);
fruit.x = Math.random() * stage.stageWidth-fruit.width;// fruit.width is subtracted from the random x position to elimate the slight possibility that a clip will be placed offstage on the right.
fruit.y = Math.random() * -500;
fruit.speed = Math.random() * 15 + 5;
fruitsOnstage.push(fruit);
}

basket_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragBasket);
stage.addEventListener(MouseEvent.MOUSE_UP, dragStop);


function dragBasket(e:Event):void {
basket_mc.startDrag();
}

function dragStop(e:Event):void {
basket_mc.stopDrag();
}

stage.addEventListener(Event.ENTER_FRAME, catchFruit);

function catchFruit(e:Event):void {

for (var i:int = fruitsOnstage.length-1; i > -1; i--) {
var currentFruit:MovieClip = fruitsOnstage[i];
currentFruit.y += currentFruit.speed;
if (currentFruit.y > stage.stageHeight - currentFruit.height) {
currentFruit.y = 0 - currentFruit.height;
fruitsLost++;
field2_txt.text = "Total Fruit Lost: " + fruitsLost;
}

if (currentFruit.hitTestObject(basket_mc)) {
fruitsCollected++;
removeChild(currentFruit);
fruitsOnstage.splice(i,1);
field1_txt.text = "Total Fruit Collected: " + fruitsCollected;
if (fruitsCollected >= 20) {
basket_mc.gotoAndStop(20);
} else if (fruitsCollected > 15) {
basket_mc.gotoAndStop(15);
} else if (fruitsCollected>10) {
basket_mc.gotoAndStop(10);
} else if (fruitsCollected>5) {
basket_mc.gotoAndStop(5);
}
}
}

if (fruitsOnstage.length <= 0) {
field1_txt.text = "You Win! You have collected enough fruit for dinner.";
field2_txt.text = "";
stage.removeEventListener(Event.ENTER_FRAME, catchFruit);
}
if (fruitsLost >= 20) {
field1_txt.text = "Sorry you lose. You have lost too much fruit!";
field2_txt.text = "";
stage.removeEventListener(Event.ENTER_FRAME, catchFruit);
for (var j:int = fruitsOnstage.length-1; j > -1; j--) {
currentFruit = fruitsOnstage[j];
removeChild(currentFruit);
fruitsOnstage.splice(j,1);
}
}

}

程式碼檔案
http://filedeck.net/zh-tw/files/1HFIXX8F/Complete.rar

flash cs5 免安裝 下載
http://uploading.com/files/fma548m2/A485c.rar/




搜尋相關Tags的文章: [ flash ] , [ 遊戲 ] ,
本篇文章發表於2011-12-18 22:37
1樓
回應

ahsac
檢舉此回應
請自行排版, 或下次記得用語言標籤放你的程式

var fruitArray:Array = new Array(Apple,Strawberry,Pear,Banana,Orange);
var fruitScore:Array = new Array( 1, 2, 3, 4, 5);
var fruitsOnstage:Array = new Array();
var fruitsCollected:int = 0;
var fruitsLost:int = 0;

for (var i:int = 0; i<20; i++) {
var fruitIndex = int(Math.random() * fruitArray.length);
var pickFruit = fruitArray[fruitIndex];
var fruit:MovieClip = new pickFruit();
addChild(fruit);
fruit.score = fruitScore[fruitIndex];
fruit.x = Math.random() * stage.stageWidth-fruit.width;// fruit.width is subtracted from the random x position to elimate the slight possibility that a clip will be placed offstage on the right.
fruit.y = Math.random() * -500;
fruit.speed = Math.random() * 15 + 5;
fruitsOnstage.push(fruit);
}

basket_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragBasket);
stage.addEventListener(MouseEvent.MOUSE_UP, dragStop);


function dragBasket(e:Event):void {
basket_mc.startDrag();
}

function dragStop(e:Event):void {
basket_mc.stopDrag();
}

stage.addEventListener(Event.ENTER_FRAME, catchFruit);

function catchFruit(e:Event):void {

for (var i:int = fruitsOnstage.length-1; i > -1; i--) {
var currentFruit:MovieClip = fruitsOnstage[i];
currentFruit.y += currentFruit.speed;
if (currentFruit.y > stage.stageHeight - currentFruit.height) {
currentFruit.y = 0 - currentFruit.height;
fruitsLost++;
field2_txt.text = "Total Fruit Lost: " + fruitsLost;
}

if (currentFruit.hitTestObject(basket_mc)) {
fruitsCollected+=currentFruit.score;
removeChild(currentFruit);
fruitsOnstage.splice(i,1);
field1_txt.text = "Total Fruit Collected: " + fruitsCollected;
if (fruitsCollected >= 20) {
basket_mc.gotoAndStop(20);
} else if (fruitsCollected > 15) {
basket_mc.gotoAndStop(15);
} else if (fruitsCollected>10) {
basket_mc.gotoAndStop(10);
} else if (fruitsCollected>5) {
basket_mc.gotoAndStop(5);
}
}
}

if (fruitsOnstage.length <= 0) {
field1_txt.text = "You Win! You have collected enough fruit for dinner.";
field2_txt.text = "";
stage.removeEventListener(Event.ENTER_FRAME, catchFruit);
}
if (fruitsLost >= 20) {
field1_txt.text = "Sorry you lose. You have lost too much fruit!";
field2_txt.text = "";
stage.removeEventListener(Event.ENTER_FRAME, catchFruit);
for (var j:int = fruitsOnstage.length-1; j > -1; j--) {
currentFruit = fruitsOnstage[j];
removeChild(currentFruit);
fruitsOnstage.splice(j,1);
}
}

}
本篇文章回覆於2011-12-18 23:32
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
作者回應

213
檢舉此回應
感謝ahsac解答 下次會注意程式碼語言標籤
本篇文章回覆於2011-12-20 00:02
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
3樓
作者回應

213
檢舉此回應
可以大概解釋一下 程式碼的意思嗎 感謝
本篇文章回覆於2011-12-20 00:21
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
4樓
回應

ahsac
檢舉此回應
哪個部份?
本篇文章回覆於2011-12-20 00:46
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.