Manhole เป็นเกมที่พัฒนาโดย Nintendo R & D1 และเป็นเกมที่หกของgame and watch มันปรากฏตัวครั้งแรกในปี 1981 โดยเกมจะเริ่มต้นโดยมีคนเดินข้ามสะพานและเราที่เป็นผู้เล่นจะต้องทำการช่วยเหลือผู้คนที่เดินบนถนนโดยระหว่างทางมีช่องว่างของท่อซึ่งเราเป็นผู้เล่นการนำถนนไปต่อเข้ากับช่วงของถนนที่ว่างอยู่ซึ่งใช้ปุ่มแต่ละปุ่มสี่ปุ่มที่สอดคล้องกับการเปิดในถนน ผู้เล่นจะต้องใช้ปุ่มเพื่อปิดบ่อพักก่อนที่จะเดินเท้าตกผ่านรูเปิดและเข้าไปในท่อระบายน้ำ
ตัวอย่างเกม Manhole
สรุป Global Variable
float x_selectmode=20;
// ตัวแปรชนิด จำนวนจริง เก็บระยะแกน x ของ ข้อความ selectmode
int radius_smooth = 80;
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าของความกว้างของปุ่ม smooth
int radius_step = 80;
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าของความกว้างของปุ่ม step
float distance_x, distance_y, distance_total;
// ตัวแปรชนิด จำนวนจริง เก็บค่าระยะห่างจากจุดศูนย์กลางของแกน x แกน y
และระยะห่างระหว่างแกน x แกน y ตามลำดับ
int divided =50;
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าตัวแปรเพื่อเอาไว้หน่วงจังหวะ
int miss = 0;
// ตัวแปรชนิด จำนวนเต็ม เก็บจำนวนคนที่ตกน้ำ
int highscore;
// ตัวแปรชนิด จำนวนเต็ม เก็บคะแนนที่มากที่สุดในการเล่นเกม
int checkscoreArea = 90;
int checkscoreArea 1 =90;
// ตัวแปรชนิด จำนวนเต็ม เก็บระยะเพื่อเพิ่มคะแนน
int stateButton =0;
// ตัวแปรชนิด จำนวนเต็ม เช๊คสถานะของปุ่ม
int scores = 0;
// ตัวแปรชนิด จำนวนเต็ม เก็บคะแนนก่อน gameover
int rounds = 1;
// ตัวแปรชนิด จำนวนเต็ม เก็บจำนวนรอบของเกม
int [] position = new int [8];
// ตัวแปรอาเรย์ ชนิด จำนวนเต็ม เก็บตำแหน่งเริ่มต้นของคนเดิน
ซึ่งเก็บเป็นแบบอาเรย์จะช่วยให้ ลดการประกาศ global variable ไปได้มาก
int count = 0;
// ตัวแปรชนิด จำนวนเต็ม เพื่อนับค่าเพิ่มขึ้นเรื่อยๆ
int changefoot=0;
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าเพื่อใช้ในการสลับขาของคนเดิน
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าเพื่อใช้ในการสลับขาของคนเดิน
สรุปฟังก์ชัน
รับผิดชอบโดย นาย ธนพล ขวัญเกื้อ
mousePressed(); ฟังก์ชันระบบตรวจสอบการคลิกของเมาส์
drawtryAgainbutton(); ฟังก์ชันวาดปุ่มกดเริ่มต้นเล่นเกมใหม่
drawmanubutton(); ฟังก์ชันวาดปุ่มกลับสู่เมนูหลัก
stratpage(); ฟังก์ชันวาดปุ่มกดเพื่อเริ่มเล่นเกม
drawStepbutton(); ฟังก์ชันวาดปุ่มเพื่อเลือกโหมด step
drawSmoothbutton(); ฟังก์ชันวาดปุ่มเพื่อเลือกโหมด smooth
รับผิดชอบโดย นาย ศุภเมธ เมษประสาท
drawFaceman(int x,int y); ฟังก์ชันวาดหน้าคนเดิน
drawHandmantop(int x ,int y); ฟังก์ชันวาดแขนของคนเดินข้างบน
drawHandmanbuttom(int x ,int y); ฟังก์ชันวาดแขนของคนเดินข้างล่าง
drawLegman(int x , int y); ฟังก์ชันวาดขาของคนเดิน
drawBodyman(int x , int y); ฟังก์ชันวาดตัวของคนเดิน
drawmantop(); ฟังก์ชันวาดคนเดินข้างบน
drawmanbuttom(); ฟังก์ชันวาดคนเดินข้างล่าง
highScore(); ฟังก์ชันตรวจสอบคะแนนสูงสุด
รับผิดชอบโดย นาย ธีรชัย สันติวิชัยพานิช
backgrounds(int y); ฟังก์ชันเอาไว้สำหรับวาดรูปพื้นหลังของเกม ประกอบด้วย
สะพาน น้ำ ภูเขา ก้อนเมฆ รับพารามิเตอร์เป็นระยะแกน Y
gameover(); ฟังก์ชันตรวจสอบกรณีไม่มีสะพานมารับคนที่เดิน
keyPressed(); ฟังก์ชันระบบเอาไว้ตรวจสอบการกดปุ่มเพื่อนำสะพานมารับ
changeMan(); ฟังก์ชันเปลี่ยนตำแหน่งของคนที่เดินบนสะพาน
showmissed(); ฟังก์ชันแสดงชีวิตที่เหลืออยู่เมื่อมีคนตกน้ำ
changesmooth(); ฟังก์ชันการเคลื่อนที่ในโหมด smooth
changestep(); ฟังก์ชันการเคลื่อนที่ในโหมด step
resetvalue(); ฟังก์ชันกำหนดค่าใหม่
manhold(); ฟังก์ชันวาดคนถือสะพาน
manfall(); ฟังก์ชันวาดคนตกน้ำ
โดยมีเงื่อนไข คือ ถ้าคนที่เดินบนสะพานมีตำแหน่งแกน x ตรงกับ ค่าของสะพานที่มารับ ให้เพิ่มค่า score ขึ้นทีละ 1 และแสดงค่า Score ที่มุมขวาบนของหน้าจอ แต่ถ้า ค่า x ไม่ตรงกับค่าที่สะพานมารับ ให้แสดง " Game Over " กลางหน้าจอ
เมื่อเริ่มต้นเกม ผู้เล่นสามารถเลือกโหมดการเล่นได้ว่า จะเล่นแบบ smooth หรือ step
รูปแสดง หน้าจอเริ่มต้นของเกม
วิธีการเล่น
กดปุ่ม w เพื่อนำสะพานมารับคนด้านบนซ้าย
กดปุ่ม O เพื่อนำสะพานมารับคนด้านบนซ้าย
รูปแสดงการกดปุ่ม O เพื่อนำสะพานมารับคน
รูปแสดงการกดปุ่ม k เพื่อนำสะพานมารับคน
กดปุ่ม d เพื่อนำสะพานมารับคนด้านบนซ้าย
รูปแสดงการกดปุ่ม d เพื่อนำสะพานมารับคน
ถ้าหาก "Game Over" และต้องการจะเล่นเกมใหม่ สามารถกดที่ปุ่ม TryAgain
หรือกลับสู่เมนูหลัก โดยกดที่ปุ่ม Manu
ตัวอย่างโค้ด
float x_selectmode=20;
// ตัวแปรชนิด จำนวนจริง เก็บระยะแกน x ของ ข้อความ selectmode
int radius_smooth = 80;
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าของความกว้างของปุ่ม smooth
int radius_step = 80;
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าของความกว้างของปุ่ม step
float distance_x, distance_y, distance_total;
// ตัวแปรชนิด จำนวนจริง เก็บค่าระยะห่างจากจุดศูนย์กลางของแกน x แกน y
และระยะห่างระหว่างแกน x แกน y ตามลำดับ
int divided =50;
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าตัวแปรเพื่อเอาไว้หน่วงจังหวะ
int miss = 0;
// ตัวแปรชนิด จำนวนเต็ม เก็บจำนวนคนที่ตกน้ำ
int highscore;
// ตัวแปรชนิด จำนวนเต็ม เก็บคะแนนที่มากที่สุดในการเล่นเกม
int checkscoreArea = 90;
int checkscoreArea1 =90;
// ตัวแปรชนิด จำนวนเต็ม เก็บระยะเพื่อเพิ่มคะแนน
int stateButton =0;
// ตัวแปรชนิด จำนวนเต็ม เช๊คสถานะของปุ่ม
int scores = 0;
// ตัวแปรชนิด จำนวนเต็ม เก็บคะแนนก่อน gameover
int rounds = 1;
// ตัวแปรชนิด จำนวนเต็ม เก็บจำนวนรอบของเกม
int [] position = new int [8];
// ตัวแปรอาเรย์ ชนิด จำนวนเต็ม เก็บตำแหน่งเริ่มต้นของคนเดิน
ซึ่งเก็บเป็นแบบอาเรย์จะช่วยให้ ลดการประกาศ global variable ไปได้มาก
int count = 0;
// ตัวแปรชนิด จำนวนเต็ม เพื่อนับค่าเพิ่มขึ้นเรื่อยๆ
int changefoot=0;
//ใช้เชคช่วงเพื่อเปลี่ยนการวาดรูปเท้าของคนเดิน
void setup() {
size(400, 400); //กำหนดขนาดหน้าจอ
}
void draw() {
drawstartpage();
startSmooth();
startStep();
count++;
changeconvert++;
}
void mousePressed() { //ฟังก์ชั่นของระบบ จะทำงานเมื่อมีเม้าส์คลิกลงไป
distance_x = mouseX-120;//พิกัดเม้าส์ X ลบกับพิกัดแกน X ของจุดศูนย์กลางของวงกลมปุ่มกด smooth
distance_y = mouseY-330;//พิกัดเม้าส์ Y ลบกับพิกัดแกน Y ของจุดศูนย์กลางของวงกลมปุ่มกด smooth
distance_total = sqrt((distance_x*distance_x)+(distance_y*distance_y));
//เชคระยะว่าเม้าอยู่ในวงกลมหรือไม่ โดยใช้หลักของพีทากอรัส
if (distance_total <= radius_smooth /2 ) {{
//หากเชคระยะมาได้ว่ามีค่าน้อยกว่าหรือเท่ากับรัศมีของวงกลมหาร2 ให้ statebutton เท่ากับ 1
stateButton =1;
}
distance_x = mouseX-280; //พิกัดเม้าส์ X ลบกับพิกัดแกน X ของจุดศูนย์กลางของวงกลมปุ่มกด state
distance_y = mouseY-330; //พิกัดเม้าส์ Y ลบกับพิกัดแกน Y ของจุดศูนย์กลางของวงกลมปุ่มกด state
distance_total = sqrt((distance_x*distance_x)+(distance_y*distance_y));
if (distance_total <= radius_step /2 ) {
//หากเชคระยะมาได้ว่ามีค่าน้อยกว่าหรือเท่ากับรัศมีของวงกลมหาร2 ให้ statebutton เท่ากับ 2
stateButton =2;
}
if (mouseX >= 140 && mouseX <= 260 && mouseY >= 250 && mouseY <= 310) {
//ถ้า พิกัดเม้าส์ x อยู่ในช่วง 140<=x<=260 และพิกัดเม้าส y อยู่ในช่วง 250<=y<=310 ใช้เชคปุ่ม tryagain
if (stateButton == 1) { //ถ้า state เท่ากับ 1 ก้อให้ state เท่ากับ1 เช่นเดิม
stateButton=1;
}
else {
stateButton=2; //กรณีอื่น ให้ state เท่ากับ 2
}
}
reset();
if (mouseX >= 220 && mouseX <= 340 && mouseY >= 250 && mouseY <= 310) {
stateButton =0 ; //ให้ state เป็น 0
startpage();//เรียกใชั้ฟังก์ชั่น startpage แล้วโปรแกรมก้อจะค้างอยู่หน้าstartpage เพราะ ได้ตั้งค่า state เป็น 0 แล้ว จะเริ่มเล่นเกมอีกทีได้ก็ต่อเมื่อเลือกโหมดในการเล่น
}
}
void drawstartpage() {//ฟังก์ชั่นวาดหน้า startpage
int color1, color2, color3;
background(0);
color1= (int)random(0, 255);//random ต่าตั้งแต่ 0-100 เก็บไว้ใน color เพื่อนำไปใช้เติมสี คำว่า manhole
color2 = (int)random(0, 255);
color3 = (int )random(0, 255);
fill(color1, color2, color3);
textSize(120);
text("MAN", 10, 100);
text("HOLE", 60, 220);
textSize(15);
fill(255);
textSize(15);
fill(255);
text("NINTENDO GAME AND WATCH", 80, 120);
textSize(18);
text("SELECT GAME MODE", x_selectmode, 260);
x_selectmode+= .1; // ให้พิกิด x ของประโยคนี้(SELECT GAME MODE)บวกเพิ่มขึ้นไปเรื่อยๆ
if (x_selectmode >= 400) {//ถ้าหากพิกัดแกน x ของประโยคนี้มากกว่าหรือเท่ากับ 400 แล้ว ให้ พิกัดแกน x เท่ากับ -200 กล่าวคือให้กลับมาเริ่มต้นใหม่นั่นเอง
x_selectmode = -200;
}
strokeWeight(10);
stroke(#48D0F7);
drawSmoothbutton();
drawStepbutton();
}
void reset() {
changeconvert = 0;
miss = 0;
checkscoreArea= 90;
checkscoreArea1 = 90;
scores = 0;
rounds = 1;
position[0] = -100;
position[1] = 125;
position[2] = -370;
position[3] = 125;
position[4] = 550;
position[5] = 275;
position[6] = 620;
position[7] = 275;
if (stateButton ==1 ) {
background(255);
drawbackgrounds(180);
drawbackgrounds(330);
drawMantop();
changeSmooth();
keyPressed();
gameover(1);
showmissed();
}
if (stateButton == 2) {
background(255);
drawbackgrounds(180);
drawbackgrounds(330);
drawMantop();
changeStep();
keyPressed();
gameover(50);
showmissed();
}
}
void drawSmoothbutton() {//ฟังก์ชั่นวาดปุ่ม smooth
fill(0);
stroke(#FFDF24);
fill(#F20F0F);
ellipse(120, 330, radius_smooth, radius_smooth);
fill(255);
textSize(14);
text("SMOOTH", 90, 340);
distance_x = mouseX-120;//พิกัดเม้าส์ X ลบกับพิกัดแกน X ของจุดศูนย์กลางของวงกลมปุ่ม smooth
distance_y = mouseY-330;//พิกัดเม้าส์ Y ลบกับพิกัดแกน Y ของจุดศูนย์กลางของวงกลมปุ่ม smooth
distance_total = sqrt((distance_x*distance_x)+(distance_y*distance_y)); //เชคระยะว่าเม้าอยู่ในวงกลมหรือไม่ โดยใช้หลักของพีทากอรัส
if (distance_total<= radius_smooth/2) { //หากเชคระยะมาได้ว่ามีค่าน้อยกว่าหรือเท่ากับรัศมีของวงกลมหาร2 ให้รัศมีเท่ากับ 100 กล่าวคือหากเม้าส์เข้าไปในรัศมีก็จะเห็นปุ่มวงกลมขยายใหญ่ขึ้น
radius_smooth= 100;
}
else {
radius_smooth = 80; //นอกจากนั้นให้รัศมีเท่ากับ 80 กล่าวคือหากเม้าสไม่เข้าไปในรัศม ปุ่มวงกลมก็จะเท่าเดิมไม่ขยายใหญ่ขึ้น
}
}
void drawStepbutton() {//ฟังก์ชั่นวาดปุ่ม step
fill(0);
fill(#F20F0F);
ellipse(280, 330, radius_step, radius_step);
fill(255);
textSize(17);
text("STEP", 263, 340);
distance_x = mouseX-280;
distance_y = mouseY-330;
distance_total = sqrt((distance_x*distance_x)+(distance_y*distance_y));
if (distance_total<= radius_step/2) {
radius_step= 100;
}
else {
radius_step = 80;
}
}
void startSmooth() { // ฟังก์ชันเริ่มเกมในโหมด smooth
if (stateButton ==1 ) {
drawbackgrounds();
drawMantop();
drawManbottom();
changeSmooth();
drawManbottom();
keyPressed();
checkgameover(1);
showmissed();
}
}
void startStep() { // ฟังก์ชันเริ่มเกมในโหมด step
if (stateButton == 2) {
drawbackgrounds();
drawMantop();
drawManbottom();
changeStep();
keyPressed();
checkgameover(50);
showmissed();
}
}
void drawTryAgainbutton() {//ฟังก์ชั่นวาดปุ่ม tryagain
noStroke();
fill(#B2FCEF);
rect(60, 250, 120, 60 );
fill(#1BE3A8);
rect(70, 260, 100, 40 );
fill(0);
textSize(19);
text("TryAgain", 80, 285);
}
void drawManubutton() {//ฟังก์ชั่นวาดปุ่ม Manu
noStroke();
fill(#B2FCEF);
rect(220, 250, 120, 60 );
fill(#1BE3A8);
rect(230, 260, 100, 40 );
fill(0);
textSize(19);
text("Manu", 250, 285);
}
void highScore() { //ฟังก์ชั่นวาด highscore
text("HIGH SCORE = "+highscore, 250, 20);
if (highscore < scores) {//ถ้า highscore น้อยกว่า score ให้ highscore มีค่าเท่ากับ scores แล้วนำค่า highscore ไปแสดงผล
highscore = scores;
}
}
void drawbackgrounds(int y) {//ฟังก์ชันวาดภาพพื้นหลัง ซึ่งประกอบด้วย เกาะ น้ำ ภูเขา และก้อนเมฆ โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน y ในการวาดรูป
background(#C9FFFB); //ใส่สีพื้อนหลังสีฟ้า
fill(0);
stroke(#5A2E01);
strokeWeight(10);
line(0, 180, 78, 180); //วาดขอบบนทางเดินก้อนแรก ด้านบน
noStroke();
fill(#A77413);
rect(0, 180, 80, 50); //วาดฐานก้อนแรก ด้านบน
stroke(#5A2E01);
strokeWeight(10);
line(152, 180, 228, 180); //วาดขอบบนทางเดินก้อนที่สอง ด้านบน
noStroke();
fill(#A77413);
rect(150, 180, 80, 50); //วาดฐานก้อนที่สอง ด้านบน
fill(#C9FFFB);
ellipse(230, 180+30, 50, 60); //วาดให้ฐานตรงกลางด้านบนเว้า
ellipse(150, 180+30, 50, 60); //วาดให้ฐานตรงกลางด้านบนเว้า
ellipse(0, 180+30, 50, 60); //วาดให้ฐานก้อนที่หนึ่งด้านบนเว้า
ellipse(80,180+30, 50, 60); //วาดให้ฐานก้อนที่หนึ่งด้านบนเว้า
fill(#2BDED0);
ellipse(95, 180+50, 20, 5); //วาดน้ำระหว่างก้อนที่หนึ่งกับที่สอง ด้านบน
ellipse(109, 180+45, 20, 5);//วาดน้ำระหว่างก้อนที่หนึ่งกับที่สอง ด้านบน
ellipse(120, 180+50, 20, 5);//วาดน้ำระหว่างก้อนที่หนึ่งกับที่สอง ด้านบน
ellipse(135,180+45, 20, 5);//วาดน้ำระหว่างก้อนที่หนึ่งกับที่สอง ด้านบน
stroke(#5A2E01);
strokeWeight(10);
line(302, 180, 398, 180); //วาดขอบบนทางเดินก้อนที่สาม ด้านบน
noStroke();
fill(#A77413);
rect(300, 180, 100, 50); //วาดฐานก้อนที่สาม ด้านบน
fill(#C9FFFB);
ellipse(300, 180+30, 50, 60); //วาดให้ฐานก้อนที่สามด้านบนเว้า
fill(#C9FFFB);
ellipse(400, 180+30, 50, 60); //วาดให้ฐานก้อนที่สามด้านบนเว้า
fill(#2BDED0);
ellipse(245, 180+50, 20, 5);//วาดน้ำระหว่างก้อนที่สองกับที่สาม ด้านบน
ellipse(260, 180+45, 20, 5);//วาดน้ำระหว่างก้อนที่สองกับที่สาม ด้านบน
ellipse(275, 180+50, 20, 5);//วาดน้ำระหว่างก้อนที่สองกับที่สาม ด้านบน
ellipse(290, 180+45, 20, 5);//วาดน้ำระหว่างก้อนที่สองกับที่สาม ด้านบน
fill(255); //วาดก้อนเมฆ
ellipse(x_selectmode+150, 30, 70, 40);
ellipse(x_selectmode+180, 40, 60, 30);
ellipse(x_selectmode+120, 40, 50, 30);
ellipse(x_selectmode+300, 60, 50, 30);
ellipse(x_selectmode+330, 50, 80, 50);
ellipse(x_selectmode+360, 60, 60, 30);
noStroke();
fill(#31FF2E);
quad(-20, 175, 100, 100, 120, 100, 220, 175);//วาดภูเขาลูกที่หนึ่ง
ellipse(110, 105, 22, 22);
quad(200, 175, 300, 70, 320, 70, 420, 175);//วาดภูเข้าลูกที่สอง
ellipse(310, 74, 21, 21);
fill(0); // ตั้งแต่ตรงนี้คือทางเดินด้านล่าง เรียงลำดับการวาดเหมือนกับด้านบน
stroke(#5A2E01);
strokeWeight(10);
line(0, 330, 78, 330);
noStroke();
fill(#A77413);
rect(0, 330, 80, 50);
stroke(#5A2E01);
strokeWeight(10);
line(152, 330, 228, 330);
noStroke();
fill(#A77413);
rect(150, 330, 80, 50);
fill(#C9FFFB);
ellipse(230, 330+30, 50, 60);
ellipse(150, 330+30, 50, 60);
ellipse(0, 330+30, 50, 60);
ellipse(80,330+30, 50, 60);
fill(#2BDED0);
ellipse(95, 330+50, 20, 5);
ellipse(109, 330+45, 20, 5);
ellipse(120, 330+50, 20, 5);
ellipse(135,330+45, 20, 5);
stroke(#5A2E01);
strokeWeight(10);
line(302, 330, 398, 330);
noStroke();
fill(#A77413);
rect(300, 330, 100, 50);
fill(#C9FFFB);
ellipse(300, 330+30, 50, 60);
fill(#C9FFFB);
ellipse(400, 330+30, 50, 60);
fill(#2BDED0);
ellipse(245, 330+50, 20, 5);
ellipse(260, 330+45, 20, 5);
ellipse(275, 330+50, 20, 5);
ellipse(290, 330+45, 20, 5);
fill(255); // sky
ellipse(x_selectmode+150, 30, 70, 40);
ellipse(x_selectmode+180, 40, 60, 30);
ellipse(x_selectmode+120, 40, 50, 30);
ellipse(x_selectmode+300, 60, 50, 30);
ellipse(x_selectmode+330, 50, 80, 50);
ellipse(x_selectmode+360, 60, 60, 30);
fill(0);
textSize(15);
text("Miss ", 100, 20); //เขียนคำว่า Miss
text("Score = "+ scores, 300, 50); //เขียนคำว่า Score
highScore(); //เรียกใช้ฟังก์ชัน highScore
}
void drawmiss(int x, int y) {//ฟังก์ชั่นวาดภาพหน้าคนที่จะขึ้นมาเมื่อคนตกน้ำ โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
fill(#F5800A);
strokeWeight(1);
ellipse(x, y, 30, 25); //หัว
fill(255);
ellipse(x, y+7, 20, 10);// ปาก
stroke(0);
line(x-7, y+4, x-5, y+10);
line(x-5, y+10, x-2, y+2);
line(x-2, y+2, x+1, y+11);
line(x+1, y+11, x+4, y+2);
line(x+4, y+2, x+6, y+10);
noStroke();
ellipse(x-4, y-5, 8, 10); // ตา
ellipse(x+4, y-5, 8, 10);
fill(0);
ellipse(x-3, y-3, 4, 4);
ellipse(x+4, y-3, 4, 4);
}
void drawFaceman(int x_man, int y_man) {//ฟังก์ชั่นวาดภาพหน้าคนเดิน โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
fill(0);
stroke(0);
strokeWeight(5);
ellipse(x_man, y_man, 30, 25); //หัว
fill(255);
noStroke();
ellipse(x_man, y_man+7, 25, 10);// ปาก
stroke(0);
strokeWeight(1);
line(x_man-2, y_man, x_man-2, y_man+13);// ฟัน
line(x_man-8, y_man, x_man-8, y_man+10);
line(x_man-5, y_man, x_man-5, y_man+12);
line(x_man+1, y_man, x_man+1, y_man+12);
line(x_man+4, y_man, x_man+4, y_man+10);
line(x_man+7, y_man, x_man+7, y_man+10);
}
void drawHandmantop(int x_mantop, int y_mantop) {//ฟังก์ชั่นวาดภาพแขนคนเดินด้านบน โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
line(x_mantop-14, y_mantop+23, x_mantop-25, y_mantop+12); // แขน
ellipse(x_mantop-25, y_mantop+12, 5, 5);
line(x_mantop+13, y_mantop+23, x_mantop+25, y_mantop+12); // แขน
ellipse(x_mantop+25, y_mantop+12, 5, 5);
}
void drawHandmanbottom(int x_manbottom, int y_manbottom) {//ฟังก์ชั่นวาดภาพแขนคนเดินด้านล่าง โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
line(x_manbottom-14, y_manbottom+23, x_manbottom-25, y_manbottom+12); // แขน
ellipse(x_manbottom-25, position[0]+12, 5, 5);
line(x_manbottom+13, y_manbottom+23, x_manbottom+25, y_manbottom+30); // แขน
ellipse(x_manbottom+25, y_manbottom+30, 5, 5);
}
void drawLegman(int x_man, int y_man) {//ฟังก์ชั่นวาดภาพแขนคนเดินด้านล่าง โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
line(x_man-5, y_man+38, x_man-10, y_man+45); // ขา
line(x_man+5, y_man+38, x_man+10, y_man+45);
if (changefoott>=1 && changefoot<=20) {//ฟังก์ชั่นวาดภาพขาคนเดิน โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
line(x_man-20, y_man+40, x_man-5, y_man+48);// เท้า
line(x_man+5, y_man+48, x_man+20, y_man+48);
}
if (changefoot>20 && changefoot<40) { //หากค่า changefoot มากว่า 20 และ น้อยกว่า 40 ให้ทำงานต่อไป ต้องเชคเพื่อให้ขาคนเดินมีการขยับขึ้นขยับลง
line(x_man-20, y_man+48, x_man-5, y_man+48);// เท้า
line(x_man+5, y_man+48, x_man+20, y_man+40);
}
if (changefoot == 40) {//ถ้า ค่าchangefoott เท่ากับ 40
changefoot=0;//ให้ ค่าchangefoot เท่ากับ 40 เท่ากับ 0
}
}
void drawBodyman(int x_man, int y_man) { //ฟังก์ชั่นวาดภาพตัวคนเดิน โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
strokeWeight(5);
line(x_man, y_man+15, x_man, y_man+20);// คอ
ellipse(x_man, y_man+27, 20, 15);// ตัว
}
void drawMantop() { //ฟังก์ชั่นวาดภาพคนเดินข้างบน
if (position[1] >=125 && position[1] < 135) {
drawFaceman(position[0], position[1]);
ellipse(position[0]-1, position[1]-5, 8, 10); // ตา
ellipse(position[0]+7, position[1]-5, 7, 10);
fill(0);
ellipse(position[0], position[1]-5, 4, 4);
ellipse(position[0]+8, position[1]-5, 4, 4);
ellipse(position[0]+15, position[1], 10, 5);// จมูก
drawBodyman(position[0], position[1]);
drawHandmantop(position[0], position[1]);
drawLegman(position[0], position[1]);
}
if (position[3] >=125 && position[3] < 135) {
drawFaceman(position[2], position[3]);
ellipse(position[2]-1, position[3]-5, 8, 10); // ตา
ellipse(position[2]+7, position[3]-5, 7, 10);
fill(0);
ellipse(position[2], position[3]-5, 4, 4);
ellipse(position[2]+8, position[3]-5, 4, 4);
ellipse(position[2]+15, position[3], 10, 5);// จมูก
drawBodyman(position[2], position[3]);
drawHandmantop(position[2], position[3]);
drawLegman(position[2], position[3]);
}
}
void drawManbottom() { //ฟังก์ชั่นวาดภาพคนเดินข้างล่าง
if (position[5]>= 275 && position[5] < 285) {
drawFaceman(position[4], position[5]);
ellipse(position[4]-8, position[5]-5, 8, 10); // ตา
ellipse(position[4], position[5]-5, 7, 10);
fill(0);
ellipse(position[4]-10, position[5]-5, 4, 4);
ellipse(position[4]-2, position[5]-5, 4, 4);
ellipse(position[4]-15, position[5], 10, 5);// จมูก
drawBodyman(position[4], position[5]);
drawHandmanbottom(position[5], position[0]);
drawLegman(position[4], position[5]);
}
if (position[7]>= 275 && position[7] < 285) {
drawFaceman(position[6], position[5]);
ellipse(position[6]-8, position[7]-5, 8, 10); // ตา
ellipse(position[6], position[7]-5, 7, 10);
fill(0);
ellipse(position[6]-10, position[7]-5, 4, 4);
ellipse(position[6]-2, position[7]-5, 4, 4);
ellipse(position[6]-15, position[7], 10, 5);// จมูก
drawBodyman(position[6], position[7]);
drawHandmanbottom(position[6], position[7]);
drawLegman(position[6], position[7]);
}
}
void manhold(int x, int y) {//ฟังก์ชั่นวาดภาพคนถือสะพาน โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
fill(0);
ellipse(x, y, 30, 25); //หัว
fill(255);
noStroke();
ellipse(x, y+7, 20, 10);// ปาก
stroke(0);
strokeWeight(1);
line(x-2, y, x-2, y+13);// ฟัน
line(x-8, y, x-8, y+10);
line(x-5, y, x-5, y+12);
line(x+1, y, x+1, y+12);
line(x+4, y, x+4, y+10);
line(x+7, y, x+7, y+10);
ellipse(x-1, y-5, 8, 10); // ตา
ellipse(x+7, y-5, 8, 10);
fill(0);
ellipse(x-1, y-7, 4, 4);
ellipse(x+7, y-7, 4, 4);
strokeWeight(5);
line(x, y+15, x, y+20);// คอ
strokeWeight(15);
line(x+3, y+23, x+10, y+35);// ตัว
strokeWeight(5);
line(x-10, y+15, x-30, y-10); // แขน
line(x-35, y-10, x-20, y-10);
line(x+10, y+20, x+35, y+10); // แขน
ellipse(x+30, y+13, 5, 5);
line(x+10, y+35, x+30, y+30); // ขา
ellipse(x+30, y+30, 5, 10);
stroke(0);
strokeWeight(7);
line(x-63, y-12, x-11, y-12);
}
void manfall(int x, int y) {//ฟังก์ชั่นวาดภาพขาคนตกน้ำ โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน xและy ในการวาดรูป
stroke(0);
strokeWeight(15);// ตัว
line(x+5, y+18, x+20, y+25);
strokeWeight(1);
fill(0);
ellipse(x, y, 30, 25); //หัว
fill(255);
ellipse(x, y+7, 20, 10);// ปาก
stroke(0);
ellipse(x-1, y-5, 8, 10); // ตา
ellipse(x+7, y-5, 8, 10);
fill(0);
ellipse(x-3, y-5, 4, 4);
ellipse(x+4, y-5, 4, 4);
strokeWeight(5);
strokeWeight(5);
line(x+20, y+25, x+35, y+20);//ขา
line(x+35, y+20, x+40, y+25);
line(x+35, y+27, x+50, y+27); // เท้า
line(x+5, y+15, x-10, y+30); // แขน
ellipse(x-6, y+25, 5, 5);
line(x+5, y+15, x+30, y+10); // แขน
ellipse(x+25, y+12, 5, 5);
fill(#2BDED0);
noStroke();
ellipse(x-30, y+20, 20, 10);
ellipse(x+50, y+10, 20, 10);
fill(#C9FFFB);
noStroke();
ellipse(x-20, y+25, 15, 15);
ellipse(x+42, y+14, 15, 10);
}
void changeSmooth() { //ฟังกชั่นวาดคนในโหมดการเล่นแบบ smooth
drawMantop(); //เรียกใช้ฟังก์ชั่น drawmantop เพื่อรวาดคนข้างบน
inc = 1;
if(rounds>=2){ //ถ้า round มากกว่าหรือเท่ากับ 2 ให้ inc เท่ากับ 2 ดังนั้น คนจะเคลื่อนที่เรวขึ้น
inc = 2 ;
}
if (position[0]+15<= width+80 && position[1] == 125 ) { //ถ้า array ตำแหน่งที่ 0 ของposition +15 แล้วน้อยกว่าเท่ากับความกว่างหน้าจอ+80 และ array ตำแหน่งที่ 1 เท่ากับ 125
position[0]+= inc; //ให้ค่า position[2] บวก inc ไปเรื่อยๆนั่นคือค่า x ของคนจะบวกไปเรื่อย ทำให้เห็นเปนคนเหลื่อนที่ไปในแนวแกน x ทางบวก
}
if (position[0]+15>width+70 && position[1] == 125 ) { //ถ้า array ตำแหน่งที่ 0 ของposition +15 แล้วมากกว่าเท่ากับความกว่างหน้าจอ+70 และ array ตำแหน่งที่ 1 เท่ากับ 125
drawManbottom(); //เรียกใช้ฟังก์ชั่น drawmanbottom เพื่อรวาดคนข้างล่าง
position[4]-=inc; //ให้ค่า position[4] ลบ inc ไปเรื่อยๆนั่นคือค่า x ของคนจะบวกไปเรื่อย ทำให้เห็นเปนคนเคลื่อนที่ไปในแนวแกน x ทางลบ
}
if (position[4]+15 <= -80 && position[5]== 275 ) { //ถ้า array ตำแหน่งที่ 4 ของposition +15 แล้วน้อยกว่าเท่ากับ -80 และ array ตำแหน่งที่ 5 เท่ากับ 125
position[0] = -50; //ให้ array ตำแหน่งที่ 0 ของposition เท่ากับ -50
position[4] = 550; //ให้ array ตำแหน่งที่ 4 ของposition เท่ากับ -50
}
if (rounds>=2) { /ถ้า round หรือจานวนรอบ มากกว่าเท่ากับ 2
drawMantop(); //วาดคนข้างบน กล่าวคือ ข้างบนจะมการววาดดนเดินไป 2 สองคน
if (position[2]+15<= width+80 ) {
position[2]+= inc;
}
if (position[2]+15>width+70 && position[3] == 125 ) {
drawManbottom(); //วาดคนข้างล่าง กล่าวคือ ข้างล่างจะมการววาดดนเดินกลับ 2 สองคน
position[6]-=inc;
}
if (position[6]+15 <= -80 && position[7]== 275 ) {
position[2] = -370;
position[6] = 620;
}
}
if (position[4]== -20) {
// ถ้า position[1] หรือ ค่า x ของคนข้างล่างน้อยกว่าเท่ากับ 20 ให้ round (จำนวนรอบ) บวกเพิ่มขึ้น 1
rounds++;
}
}
void changeStep() { //ฟังกชั่นวาดคนในโหมดการเล่นแบบ step
inc = 70; //ฟังกชั่นวาดคนในโหมดการเล่นแบบ step
if(rounds>=3){
divided = 40;
}
if (count%divided==0) { //ถ้า count หาร divided ได้เศษ 0 แล้วจะทำงาน ซึ่งเงื่อไขนี้ใช้เพื่อ หน่วงการเคลื่อนที่ของคน ให้เดินเป็น step
if (position[0]+15<= width+80 && position[1] == 125) {
position[0]+= inc;
}
if (position[0]+15>width+70 && position[1] == 125 ) {
position[4]-=inc;
}
if (position[4]+15 <= -80 && position[5]== 275 ) {
position[0]= -100;
position[4] = 550;
}
if (rounds>=2) {
if (position[2]+15<= width+80 && position[3] == 125) {
position[2]+= inc;
}
if (position[2]+15>width+70 && position[3] == 125 ) {
position[6]-=inc;
}
if (position[6]+15 <= -80 && position[7]== 275 ) {
position[2]= -370;
position[6] = 620;
}
}
if (position[4] == -80) {
rounds++;
}
}
}
void keyPressed() { //ฟังก์ชั่นที่ใช้ในการกดปุ่ม
if (key == 'w' ) { //สร้างเงื่อนไขว่าถ้ากดปุ่ม w
if ( position[0]+15 >= checkscoreArea-10 && position[0]+15<= checkscoreArea+50 ) {
//และถ้าตำแหน่งที่2 +15 มีค่ามากกว่าหรือเท่ากับ checkscoreArea-10และตำแหน่งที่2+15มีค่าน้อยกว่าหรือเท่ากับcheckscoreArea+50
if (position[1] == 125 ) { //และถ้าค่าตำแหน่งที่3 =125
scores = scores + 1; //ให้เพิ่มค่าscoreครั้งละ1
}
checkscoreArea = 0; //ให้เปลี่ยนค่าcheckเท่ากับ 0
}
if (position[2]+15 >= checkscoreArea1-10 && position[2]+15<= checkscoreArea1+50) {
//สร้างเงื่อนไขว่าถ้าตำแหน่งที่4+15มากกว่าหรือเท่ากับcheck1 -10และมีค่าน้อยกว่าหรือเท่ากับcheck1+50
if (position[3] == 125 ) { //สร้างเงื่อนไขว่าถ้าค่าของตำแหน่งที่3 =125
scores = scores + 1; //ให้เพิ่มค่าscoreครั้งละ1
}
checkscoreArea1 = 0; //เปลี่ยนค่าcheck1เป็น0
}
strokeWeight(1); //ให้น้ำหนักเส้น=1
drawmanhold(150, 190); //เรียกฟังก์ชั่นวาดคนมารับโดยกำหนดค่าx,yให้กับฟังก์ชั่น
}
if (key == 'd' ) { //สร้างเงื่อนไขว่าถ้ากดปุ่มd
if (position[4]-15 >= checkscoreArea+630 && position[4]-15 <= checkscoreArea+697) {
//ถ้าค่าของตำแหน่งที่4-15มากกว่าหรือเท่ากับค่าcheck+360และตำแหน่งที่4-15น้อยกว่าหรือเท่ากับcheck+697
if (position[5] == 275) { //ถ้าค่าตำแหน่งที่5 เท่ากับ275
scores = scores + 1; //ให้เพิ่มค่าscoreครังละ1
}
checkscoreArea=-800;
}
if (position[6]-15 >= checkscoreArea1+780 && position[6]-15 <= checkscoreArea1+847) {
//ถ้าค่าของตำแหน่งที่6-15มากกว่าหรือเท่ากับcheck1+780และน้อยกว่าหรือเท่ากับcheck1+847
if (position[7] == 275) { //และถ้าตำแหน่งที่ 7 เท่ากับ275
scores = scores + 1; //ให้เพิ่มค่าscoreครังละ1
}
checkscoreArea1=-800;
}
strokeWeight(1); //ให้น้ำหนักเส้น=1
drawmanhold(150, 340); //เรียกฟังก์ชั่นวาดคนมารับโดยกำหนดค่าx,yให้กับฟังก์ชั่น
}
if (key == 'o' ) { //สร้างเงื่อนไขว่าถ้ากดปุ่มo
if (position[0]+15 >= checkscoreArea+235 &&position[0]+15 <= checkscoreArea+290) {
//ถ้าค่าของตำแหน่งที่0+15มากกว่าหรือเท่ากับcheck+235และน้อยกว่าหรือเท่ากับcheck+290
if (position[1] == 125) { //และถ้าตำแหน่งที่ 1 เท่ากับ125
scores = scores + 1; //ให้เพิ่มค่าscoreครังละ1
}
checkscoreArea=-290;
}
if (position[2]+15 >= checkscoreArea1+235 &&position[2]+15 <= checkscoreArea1+290) {
//ถ้าค่าของตำแหน่งที่2+15มากกว่าหรือเท่ากับcheck+235และน้อยกว่าหรือเท่ากับcheck+290
if (position[3] == 125) {//และถ้าตำแหน่งที่ 3 เท่ากับ125
scores = scores + 1; //ให้เพิ่มค่าscoreครังละ1
}
checkscoreArea1=-510;
}
strokeWeight(1);
drawmanhold(300, 190); //เรียกฟังก์ชั่นวาดคนมารับโดยกำหนดค่าx,yให้กับฟังก์ชั่น
}
if (key == 'k' ) { //สร้างเงื่อนไขว่าถ้ากดปุ่มk
if (position[4]-15 >= checkscoreArea+525 && position[4]-15 <=checkscoreArea+585) {
if (position[5]== 275) {
scores = scores + 1;
}
checkscoreArea = -550;
}
if (position[6]+15 >= checkscoreArea1+745 && position[6]+15 <=checkscoreArea1+805) {
if (position[7]== 275) {
scores = scores + 1;
}
checkscoreArea1 = -700;
}
strokeWeight(1);
drawmanhold(300, 340); //เรียกฟังก์ชั่นวาดคนมารับโดยกำหนดค่าx,yให้กับฟังก์ชั่น
}
if ( checkscoreArea==-800) { //สร้างเงื่อนไขว่าค่าcheckเท่ากับ-800หรือไม่
checkscoreArea = 90; //ถ้าเข้าเงื่อนไขให้เปลี่ยนค่าcheck เท่ากับ90
}
if ( checkscoreArea1==-800) { //สร้างเงื่อนไขว่าค่าcheck1เท่ากับ-800หรือไม่
checkscoreArea1 = 90; //ถ้าเข้าเงื่อนไขให้เปลี่ยนค่าcheck1 เท่ากับ90
}
}
void checkgameover(int divided) {//สร้างฟังก์ชั่นgameoverโดยรับค่าพารามิเตอร์ที่ชื่อว่า divided
if (count%divided==0) { //สร้างเงื่อนไขถ้าค่าcountหารค่าdividedแล้วเหลือเศษ 0
if (key != 'w') { //ถ้าไม่ได้กดปุ่มw
if (position[0]>= 87&& position[0]<=110 ) {
//ถ้าค่าตำแหน่งที่ 0 มากว่าเท่ากับ87และน้อยกว่าหรือเท่ากับ110
position[0] =95; //ให้ค่าของตำแหน่งที่ 0 เท่ากับ95
position[1]+=1; //ให้เพิ่มค่าของตำแหน่งที่1 เพิ่มขึ้นครั้งละ1
}
if (position[2]>= 87&& position[2]<=110 ) {
//ถ้าค่าตำแหน่งที่2มากว่าเท่ากับ87และน้อยกว่าหรือเท่ากับ110
position[2]=95; //ให้ค่าของตำแหน่งที่2เท่ากับ95
position[3]+=1; //ให้เพิ่มค่าของตำแหน่งที่3เพิ่มขึ้นครั้งละ1
}
}
if (key != 'o') { //ถ้าไม่ได้กดปุ่มo
if (position[0] >= 235&& position[0]<=260) {
//ถ้าค่าตำแหน่งที่0มากว่าเท่ากับ235และน้อยกว่าหรือเท่ากับ260
position[0]=255; //ให้ค่าของตำแหน่งที่0เท่ากับ255
position[1]+=1; //ให้เพิ่มค่าของตำแหน่งที่1เพิ่มขึ้นครั้งละ1
}
if (position[2] >= 235&& position[2]<=260) {
//ถ้าค่าตำแหน่งที่2มากว่าเท่ากับ235และน้อยกว่าหรือเท่ากับ260
position[2]=255; //ให้ค่าของตำแหน่งที่2เท่ากับ255
position[3]+=1; //ให้เพิ่มค่าของตำแหน่งที่3เพิ่มขึ้นครั้งละ1
}
}
if (key != 'k') { //ถ้าไม่ได้กดปุ่มk
if (position[4]>= 240&& position[4]<=270) { //ถ้าค่าตำแหน่งที่4มากว่าเท่ากับ240และน้อยกว่าหรือเท่ากับ270
position[4]= 275; //ให้ค่าของตำแหน่งที่1เท่ากับ275
position[5]+=1; //ให้เพิ่มค่าของตำแหน่งที่0เพิ่มขึ้นครั้งละ1
}
if (position[6] >= 240&& position[6]<=270) {
//ถ้าค่าตำแหน่งที่5มากว่าเท่ากับ240และน้อยกว่าหรือเท่ากับ270
position[6]= 275; //ให้ค่าของตำแหน่งที่6เท่ากับ275
position[7]+=1; //ให้เพิ่มค่าของตำแหน่งที่7เพิ่มขึ้นครั้งละ1
}
}
if (key != 'd') { //ถ้าไม่ได้กดปุ่มd
if (position[4]>= 120&& position[4]<=148) {
//ถ้าค่าตำแหน่งที่4มากว่าเท่ากับ120และน้อยกว่าหรือเท่ากับ148
position[4] = 130; //ให้ค่าของตำแหน่งที่4เท่ากับ130
position[5]+=1; //ให้เพิ่มค่าของตำแหน่งที5เพิ่มขึ้นครั้งละ1
}
else if (position[6]>= 120&& position[6]<=148) {
//แล้วถ้าตำแหน่งที่6มากกว่าหรือเท่าหับ120และน้อยกว่าหรือเท่ากับ148
position[6] = 130; //ให้ค่าของตำแหน่งที่6เท่ากับ130
position[7]+=1; //ให้เพิ่มค่าของตำแหน่งที7เพิ่มขึ้นครั้งละ1
}
}
}
if (position[1]>125) { //ถ้าค่าตำแหน่งที่1มากกว่า125
position[1]++; //ให้เพิ่มค่าตำแหน่งที่1ครั้งละ1
}
if (position[5]>275) { //ถ้าค่าตำแหน่งที่5มากกว่า275
position[5]++; //ให้เพิ่มค่าตำแหน่งที่5ครั้งละ1
}
if (position[3]>125) { //ถ้าค่าตำแหน่งที่3มากกว่า125
position[3]++; //ให้เพิ่มค่าตำแหน่งที่3ครั้งละ1
}
if (position[7]>275) { //ถ้าค่าตำแหน่งที7มากกว่า275
position[7]++; //ให้เพิ่มค่าตำแหน่งที่7ครั้งละ1
}
if (position[1] >= 135 || position[5]>=286 || position[3] >= 135 || position[7]>=286) {
// เชคระยะแกน y ว่ามันตกแล้วหรือยัง ถ้าตกแล้วให้ทำต่อ
if (position[0] == 95 || position[2] == 95 ) {
drawmanfall(110, 190); //วาดรูปคนที่หล่น
if (position[1] > 200 || position[3] > 200) {
position[1] = 450;
position[3] = 450;
}
}
if (position[0] == 255 || position[2] == 255) {
drawmanfall(255, 190);
if (position[1]> 200 || position[3]> 200) {
position[1] = 450;
position[3] = 450;
}
}
if (position[4] == 130 || position[6] == 130) {
drawmanfall(110, 340);
if (position[5]> 350 || position[7] > 350) {
position[5]= 450;
position[7] = 450;
}
}
if (position[4]== 275 || position[6]== 275) {
drawmanfall(255, 340);
if (position[5] > 350 || position[7] > 350) {
position[5] = 450;
position[7] = 450;
}
}
changefoot=0;
}
if (position[1] >= 126) { //เชคระยะแกน y เมื่อคนหล่นแล้วให้เซตค่า
position[2] = 450;
position[4] = 450;
position[6] = 450;
}
if (position[3] >= 126) {//เชคระยะแกน y เมื่อคนหล่นแล้วให้เซตค่า
position[0] = 450;
position[4] = 450;
position[6] = 450;
}
if (position[5] >= 276) { //เชคระยะแกน y เมื่อคนหล่นแล้วให้เซตค่า
position[0] = 450;
position[2] = 450;
position[6] = 450;
}
if (position[7] >= 276) { //เชคระยะแกน y เมื่อคนหล่นแล้วให้เซตค่า
position[0] = 450;
position[2] = 450;
position[4] = 450;
}
}
void showmissed() { // ฟังก์ชันแสดงชีวิตที่เหลืออยู่เมื่อมีคนตกน้ำ
if (position[3]==450 || position[0] == 450 || position[6]==450 || position[7] == 450) {
miss++;
}
if (position[3] ==450 || position[6] == 450) {
position[3] =125;
position[2]= -100;
position[6] = 125;
position[4] = -370;
check = 90;
check1 = 90;
}
if (position[0]== 450 || position[7]== 450) {
position[1]= 550;
position[0] = 275;
position[5]= 620;
position[7] = 275;
check = -290;
check1 = -510;
}
if (miss >0) { // ตรวจสอบงื่อนไขเพื่อวาดรูปชีวิตที่เหลืออยู่ของคน
noStroke();
drawmiss(150, 15);
if (miss >1) {
drawmiss(185, 15);
}
if (miss >2) { // ถ้าคนตกน้ำครบ 3 รอบ จะขึ้นปุ่ม TryAgain กับ Manu
drawmiss(220, 15);
fill(#FF6C17);
textSize(50);
text("Game Over", (width/4)-20, 140);
position[3] = 451;
position[0] = 451;
position[6] = 451;
position[7] = 451;
drawTryAgainbutton();
drawManubutton();
}
}
}
Manhole Game and Watch







ไม่มีความคิดเห็น:
แสดงความคิดเห็น