最後修正,加上結束畫面
最終程式碼:
PImage[] monsters = new PImage[5]; // 建立怪物陣列 int totalMonsters = 0; int maxMonsters = 8; int[] monsterX = new int[maxMonsters]; int[] monsterY = new int[maxMonsters]; int[] monsterMotion = new int[maxMonsters]; int[] restTimers = new int[maxMonsters]; // 每個怪物的休息時間計數器 int[] moveTimers = new int[maxMonsters]; // 每個怪物的移動時間計數器 int[] moveDirections = new int[maxMonsters]; // 每個怪物的移動方向 float totalTime = 4; // 計時總時間(秒) import processing.sound.*; SoundFile file, file2,file3; PFont myFont; int playertype='5'; int player1motion='0'; int player2motion='0'; int state=0; PImage one, pika, pikayou, start, player1, player2, grass, bigdick, prepare, ball, b25; PImage player1front, player1back, player1left, player1right; PImage player2front, player2back, player2left, player2right; int phealth = 100;//玩家血條 int mhealth = 100;//怪物血條 int xPos, yPos; int elapsedTime ; int remainingTime ; void setup() { file=new SoundFile(this, "pokemon.mp3"); file2=new SoundFile(this, "attack.mp3"); file3=new SoundFile(this,"good.mp3"); file.play(); file.loop(); size(1000, 700); myFont = createFont("標楷體", 100); textFont(myFont); one = loadImage("one.png"); pika=loadImage("pika.png"); start=loadImage("start.png"); player1=loadImage("player1.png"); player2=loadImage("player2.png"); grass=loadImage("grass.png"); player1front=loadImage("player1front.png"); player1back=loadImage("player1back.png"); player1left=loadImage("player1left.png"); player1right=loadImage("player1right.png"); player2front=loadImage("player2front.png"); player2back=loadImage("player2back.png"); player2left=loadImage("player2left.png"); player2right=loadImage("player2right.png"); bigdick=loadImage("bigdick.png"); monsters[0] = loadImage("monster1.png"); monsters[1] = loadImage("monster2.png"); monsters[2] = loadImage("monster3.png"); monsters[3] = loadImage("monster4.png"); monsters[4] = loadImage("monster3-1.png"); pikayou=loadImage("pikayou.png"); prepare=loadImage("prepare.jpg"); ball=loadImage("ball.png"); b25=loadImage("25.png"); xPos= width / 2; yPos= height / 2; for (int i = 0; i < maxMonsters; i++) { restTimers[i] = int(random(60, 180)); // 設定每個怪物的休息時間,範圍為60到180幀 moveTimers[i] = int(random(30, 60)); // 設定每個怪物的移動時間,範圍為30到60幀 moveDirections[i] = int(random(4)); // 設定每個怪物的初始移動方向 moveMonster(i); } } void draw() { if (state==15) { totalTime-=0.02; } if (state==0) {//封面 image(one, 0, 0); image(pika, 350, 150); image(start, 365, 430); textSize(40); fill(255); rect(880, 15, 80, 45); fill(255, 0, 0); text("說明", 880, 50); text("左鍵繼續", 800, 680); textSize(70); fill(0); text("寶可夢大師", 320, 100); //textSize(30);fill(255,0,0);text("滑鼠左鍵操控",380,570); } else if (state==1) {//選角色 image(one, 0, 0);//background(232,222,33); textSize(40); fill(255, 0, 0); text("右鍵返回", 800, 680); text("小凱", 280, 270); text("小賴", 630, 270); textSize(70); fill(0); text("選擇你的角色", 280, 150); image(player1, 180, 300);//rect(200,300,200,200); image(player2, 530, 300);//rect(550,300,200,200); } else if (state==2) {//說明 image(one, 0, 0); textSize(40); fill(255, 0, 0); text("右鍵返回", 800, 680); text("操作說明", 420, 175); fill(0); text("滑鼠:左鍵點擊,右鍵返回", 280, 250); text("鍵盤:WASD鍵控制角色移動", 280, 300); text("聲音:Z鍵暫停音樂,X鍵繼續撥放", 280, 350); text("(不要重複按,音樂會當掉)", 380, 400); } else if (state==3) {//player1場景 playertype='1'; image(prepare, 0, 0); fill(0); text("歡迎來到寶可夢世界,我是大木博士,\n這是初次見面禮,請收下你的皮卡丘,\n希望你可以幫我捕捉一隻寶可夢回來\n當作是給你皮卡丘的任務^_^。", 180, 120); textSize(40); fill(255, 0, 0); text("右鍵返回", 800, 680); image(bigdick, xPos+50, yPos-25); image(pikayou, xPos+50, yPos-55); image(start, 365, 480); } else if (state==4) {//player2場景 playertype='2'; image(prepare, 0, 0); fill(0); text("歡迎來到寶可夢世界,我是大木博士,\n這是初次見面禮,請收下你的皮卡丘,\n希望你可以幫我捕捉一隻寶可夢回來\n當作是給你皮卡丘的任務^_^。", 180, 120); image(bigdick, xPos+50, yPos-25); image(pikayou, xPos+50, yPos-55); image(start, 365, 480); textSize(40); fill(255, 0, 0); text("右鍵返回", 800, 680); } else if (state==5) {//player1遊戲畫面 image(grass, 0, 0); if (keyPressed) { if (key=='w') { yPos -= 10; player1motion='1'; } if (key=='s') { yPos += 10; player1motion='0'; } if (key=='a') { xPos -= 10; player1motion='2'; } if (key=='d') { xPos += 10; player1motion='3'; } } if (player1motion=='0') { image(player1front, xPos-25, yPos-25, 45, 45); } if (player1motion=='1') { image(player1back, xPos-25, yPos-25, 30, 40); } if (player1motion=='2') { image(player1left, xPos-25, yPos-25, 40, 40); } if (player1motion=='3') { image(player1right, xPos-25, yPos-25, 40, 40); } for (int i = 0; i < totalMonsters; i++) { moveMonster(i); drawMonster(i); } // 當怪物總數小於最大值時,生成新的怪物 if (totalMonsters < maxMonsters) { generateMonster(); } delay(50); for (int i = 0; i < totalMonsters; i++) { if (dist(xPos, yPos, monsterX[i], monsterY[i]) < 50) { // 根據不同的怪物進入相對應的戰鬥畫面 if (i == 0||i==5) { state = 7; // 進入 state8 戰鬥畫面 file.stop(); file2.play(); file2.loop(); } else if (i == 1||i==6) { state = 8; // 進入 state9 戰鬥畫面 file.stop(); file2.play(); file2.loop(); } else if (i == 3) { state = 9; // 進入 state10 戰鬥畫面 file.stop(); file2.play(); file2.loop(); } else if (i == 2||i== 4||i==7) { state = 10; // 進入 state11 戰鬥畫面 file.stop(); file2.play(); file2.loop(); } removeMonster(i); break; } } } else if (state==6) {//player2遊戲畫面 playertype='2'; background(255); image(grass, 0, 0); if (keyPressed) { if (key=='w') { player2motion='1'; yPos -= 10; } if (key=='s') { player2motion='0'; yPos += 10; } if (key=='a') { player2motion='2'; xPos -= 10; } if (key=='d') { player2motion='3'; xPos += 10; } } if (player2motion=='0') { image(player2front, xPos-25, yPos-25, 35, 45); } if (player2motion=='1') { image(player2back, xPos-25, yPos-25, 35, 40); } if (player2motion=='2') { image(player2left, xPos-25, yPos-25, 40, 40); } if (player2motion=='3') { image(player2right, xPos-25, yPos-25, 40, 40); } for (int i = 0; i < totalMonsters; i++) { moveMonster(i); drawMonster(i); } // 當怪物總數小於最大值時,生成新的怪物 if (totalMonsters < maxMonsters) { generateMonster(); } delay(50); for (int i = 0; i < totalMonsters; i++) { if (dist(xPos, yPos, monsterX[i], monsterY[i]) < 50) { // 根據不同的怪物進入相對應的戰鬥畫面 if (i == 0||i==5) { state = 11; // 進入 state8 戰鬥畫面 file.stop(); file2.play(); file2.loop(); } else if (i == 1||i==6) { state = 12; // 進入 state9 戰鬥畫面 file.stop(); file2.play(); file2.loop(); } else if (i == 3||i==7) { state = 13; // 進入 state10 戰鬥畫面 file.stop(); file2.play(); file2.loop(); } else if (i == 2||i== 4) { state = 14; // 進入 state11 戰鬥畫面 file.stop(); file2.play(); file2.loop(); } removeMonster(i); break; // 碰到一個怪物即可進入對戰畫面,結束迴圈 } } } else if (state==7) {//皮卡丘vs妙蛙種子 background(255); if (mhealth<40) { fill(255, 0, 0); text("捕捉", 400, 280); } fill(191, 185, 185); rect(150, 480, 450, 150); fill(255, 0, 0); text("背包", 750, 530); text("逃跑", 750, 600); fill(0); text("皮卡丘", 600, 350); text("妙蛙種子", 150, 50); text("撞擊", 200, 530); text("十萬伏特", 400, 530); text("鐵尾", 200, 600); text("電光一閃", 400, 600); image(monsters[4], 120, 280, 180, 180); image(monsters[0], 700, 60, 180, 180); //血條 fill(255, 255, 255); rect(600, 365, 300, 30); rect(150, 65, 300, 30); float playerBarLength=map(phealth, 0, 100, 0, 300); float healthBarLength = map(mhealth, 0, 100, 0, 300); fill(255, 0, 0); rect(600, 365, playerBarLength, 30); rect(150, 65, healthBarLength, 30); } else if (state==8) {//皮卡丘vs小火龍 background(255); if (mhealth<40) { fill(255, 0, 0); text("捕捉", 400, 280); } fill(191, 185, 185); rect(150, 480, 450, 150); fill(255, 0, 0); text("背包", 750, 530); text("逃跑", 750, 600); fill(0); text("皮卡丘", 600, 350); text("小火龍", 150, 50); text("撞擊", 200, 530); text("十萬伏特", 400, 530); text("鐵尾", 200, 600); text("電光一閃", 400, 600); image(monsters[4], 120, 280, 180, 180); image(monsters[1], 700, 60, 180, 180); //血條 fill(255, 255, 255); rect(600, 365, 300, 30); rect(150, 65, 300, 30); float playerBarLength=map(phealth, 0, 100, 0, 300); float healthBarLength = map(mhealth, 0, 100, 0, 300); fill(255, 0, 0); rect(600, 365, playerBarLength, 30); rect(150, 65, healthBarLength, 30); } else if (state==9) {//皮卡丘vs杰尼龜 background(255); if (mhealth<40) { fill(255, 0, 0); text("捕捉", 400, 280); } fill(191, 185, 185); rect(150, 480, 450, 150); fill(255, 0, 0); text("背包", 750, 530); text("逃跑", 750, 600); fill(0); text("皮卡丘", 600, 350); text("杰尼龜", 150, 50); text("撞擊", 200, 530); text("十萬伏特", 400, 530); text("鐵尾", 200, 600); text("電光一閃", 400, 600); image(monsters[4], 120, 280, 180, 180); image(monsters[3], 700, 60, 180, 180); //血條 fill(255, 255, 255); rect(600, 365, 300, 30); rect(150, 65, 300, 30); float playerBarLength=map(phealth, 0, 100, 0, 300); float healthBarLength = map(mhealth, 0, 100, 0, 300); fill(255, 0, 0); rect(600, 365, playerBarLength, 30); rect(150, 65, healthBarLength, 30); } else if (state==10) {//皮卡丘vs皮卡丘 background(255); if (mhealth<40) { fill(255, 0, 0); text("捕捉", 400, 280); } fill(191, 185, 185); rect(150, 480, 450, 150); fill(255, 0, 0); text("背包", 750, 530); text("逃跑", 750, 600); fill(0); text("皮卡丘", 600, 350); text("皮卡丘", 150, 50); text("撞擊", 200, 530); text("十萬伏特", 400, 530); text("鐵尾", 200, 600); text("電光一閃", 400, 600); image(monsters[4], 120, 280, 180, 180); image(monsters[2], 700, 60, 180, 180); //血條 fill(255, 255, 255); rect(600, 365, 300, 30); rect(150, 65, 300, 30); float playerBarLength=map(phealth, 0, 100, 0, 300); float healthBarLength = map(mhealth, 0, 100, 0, 300); fill(255, 0, 0); rect(600, 365, playerBarLength, 30); rect(150, 65, healthBarLength, 30); } else if (state==11) {//皮卡丘vs妙蛙種子2 background(255); if (mhealth<40) { fill(255, 0, 0); text("捕捉", 400, 280); } fill(191, 185, 185); rect(150, 480, 450, 150); fill(255, 0, 0); text("背包", 750, 530); text("逃跑", 750, 600); fill(0); text("皮卡丘", 600, 350); text("妙蛙種子", 150, 50); text("撞擊", 200, 530); text("十萬伏特", 400, 530); text("鐵尾", 200, 600); text("電光一閃", 400, 600); image(monsters[4], 120, 280, 180, 180); image(monsters[0], 700, 60, 180, 180); //血條 fill(255, 255, 255); rect(600, 365, 300, 30); rect(150, 65, 300, 30); float playerBarLength=map(phealth, 0, 100, 0, 300); float healthBarLength = map(mhealth, 0, 100, 0, 300); fill(255, 0, 0); rect(600, 365, playerBarLength, 30); rect(150, 65, healthBarLength, 30); } else if (state==12) {//皮卡丘vs小火龍2 background(255); if (mhealth<40) { fill(255, 0, 0); text("捕捉", 400, 280); } fill(191, 185, 185); rect(150, 480, 450, 150); fill(255, 0, 0); text("背包", 750, 530); text("逃跑", 750, 600); fill(0); text("皮卡丘", 600, 350); text("小火龍", 150, 50); text("撞擊", 200, 530); text("十萬伏特", 400, 530); text("鐵尾", 200, 600); text("電光一閃", 400, 600); image(monsters[4], 120, 280, 180, 180); image(monsters[1], 700, 60, 180, 180); //血條 fill(255, 255, 255); rect(600, 365, 300, 30); rect(150, 65, 300, 30); float playerBarLength=map(phealth, 0, 100, 0, 300); float healthBarLength = map(mhealth, 0, 100, 0, 300); fill(255, 0, 0); rect(600, 365, playerBarLength, 30); rect(150, 65, healthBarLength, 30); } else if (state==13) {//皮卡丘vs杰尼龜2 background(255); if (mhealth<40) { fill(255, 0, 0); text("捕捉", 400, 280); } fill(191, 185, 185); rect(150, 480, 450, 150); fill(255, 0, 0); text("背包", 750, 530); text("逃跑", 750, 600); fill(0); text("皮卡丘", 600, 350); text("杰尼龜", 150, 50); text("撞擊", 200, 530); text("十萬伏特", 400, 530); text("鐵尾", 200, 600); text("電光一閃", 400, 600); image(monsters[4], 120, 280, 180, 180); image(monsters[3], 700, 60, 180, 180); //血條 fill(255, 255, 255); rect(600, 365, 300, 30); rect(150, 65, 300, 30); float playerBarLength=map(phealth, 0, 100, 0, 300); float healthBarLength = map(mhealth, 0, 100, 0, 300); fill(255, 0, 0); rect(600, 365, playerBarLength, 30); rect(150, 65, healthBarLength, 30); } else if (state==14) {//皮卡丘vs皮卡丘2 background(255); if (mhealth<40) { fill(255, 0, 0); text("捕捉", 400, 280); } fill(191, 185, 185); rect(150, 480, 450, 150); fill(255, 0, 0); text("背包", 750, 530); text("逃跑", 750, 600); fill(0); text("皮卡丘", 600, 350); text("皮卡丘", 150, 50); text("撞擊", 200, 530); text("十萬伏特", 400, 530); text("鐵尾", 200, 600); text("電光一閃", 400, 600); image(monsters[4], 120, 280, 180, 180); image(monsters[2], 700, 60, 180, 180); //血條 fill(255, 255, 255); rect(600, 365, 300, 30); rect(150, 65, 300, 30); float playerBarLength=map(phealth, 0, 100, 0, 300); float healthBarLength = map(mhealth, 0, 100, 0, 300); fill(255, 0, 0); rect(600, 365, playerBarLength, 30); rect(150, 65, healthBarLength, 30); } else if (state==15) { file2.stop(); background(0); fill(255, 0, 0); text("等待捕捉中", 500, 450); // 顯示剩餘時間 fill(0); textAlign(CENTER, CENTER); textSize(32); fill(255); text(floor(totalTime), width/2, height/2); // 檢查計時器是否結束 if (totalTime <=1) { state=16; totalTime=15; } } else if (state==16) {//捕捉 background(255); fill(255); rect(350, 480, 300, 40); fill(255, 0, 0); textSize(40); text("捕捉成功!!", 500, 100); text("回到找博士吧!!", 490, 500); //text("繼續捕捉", 490, 600); image(ball, 290, 100); } else if (state==17) {//回去找博士 image(b25, 0, 0); image(bigdick, 250, 200); fill(0); text("謝謝你的幫忙,祝你成為寶可夢大師^o^!!", 500, 120); fill(255); //rect(200, 530, 200, 40); rect(400, 530, 200, 40); fill(255, 0, 0); //text("重新開始", 300, 550); text("結束遊戲", 500, 550); } } void generateMonster() { int newMonsterX = int(random(50, 950)); int newMonsterY = int(random(50, 650)); monsterX[totalMonsters] = newMonsterX; monsterY[totalMonsters] = newMonsterY; monsterMotion[totalMonsters] = int(random(4)); totalMonsters++; } void moveMonster(int index) { if (restTimers[index] > 0) { restTimers[index]--; // 怪物正在休息中,不進行移動 } else { if (moveTimers[index] > 0) { moveTimers[index]--; // 怪物在選定方向移動中 int stepSize = 5; // 調整怪物移動的步數 // 根據移動方向移動怪物 if (moveDirections[index] == 0 && monsterY[index] > stepSize) { monsterY[index] -= stepSize; } else if (moveDirections[index] == 1 && monsterY[index] < height - stepSize) { monsterY[index] += stepSize; } else if (moveDirections[index] == 2 && monsterX[index] > stepSize) { monsterX[index] -= stepSize; } else if (moveDirections[index] == 3 && monsterX[index] < width - stepSize) { monsterX[index] += stepSize; } } else { // 重新選擇下一個移動方向和時間 moveDirections[index] = int(random(4)); moveTimers[index] = int(random(30, 60)); // 設定每個怪物的移動時間,範圍為30到60幀 restTimers[index] = int(random(60, 180)); // 設定每個怪物的休息時間,範圍為60到180幀 } } } void drawMonster(int index) { // 根據 monsterMotion[index] 繪製怪物圖像 // 請注意:這裡的程式碼會根據 monsterX[index] 和 monsterY[index] 繪製怪物圖像 // 您需要繪製怪物的圖像,並在適當的位置 monsterX[index] 和 monsterY[index] 上繪製它 // 示範: image(monsters[index % monsters.length], monsterX[index], monsterY[index], 50, 50); } void removeMonster(int index) { for (int i = index; i < totalMonsters - 1; i++) { monsterX[i] = monsterX[i + 1]; monsterY[i] = monsterY[i + 1]; monsterMotion[i] = monsterMotion[i + 1]; } totalMonsters--; } void mousePressed() { if (state==0) { if (dist(mouseX, mouseY, 460, 530)<40&&mouseButton==LEFT) { state=1; } if (dist(mouseX, mouseY, 900, 50)<40&&mouseButton==LEFT) { state=2; } } else if (state==1) { if (mouseButton == RIGHT) { state=0; } if (dist(mouseX, mouseY, 315, 400)<80&&mouseButton == LEFT) { playertype='1'; state=3; } if (dist(mouseX, mouseY, 670, 400)<80&&mouseButton == LEFT) { playertype='2'; state=4; } } else if (state==2) { if (mouseButton == RIGHT) { state=0; } } else if (state==3) { if (mouseButton == RIGHT) { state=1; } if (dist(mouseX, mouseY, 460, 560)<40&&mouseButton==LEFT) { state=5; } } else if (state==4) { if (mouseButton == RIGHT) { state=1; } if (dist(mouseX, mouseY, 460, 560)<40&&mouseButton==LEFT) { state=6; } } else if (state==5) { if (mouseButton == RIGHT) { state=3; xPos= width / 2; yPos= height / 2; } } else if (state==6) { if (mouseButton == RIGHT) { state=4; xPos= width / 2; yPos= height / 2; } } else if (state==7) { ///逃跑判斷 if (dist(mouseX, mouseY, 780, 500)<30&&mouseButton==LEFT) { phealth =100; } if (dist(mouseX, mouseY, 780, 600)<30&&mouseButton==LEFT) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } if (dist(mouseX, mouseY, 450, 250)<30&&mouseButton==LEFT&&mhealth<40) {//跳到捕捉畫面 state=15; } if (dist(mouseX, mouseY, 230, 500)<40&&mouseButton==LEFT)//撞擊 { mhealth -= 5; phealth -= 5; } if (dist(mouseX, mouseY, 500, 500)<40&&mouseButton==LEFT)//十萬伏特 { mhealth -= 10; phealth -= 5; } if (dist(mouseX, mouseY, 230, 600)<40&&mouseButton==LEFT)//鐵尾 { mhealth -= 15; phealth -= 5; } if (dist(mouseX, mouseY, 500, 600)<40&&mouseButton==LEFT)//電光一閃 { mhealth -= 20; phealth -= 5; } // 确保玩家血量不小於0 if (phealth < 0) { phealth = 0; } if (mhealth < 0||mhealth==0) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } } else if (state==8) { ///逃跑判斷 if (dist(mouseX, mouseY, 780, 500)<30&&mouseButton==LEFT) { phealth =100; } if (dist(mouseX, mouseY, 780, 600)<30&&mouseButton==LEFT) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } if (dist(mouseX, mouseY, 450, 250)<30&&mouseButton==LEFT&&mhealth<40) {//跳到捕捉畫面 state=15; } if (dist(mouseX, mouseY, 230, 500)<40&&mouseButton==LEFT)//撞擊 { mhealth -= 5; phealth -= 5; } if (dist(mouseX, mouseY, 500, 500)<40&&mouseButton==LEFT)//十萬伏特 { mhealth -= 10; phealth -= 5; } if (dist(mouseX, mouseY, 230, 600)<40&&mouseButton==LEFT)//鐵尾 { mhealth -= 15; phealth -= 5; } if (dist(mouseX, mouseY, 500, 600)<40&&mouseButton==LEFT)//電光一閃 { mhealth -= 20; phealth -= 5; } // 确保玩家血量不小於0 if (phealth < 0) { phealth = 0; } if (mhealth < 0||mhealth==0) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } } else if (state==9) { ///逃跑判斷 if (dist(mouseX, mouseY, 780, 500)<30&&mouseButton==LEFT) { phealth =100; } if (dist(mouseX, mouseY, 780, 600)<30&&mouseButton==LEFT) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } if (dist(mouseX, mouseY, 450, 250)<30&&mouseButton==LEFT&&mhealth<40) {//跳到捕捉畫面 state=15; } if (dist(mouseX, mouseY, 230, 500)<40&&mouseButton==LEFT)//撞擊 { mhealth -= 5; phealth -= 5; } if (dist(mouseX, mouseY, 500, 500)<40&&mouseButton==LEFT)//十萬伏特 { mhealth -= 10; phealth -= 5; } if (dist(mouseX, mouseY, 230, 600)<40&&mouseButton==LEFT)//鐵尾 { mhealth -= 15; phealth -= 5; } if (dist(mouseX, mouseY, 500, 600)<40&&mouseButton==LEFT)//電光一閃 { mhealth -= 20; phealth -= 5; } // 确保玩家血量不小於0 if (phealth < 0) { phealth = 0; } if (mhealth < 0||mhealth==0) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } } else if (state==10) { ///逃跑判斷 if (dist(mouseX, mouseY, 780, 500)<30&&mouseButton==LEFT) { phealth =100; } if (dist(mouseX, mouseY, 780, 600)<30&&mouseButton==LEFT) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } if (dist(mouseX, mouseY, 450, 250)<30&&mouseButton==LEFT&&mhealth<40) {//跳到捕捉畫面 state=15; } if (dist(mouseX, mouseY, 230, 500)<40&&mouseButton==LEFT)//撞擊 { mhealth -= 5; phealth -= 5; } if (dist(mouseX, mouseY, 500, 500)<40&&mouseButton==LEFT)//十萬伏特 { mhealth -= 10; phealth -= 5; } if (dist(mouseX, mouseY, 230, 600)<40&&mouseButton==LEFT)//鐵尾 { mhealth -= 15; phealth -= 5; } if (dist(mouseX, mouseY, 500, 600)<40&&mouseButton==LEFT)//電光一閃 { mhealth -= 20; phealth -= 5; } // 确保玩家血量不小於0 if (phealth < 0) { phealth = 0; } if (mhealth < 0||mhealth==0) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } } else if (state==11) { ///逃跑判斷 if (dist(mouseX, mouseY, 780, 500)<30&&mouseButton==LEFT) { phealth =100; } if (dist(mouseX, mouseY, 780, 600)<30&&mouseButton==LEFT) { resethealth(); state=6; file2.stop(); file.play(); file.loop(); } if (dist(mouseX, mouseY, 450, 250)<30&&mouseButton==LEFT&&mhealth<40) {//跳到捕捉畫面 state=15; } if (dist(mouseX, mouseY, 230, 500)<40&&mouseButton==LEFT)//撞擊 { mhealth -= 5; phealth -= 5; } if (dist(mouseX, mouseY, 500, 500)<40&&mouseButton==LEFT)//十萬伏特 { mhealth -= 10; phealth -= 5; } if (dist(mouseX, mouseY, 230, 600)<40&&mouseButton==LEFT)//鐵尾 { mhealth -= 15; phealth -= 5; } if (dist(mouseX, mouseY, 500, 600)<40&&mouseButton==LEFT)//電光一閃 { mhealth -= 20; phealth -= 5; } // 确保玩家血量不小於0 if (phealth < 0) { phealth = 0; } if (mhealth < 0||mhealth==0) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } } else if (state==12) { ///逃跑判斷 if (dist(mouseX, mouseY, 780, 500)<30&&mouseButton==LEFT) { phealth =100; } if (dist(mouseX, mouseY, 780, 600)<30&&mouseButton==LEFT) { resethealth(); state=6; file2.stop(); file.play(); file.loop(); } if (dist(mouseX, mouseY, 450, 250)<30&&mouseButton==LEFT&&mhealth<40) {//跳到捕捉畫面 state=15; } if (dist(mouseX, mouseY, 230, 500)<40&&mouseButton==LEFT)//撞擊 { mhealth -= 5; phealth -= 5; } if (dist(mouseX, mouseY, 500, 500)<40&&mouseButton==LEFT)//十萬伏特 { mhealth -= 10; phealth -= 5; } if (dist(mouseX, mouseY, 230, 600)<40&&mouseButton==LEFT)//鐵尾 { mhealth -= 15; phealth -= 5; } if (dist(mouseX, mouseY, 500, 600)<40&&mouseButton==LEFT)//電光一閃 { mhealth -= 20; phealth -= 5; } // 确保玩家血量不小於0 if (phealth < 0) { phealth = 0; } if (mhealth < 0||mhealth==0) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } } else if (state==13) { ///逃跑判斷 if (dist(mouseX, mouseY, 780, 500)<30&&mouseButton==LEFT) { phealth =100; } if (dist(mouseX, mouseY, 780, 600)<30&&mouseButton==LEFT) { resethealth(); state=6; file2.stop(); file.play(); file.loop(); } if (dist(mouseX, mouseY, 450, 250)<30&&mouseButton==LEFT&&mhealth<40) {//跳到捕捉畫面 state=15; } if (dist(mouseX, mouseY, 230, 500)<40&&mouseButton==LEFT)//撞擊 { mhealth -= 5; phealth -= 5; } if (dist(mouseX, mouseY, 500, 500)<40&&mouseButton==LEFT)//十萬伏特 { mhealth -= 10; phealth -= 5; } if (dist(mouseX, mouseY, 230, 600)<40&&mouseButton==LEFT)//鐵尾 { mhealth -= 15; phealth -= 5; } if (dist(mouseX, mouseY, 500, 600)<40&&mouseButton==LEFT)//電光一閃 { mhealth -= 20; phealth -= 5; } // 确保玩家血量不小於0 if (phealth < 0) { phealth = 0; } if (mhealth < 0||mhealth==0) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } } else if (state==14) { ///逃跑判斷 if (dist(mouseX, mouseY, 780, 500)<30&&mouseButton==LEFT) { phealth =100; } if (dist(mouseX, mouseY, 780, 600)<30&&mouseButton==LEFT) { resethealth(); state=6; file2.stop(); file.play(); file.loop(); } if (dist(mouseX, mouseY, 450, 250)<30&&mouseButton==LEFT&&mhealth<40) {//跳到捕捉畫面 state=15; file2.stop(); file3.play(); } if (dist(mouseX, mouseY, 230, 500)<40&&mouseButton==LEFT)//撞擊 { mhealth -= 5; phealth -= 5; } if (dist(mouseX, mouseY, 500, 500)<40&&mouseButton==LEFT)//十萬伏特 { mhealth -= 10; phealth -= 5; } if (dist(mouseX, mouseY, 230, 600)<40&&mouseButton==LEFT)//鐵尾 { mhealth -= 15; phealth -= 5; } if (dist(mouseX, mouseY, 500, 600)<40&&mouseButton==LEFT)//電光一閃 { mhealth -= 20; phealth -= 5; } // 确保玩家血量不小於0 if (phealth < 0) { phealth = 0; } if (mhealth < 0||mhealth==0) { resethealth(); state=5; file2.stop(); file.play(); file.loop(); } } else if (state==15) { file.stop(); file2.stop(); } else if (state==16) { if (dist(mouseX, mouseY, 460, 530)<50&&mouseButton==LEFT) { file3.play(); state=17; } } else if (state==17) { if (dist(mouseX, mouseY, 500, 530)<50&&mouseButton==LEFT) { exit(); } } if (phealth<0||phealth==0) { resethealth(); }//end of } void keyPressed() { if (key=='Z'||key=='z') { file.pause(); } else if (key=='X'||key=='x') file.play(); } void resethealth() { mhealth = 100; phealth = 100; }
沒有留言:
張貼留言