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;
//ใช้เชคช่วงเพื่อเปลี่ยนการวาดรูปเท้าของคนเดิน
int inc = 1;
//ตัวแปร int เอาไว้สำหรับเพิ่ม ลด ระยะแกน x ของคนเดินทั้งในโหมด step และ smooth
void setup() {
size(400, 400); //กำหนดขนาดหน้าจอ
}
void draw() {
drawstartpage();
startSmooth();
startStep();
}
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 ) {
drawbackgrounds();
drawMantop(position[0],position[1]); // เรียกใช้ฟังก์ชันวาดคนเดินแบบรับพารามิเตอร์แกน x , y
drawMantop(position[2],position[3]);
drawManbottom(position[4],position[5]);
drawManbottom(position[6],position[7]);
changeSmooth();
keyPressed();
gameover(1);
showmissed();
}
if (stateButton == 2) {
drawbackgrounds();
drawMantop(position[0],position[1]);
drawMantop(position[2],position[3]);
drawManbottom(position[4],position[5]);
drawManbottom(position[6],position[7]);
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() {
// ฟังก์ชัน drawbackgrounds แก้ไขโดยการแยกเป็นฟังก์ชันย่อยๆ เพื่อลดขนาดของฟังก์ชัน
drawbackgrounds
background(#C9FFFB); //ใส่สีพื้นหลังสีฟ้า
drawwall(0, 180);
drawwall(152, 180);
drawwall(315, 180);
drawcurvofwall(150, 180);
drawwall(0, 330);
drawwall(150, 330);
drawwall(315, 330);
drawcurvofwall(150, 330);
drawwater(95, 180);
drawwater(245, 180);
drawwater(95, 330);
drawwater(245, 330);
drawmountain();
drawcloud();
fill(0);
textSize(15);
text("Miss ", 100, 20); //เขียนคำว่า Miss
text("Score = "+ scores, 300, 50); //เขียนคำว่า Score
highScore(); //เรียกใช้ฟังก์ชัน highScore
}
void drawwall(int x, int y) { // วาดกำแพงสำหรับคนเดิน
fill(0);
stroke(#5A2E01);
strokeWeight(10);
line(x, y, x+80, y); //วาดขอบบนทางเดิน
noStroke();
fill(#A77413);
rect(x, y, 80, 50); //วาดกำแพง
}
void drawcurvofwall(int x, int y) { // ฟังก์ชันวาดส่วนเว้าของกำแพง
fill(#C9FFFB);
ellipse(x+80, y+30, 50, 60);
ellipse(x, y+30, 50, 60);
ellipse(x-150, y+30, 50, 60);
ellipse(x-70, y+30, 50, 60);
ellipse(x+165, y+30, 50, 60);
fill(#C9FFFB);
ellipse(x+245, y+30, 50, 60);
}
void drawwater(int x, int y) { //ฟังก์ชันวาดน้ำ
fill(#2BDED0);
ellipse(x, y+50, 20, 5);
ellipse(x+15, y+45, 20, 5);
ellipse(x+30, y+50, 20, 5);
ellipse(x+45, y+45, 20, 5);
}
void drawmountain() { // ฟังก์ชันวาดรูปภูเขา
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);
}
void drawcloud() { // ฟังก์ชันวาดรูปก้อนเมฆ
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);
}
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<=40) {//ฟังก์ชั่นวาดภาพขาคนเดิน โดยรับพาริมิเตอร์นำไปใช้เป็นพิกัดแกน 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>40 && changefoot<80) {
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);
}
changefoot++;
if (changefoot == 80) {
changefoot=0;
}
}
void drawMantop(int x,int y) {
if (y >=125 && y< 135) {
drawFaceman(x, y);
ellipse(x-1,y-5, 8, 10); // ตา
ellipse(x+7,y-5, 7, 10);
fill(0);
ellipse(x,y-5, 4, 4);
ellipse(x+8,y -5, 4, 4);
ellipse(x+15,y, 10, 5);// จมูก
drawBodyman(x,y);
drawHandmantop(x, y);
drawLegman(x, y);
}
}
void drawManbottom(int x,int y) { // ฟังก์ชันวาดคนเดินด้านล่าง แบบ รับพารามิเตอร์เป็นพิกัดแกน x ,y เพื่อวาดคน
if (y>= 275 && y < 285) {
drawFaceman(x,y);
ellipse(x-8,y-5, 8, 10); // ตา
ellipse(x, y-5, 7, 10);
fill(0);
ellipse(x-10,y-5, 4, 4);
ellipse(x-2,y-5, 4, 4);
ellipse(x-15,y, 10, 5);// จมูก
drawBodyman(x, y);
drawHandmanbottom(x, y);
drawLegman(x, y);
}
}
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++;
}
}
count++;
}
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เพื่อไม่ให้เข้าเงื่อนไขของฟังก์ชัน keypressed();
position[1]++; //ให้เพิ่มค่าตำแหน่งที่1ครั้งละ1
}
if (position[5]>275) { //ถ้าค่าตำแหน่งที่5มากกว่า275เพื่อไม่ให้เข้าเงื่อนไขของฟังก์ชัน keypressed();
position[5]++; //ให้เพิ่มค่าตำแหน่งที่5ครั้งละ1
}
if (position[3]>125) { //ถ้าค่าตำแหน่งที่3มากกว่า125เพื่อไม่ให้เข้าเงื่อนไขของฟังก์ชัน keypressed();
position[3]++; //ให้เพิ่มค่าตำแหน่งที่3ครั้งละ1
}
if (position[7]>275) { //ถ้าค่าตำแหน่งที7มากกว่า275เพื่อไม่ให้เข้าเงื่อนไขของฟังก์ชัน keypressed();
position[7]++; //ให้เพิ่มค่าตำแหน่งที่7ครั้งละ1
}
if (position[1] >= 135 || position[5]>=286 || position[3] >= 135 || position[7]>=286) {
// เชคระยะแกน y มากกว่า 135 หรือ 286 แล้วหรือยัง (ซึ่งตอนนี้ตัวคนที่เดินจะไม่แสดงแล้ว)
if (position[0] == 95 || position[2] == 95 ) {
drawmanfall(110, 190);
//เรียกฟังก์ชันวาดรุปคนที่ตกน้ำและจะวาดคนตกน้ำจนกระทั่ง แกน y ของคนเดินด้านบนมากกว่า 200
if (position[1] > 200 || position[3] > 200) {
// เมื่อแกน y ของคนเดินด้านบน มากกว่า 200 แล้ว ให้ค่า y เท่ากับ 450 ทำให้คนตกน้ำหายไป
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);
//เรียกฟังก์ชันวาดรุปคนที่ตกน้ำและจะวาดคนตกน้ำจนกระทั่ง แกน y ของคนเดินด้านล่างมากกว่า 350
if (position[5]> 350 || position[7] > 350) {
// เมื่อแกน y ของคนเดินด้านบน มากกว่า 350 แล้ว ให้ค่า y เท่ากับ 450 ทำให้คนตกน้ำหายไป
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;
}
}
}
}
void otherdisappear(){ // ฟังก์ชันตรวจสอบเงื่อนไขเพื่อให้ตัวละครอื่นๆที่ยังไม่ตกหายไป เมื่อมีตัวละครตัวใดตัวหนึ่งตกแล้ว
// ***** ไม่สามารถยุบรวมฟังก์ชันได้เนื่องจากคำสั่งที่ทำเมื่อเข้าเงื่อนไขนั้นไม่เหมือนกัน
if (position[1] >= 126) {
position[2] = 450;
position[4] = 450;
position[6] = 450;
}
if (position[3] >= 126) {
position[0] = 450;
position[4] = 450;
position[6] = 450;
}
if (position[5] >= 276) {
position[0] = 450;
position[2] = 450;
position[6] = 450;
}
if (position[7] >= 276) {
position[0] = 450;
position[2] = 450;
position[4] = 450;
}
}
void showmissed() {
if (position[1]==450 || position[5] == 450 || position[3]==450 || position[7] == 450) {
// ตรวจสอบหากมีแกน y ของคนหนึ่งเท่ากับ 450 ให้ค่า miss เพิ่มขึ้นทีละ 1
miss++;
}
if (position[1] ==450 || position[3] == 450) {
//ตรวจสอบเงื่อนไขถ้าหากมีแกน y ของตัวที่ 1 หรือ 2 ข้างบน เท่ากับ 450 (ตกน้ำ)
ให้ทุกตัวที่อยู่ข้างบนเริ่มเคลื่อนที่ใหม่ตามค่าที่กำหนด ต่อไปนี้
position[1] =125;
position[0]= -100;
position[3] = 125;
position[2] = -370;
checkscoreArea = 90;
checkscoreArea1 = 90;
}
else if (position[5]== 450 || position[7]== 450) {
//ตรวจสอบเงื่อนไขถ้าหากมีแกน y ของตัวที่ 1 หรือ 2 ข้างล่าง เท่ากับ 450 (ตกน้ำ)
ให้ทุกตัวที่อยู่ข้างล่างเริ่มเคลื่อนที่ใหม่ตามค่าที่กำหนด ต่อไปนี้
position[4]= 550;
position[5] = 275;
position[6]= 620;
position[7] = 275;
checkscoreArea = -290;
checkscoreArea1 = -510;
}
if (miss>0) { // ตรวจสอบเงื่อนไขเพื่อวาดรูปหน้าคน หรือ ชีวิตที่เหลืออยุ่ในการเล่นเกม
noStroke();
drawmiss(150, 15);
if (miss >1) {
drawmiss(185, 15);
}
if (miss>2) {
// เมื่อตกน้ำครบ 3 รอบ ให้แสดงข้อความ Game over และ เรียกใช้ฟังก์ชันวาดปุ่ม TryAgain และ Manu
drawmiss(220, 15);
fill(#FF6C17);
textSize(50);
text("Game Over", (width/4)-20, 140);
position[1] = 451;
position[5] = 451;
position[3] = 451;
position[7] = 451;
drawTryAgainbutton();
drawManubutton();
}
}
}
comprofun
วันพุธที่ 30 ตุลาคม พ.ศ. 2556
วันจันทร์ที่ 28 ตุลาคม พ.ศ. 2556
28/10/56
สรุป 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 check = 90;
int check1 =90;
// ตัวแปรชนิด จำนวนเต็ม เก็บระยะเพื่อเพิ่มคะแนน
int stateButton =0;
// ตัวแปรชนิด จำนวนเต็ม เช๊คสถานะของปุ่ม
int scores = 0;
// ตัวแปรชนิด จำนวนเต็ม เก็บคะแนนก่อน gameover
int rounds = 1;
// ตัวแปรชนิด จำนวนเต็ม เก็บจำนวนรอบของเกม
int [] position = new int [8];
// ตัวแปรอาเรย์ ชนิด จำนวนเต็ม เก็บตำแหน่งเริ่มต้นของคนเดิน
ซึ่งเก็บเป็นแบบอาเรย์จะช่วยให้ ลดการประกาศ global variable ไปได้มาก
int count = 0;
// ตัวแปรชนิด จำนวนเต็ม เพื่อนับค่าเพิ่มขึ้นเรื่อยๆ
int changeconvert=0
// ตัวแปรชนิด จำนวนเต็ม เก็บค่าเพื่อใช้ในการสลับขาของคนเดิน
วันพฤหัสบดีที่ 24 ตุลาคม พ.ศ. 2556
ส่วนที่เหลือต้องทำในเกมและหน้าที่ที่เหลือ
ในส่วนเกมในรูปแบบ step ที่ยังทำไม่เสร็จสมบูรณ์
ซึ่งเหลือในส่วนบัคของเกมโดยในส่วนนี้ทั้งสามคนในกลุ่มจะช่วยกันหาและแก้ไขในส่วนที่เหลืส่วนที่เหลือ เพราะในส่วนของฟังก์ชั่นนั้นมีครบแต่อาจจะมีเพิ่มตามความเหมาะสมรวมเวลาที่ใช้ประมะาณ 2-3วัน
ซึ่งเหลือในส่วนบัคของเกมโดยในส่วนนี้ทั้งสามคนในกลุ่มจะช่วยกันหาและแก้ไขในส่วนที่เหลืส่วนที่เหลือ เพราะในส่วนของฟังก์ชั่นนั้นมีครบแต่อาจจะมีเพิ่มตามความเหมาะสมรวมเวลาที่ใช้ประมะาณ 2-3วัน
แก้ไขCOMMENT
ในส่วน Global Variable มีชื่อตัวแปรที่ไม่สื่อความหมาย ซึ่งคอมเม้นไว้ด้านหลังตัวแปรแล้ว
int x=-100; //ชื่อตัวแปรไม่สื่อความหมาย //ค่าที่ใช้บอกตำแหน่งในแกน x
int r_smooth = 80; //rคืออะไร ไม่สื่อความหมาย // r ย่อมาจาก radius คือรัศมีของปุ่ม smooth ที่ใช้กดในขั้นตอนการเล่น แก้เป็น r_smooth_button
int r_step = 80; //rคืออะไร ไม่สื่อความหมาย // r คือ รัศมีของปุ่ม step ที่ใช้กดในขั้นตอนการเล่น แก้เป็น r_smooth_button
int x_butt=0; //ชื่อตัวแปรไม่สื่อความหมาย // ชัดเจนว่าเป็นตำแหน่งในแกน x ของปุ่ม
int chk_SMOOTH=0;
int chk_STEP=0;
int a, b, g; //ชื่อตัวแปรไม่สื่อความหมาย // โค้ดสีของ ฟังก์ชั่น startpage แก้เป็น r,g,b ตามหลักแม่สี
float dx, dy, total; //ชื่อตัวแปรไม่สื่อความหมาย
int highscore;
int c = 90; //ชื่อตัวแปรไม่สื่อความหมาย// chk_fallareatop
int c1 = 90; //ชื่อตัวแปรไม่สื่อความหมาย//chk_fallareabottom
int j = 0; //ชื่อตัวแปรไม่สื่อความหมาย//startbutton_state
int j1 = 0; //ชื่อตัวแปรไม่สื่อความหมาย//tryagainbutton_state
int inc = 1; //ชื่อตัวแปรไม่สื่อความหมาย//carrymove
int count = 0; //countของฟังก์ชั่นไหน ระบุฟังก์ชั่นด้วย//count_score
int rounds = 1;
int s = 0; //ชื่อตัวแปรไม่สื่อความหมาย // carry_number
int d =50; //ชื่อตัวแปรไม่สื่อความหมา //speed
int k = 320; //ชื่อตัวแปรไม่สื่อความหมาย // x_start_button
int k1 = 50; //ชื่อตัวแปรไม่สื่อความหมาย // y_start_button
int ytop = 125; //ชื่อตัวแปรไม่สื่อความหมาย// y_moveman_top
int xtop = -100; //ชื่อตัวแปรไม่สื่อความหมาย //x_moveman_top
int xbot = 470; //ชื่อตัวแปรไม่สื่อความหมาย // x_moveman_bottom
int ybot = 275; //ชื่อตัวแปรไม่สื่อความหมาย//y_moveman_bottom
วันพุธที่ 23 ตุลาคม พ.ศ. 2556
COMMENTGROUP5
จากเกม fire ของกลุ่มที่ 5 มีจำนวน global variable ทั้งหมด 23 ตัวแปร ซึ่งตัวแปรแต่ละตัวนั้นมีชื่อที่บ่งบอกถึงค่าของตัวแปรนั้นๆได้อย่างชัดเจนแต่บางทีชื่อตัวแปรบางตัวอาจจะยาวเกินไปซึ่งสามารถย่อได้
เพื่อให้ในเวลาใช้ในฟังก์ชั่นนั้นใช้ได้สะดวกกว่า
boolean gameSmooth = true;
//ประกาศตัวแปร gameSmooth เพื่อบอกให้เกมทำงานแบบ smooth หรือ step ถ้า gameSmooth เป็น true ให้เกมทำงานแบบ smooth ถ้าเป็น false ให้เกมทำงานแบบ step
int playerHealthPoint = 3;
//ประกาศตัวแปร playerHealtPoint เพื่อบอกว่าผู้เล่นสามารถพลาดในการรับผู้ที่ตกลงมาจากตึกเป็นจำนวนเท่าใด
int playerScore = 0;
//ประกาศตัวแปร playerScore เพื่อบันทึกค่าคะแนนที่ผู้เล่นสามารถทำได้
int nowGamePage = 0;
//ประกาศตัวแปร nowGamePage เพื่อบอกให้เกมทำงานเป็นหน้าๆ โดยเมื่อ nowGamePage เท่ากับ 0 จะแสดงหน้าเมนู หากเท่ากับ 1 จะแสดงหน้าเล่นเกม
int hospitalManPos = 0;
//ประกาศตัวแปร hospitalManPos ใช้ในการทำเกมแบบ step เพื่อบอกว่า ตัวรับหรือผู้เล่นนั้นอยู่ในตำแหน่งใด
float addDropperTime = 500;
//ประกาศตัวแปร addDropperTime เพื่อกำหนดเวลาว่าเวลาใดจะให้คนโดดตึกลงมา
float addDropperTimeCount = 600f;
//ประกาศตัวแปร addDropperTimeCount เพื่อนับเวลาไปเทียบกับ addDropperTime ที่ใช้ในการสร้างตัวกระโดดตึก
int[] dropPositionStep = new int[ 0 ];
//ประกาศตัวแปร dropPositionStep เพื่อเก็บตำแหน่งของผู้ที่กระโดดตึกลงมา
float[] dropTimeStep = new float[ 0 ];
//ประกาศตัวแปร dropTimeStep เพื่อเก็บเวลาในการเปลี่ยน frame ของตัวที่กระโดดตึกลงมา
float[] currentDropTimeStep = new float[ 0 ];
//ประกาศตัวแปร currentDropTimeStep เพื่อนับเวลาไปเทียบกับ dropTimeStep ในการเปลี่ยน frame
float dropTimeStepSpeed = 50;
//ประกาศตัวแปร dropTimeStepSpeed เพื่อใช้กำหนดความเร็วเมื่อผู้เล่นเริ่มกระโดดตึกโดยจะลดลงเรื่อยๆภายในการเล่น
float hotspitalManPosSmooth = -180f;
//ประกาศตัวแปร hospitalManPosSmooth เพื่อเก็บตำแหน่งของผู้รับหรือตัวเล่นนั้นอยู่ในตำแหน่งใด
float[] dropperPositionXSmooth = new float[ 0 ];
//ประกาศตัวแปร dropperPositionXSmooth เพื่อเก็บค่าตำแหน่งตัวที่กระโดดในแกน X ในการเล่นแบบ smooth
float[] dropperPositionYSmooth = new float[ 0 ];
//ประกาศตัวแปร dropperPositionYSmooth เพื่อเก็บค่าตำแหน่งตัวที่กระโดดในแกน Y ในการเล่นแบบ smooth
float[] dropperSmoothSpeed = new float[ 0 ];
//ประกาศตัวแปร dropperSmoothSpeed เพิ่อกำหนดความเร็วตัวที่ตกลงมาจากตึกในการเล่นแบบ smooth
int startPlayerHealthPoint;
//ประกาศตัวแปรเพื่อเก็บค่าเริ่มต้นของ playerHealthPoint ไว้เพื่อใช้ในการ restart game
boolean gameIsStart = true;
//ประกาศตัวแปร gameIsStart เพื่อกำหนดว่าเกมเริ่มขึ้นหรือยัง
boolean isOverButtonStep = false;
//ประกาศตัวแปร isOverButtonStep เพื่อเก็บค่าไว้บอกเกี่ยวกับปุ่มการเล่นเกมแบบ step ในหน้าเมนู
boolean isOverButtonSmooth = false;
//ประกาศตัวแปร isOverButtonSmooth เพื่อเก็บค่าไว้บอกเกี่ยวกับปุ่มการเล่นเกมแบบ smooth ในหน้าเมนู
int smokeTime = 0;
//ประกาศตัวแปร smokeTime เพื่อกำหนดเวลาว่าเวลาใดจะให้เปลี่ยน frame ของควันไฟ
int smokeStep = 0;
//ประกาศตัวแปร smokeStep เพื่อใช้กำหนดตำแหน่งของควันไฟในแต่ละ step
int lightAmbulanceTimeCount = 0;
//ประกาศตัวแปร lightAmbulanceTimeCount เพื่อใช้นับเวลาของไฟกระพริบบริเวณรถพยาบาล
int lightAmbulanceStep = 0;
//ประกาศตัวแปร lightAmbulanceStep เพื่อใช้กำหนดเวลาให้ไฟกระพริบนานเท่าไหร่ โดยค่ายิ่งมาก ไฟก็ยิ่งกระพริบช้า
void setup ()
//เป็นฟังก์ชั่นเพื่อกำหนดค่าต่างๆของเกม
{
size( 800, 550 ); //กำหนดขนาดหน้าจอของเกมส์
startPlayerHealthPoint = playerHealthPoint; //เก็บจำนวนที่ผู้เล่นสามารถพลาดใส่ตัวแปร startPlayerHealthPoint เพื่อใช้ในการเริ่มเกมส์ใหม่
}
ฟังก์ชั่นมีจำนวนฟังก์ชั่นทั้งหมด 30ฟังก์ชั่น ซึ่งแต่ละฟังก์ชั่นก็มีชื่อที่บ่งบอกถึงการทำงานของฟังก์ชั่นนั้นได้ชัดเจนแต่ชื่อฟังก์ชั่นบางตัวอาจจะยาวเกินไปบางทีอาจสามารถแก้ไขชื่อฟังก์ชั่นบางตัวโดยการย่อชื่อฟังก์ชั่นได้ และชื่อฟังก์ชั่นบางตัวเมื่อได้อ่่านแล้วทำให้ไม่เข้าใจในความหมายของฟังก์ชั่นนั้นๆว่าใช้ทำอะไร อย่างเช่น droppositionstep(); ที่ไม่เข้าใจความหมายองฟังก์ชั่นนี้ว่าต้องการให้ทำไรอะไร
void draw () //เป็นฟังก์ชั่นที่ถูกเรียกใช้ในการ update สิ่งต่างๆที่เกิดขึ้นในทุกๆ frame
{
background( 255 ); //กำหนดสีของพิ้นหลัง
if ( nowGamePage == 0 )
//ตรวจสอบว่า nowGamePage มีค่าเท่าใด หากเป็น 0 เรียกฟังก์ชัน StartPage ส่วนหากเท่ากับ 1 ให้เรียกฟังก์ชัน GamePage
{
StartPage(); //เรียกฟังก์ขั่นเพื่อแสดงผลหน้าเมนู
}
else if ( nowGamePage == 1 )
{
GamePage(); //เรียกฟังก์ชั่นเพื่อแสดงผลหน้าเกม
}
}
void keyPressed () //เป็นฟังก์ชั่นที่ถูกเรียกใช้เมื่อกดปุ่ม
{
if ( !gameSmooth ) //ตรวจสอบว่าเกมเป็นประเภทใด smooth หรือ step
{
if ( keyCode == LEFT )
//ตรวจสอบว่าเมื่อกดปุ่มลูกศรซ้าย ให้ทำการเคลื่อนที่ตัวรับไปทางซ้าย 1 ตำแหน่ง โดยมีผลกับเกมแบบ step และตรวจสอบว่าไม่ได้อยู่ในตำแหน่งแรก
{
if ( hospitalManPos > 0 ) hospitalManPos--;
}
else if ( keyCode == RIGHT )
//ตรวจสอบว่าเมื่อกดปุ่มลูกศรขวา ให้ทำการเคลื่อนที่ตัวรับไปทางขวา 1 ตำแหน่ง โดยมีผลกับเกมแบบ step และไม่สามารถเคลื่อนเกินตำแหน่งสุดท้ายได้ ด้วยการกำหนดให้ตำแหน่งสุดท้ายคือตำแหน่งที่สาม
{
if ( hospitalManPos < 2 ) hospitalManPos++;
}
}
else
{
if ( keyCode == RIGHT )
//ตรวจสอบกว่าเมื่อกดปุ่มลูกศรขวา ให้ทำการเคลื่อนที่ ตัวรับไปทางขวา 10 หน่วย โดยมีผลกับเกมแบบ smooth และไม่สามารถเคลื่อนที่ได้เกินตำแหน่งที่กำหนด
{
if ( hotspitalManPosSmooth < 150 ) hotspitalManPosSmooth += 10f;
}
else if ( keyCode == LEFT )
//ตรวจสอบกว่าเมื่อกดปุ่มลูกศรซ้าย ให้ทำการเคลื่อนที่ ตัวรับไปทางซ้าย 10 หน่วย โดยมีผลกับเกมแบบ smooth และไม่สามารถเคลื่อนที่ได้เกินตำแหน่งที่กำหนด
{
if ( hotspitalManPosSmooth > -180f ) hotspitalManPosSmooth -= 10f;
}
}
}
void mousePressed () //เป็นฟังก์ชั่นที่เรียกใช้เมื่อทำการคลิกเมาส์
{
if ( isOverButtonStep )
//ตรวจสอบว่า isOverButtonStep เป็นจริงหรือไม่ หากเป็นจริงให้ทำการเปลี่ยนหน้าไปที่หน้าเกม และเลือกเกมเป็นแบบ step
{
gameSmooth = false; //แก้ไขค่า gameSmooth เป็น false
nowGamePage = 1; //แก้ไขค่า nowGamePage เป็น 1
}
if ( isOverButtonSmooth )
//ตวรจสอบว่า isOverButtonSmooth เป็นจริงหรือไม่ หากเป็นจริงให้ทำการเปลี่ยนหน้าไปที่หน้าเกม และเลือกเกมเป็นแบบ smooth
{
gameSmooth = true; //แก้ไขค่า gameSmooth เป็น true
nowGamePage = 1; //แก้ไขค่า nowGamePage เป็น 1
}
if ( !gameIsStart && nowGamePage == 1 )
//ตรวจสอบว่าเกมนั้นเริ่มไปแล้วหรือไม่ หากเกมจบ gameIsStart จะเป็น false และเกมยังอยู่ในหน้าเกม ให้เปลี่ยนไปที่หน้าแรกแล้วทำการเรียกฟังก์ชั่นเพื่อ เริ่มเกมส์ใหม่
{
nowGamePage = 0; //แก้ไขค่า nowGamePage เป็น 0
RestartGame(); //เรียกฟังก์ชั่นเพื่อเริ่มเกมส์ใหม่
}
}
void RestartGame () //ฟังก์ชั่นที่ใช้ในการเริ่มเกมส์ใหม่โดยการเปลี่ยนค่ากลับไปเป็นค่าเริ่มต้นทั้งหมด
{
isOverButtonStep = false; //เปลี่ยน isOverButtonStep เป็น false
isOverButtonSmooth = false; //เปลี่ยน isOverButtonStep เป็น false
playerScore = 0; //เปลี่ยน playerScore หรือ คะแนนของผู้เล่นเป็น 0
playerHealthPoint = startPlayerHealthPoint; //เปลี่ยนค่า playerHealthPoint เป็นค่าเริ่มต้นที่เก็บไว้ใน startPlayerHealthPoint
hospitalManPos = 0; //เปลี่ยนค่า hospitalManPos เป็นค่าเริ่มต้น
addDropperTime = 600f; //เปลี่ยนค่า addDropperTime เป็นค่าเริ่มต้น
addDropperTimeCount = 600f; //เปลี่ยนค่า addDropperTimeCount เป็นค่าเริ่มต้น
dropPositionStep = new int[ 0 ]; //เปลี่ยนค่า dropPositionStep เป็นค่าเริ่มต้น
dropTimeStep = new float[ 0 ]; //เปลี่ยนค่า dropTimeStep เป็นค่าเริ่มต้น
currentDropTimeStep = new float[ 0 ]; //เปลี่ยนค่า currentDropTimeStep เป็นค่าเริ่มต้น
dropTimeStepSpeed = 50; //เปลี่ยนค่า dropTimeStepSpeed เป็นค่าเริ่มต้น
hotspitalManPosSmooth = -180f; //เปลี่ยนค่า hotspitalManPosSmooth เป็นค่าเริ่มต้น
dropperPositionXSmooth = new float[ 0 ]; //เปลี่ยนค่า dropperPositionXSmooth เป็นค่าเริ่มต้น
dropperPositionYSmooth = new float[ 0 ]; //เปลี่ยนค่า dropperPositionYSmooth เป็นค่าเริ่มต้น
dropperSmoothSpeed = new float[ 0 ]; //เปลี่ยนค่า dropperSmoothSpeed เป็นค่าเริ่มต้น
gameIsStart = true; //เปลี่ยนค่า gameIsStart เป็นค่าเริ่มต้น
}
//Game logic
void StartPage () //ฟังก์ชั่นใช้ในการทำงานของหน้าเมนู
{
pushMatrix(); //เริ่มต้น matrix
translate( -100, -90 ); //ย้ายตำแหน่ง matrix ไปที่ -100, -90
scale( 1.2f ); //เปลี่ยนขนาดของ matrix
startFire();
peopleI();
topBuilt();
build();
popMatrix(); //จบการเปลี่ยนค่า matrix
isOverButtonSmooth = CheckOverButton( 140, 350, 190, 80 );
//กำหนดค่า isOverButtonSmooth ด้วยการเรียกฟังก์ชั่น CheckOverButton
if ( isOverButtonSmooth ) StartGameButton( 140, 350, 190, 80, 0, 255, 0 );
//ตรวจสอบว่า isOverButtonSmooth เป็นจริงหรือไม่ ให้เรียกฟังก์ชั่น StartGameButton เพื่อวาดปุ่ม
else StartGameButton( 140, 350, 190, 80, 255, 0, 0 );
textSize(50); //กำหนดขนาดตัวอักษร
fill(0); //ใส่สีให้ตัวอักษร
textAlign(LEFT); //เปลี่ยนให้ตัวหนังสือชิดซ้าย
text("Smooth", 145, 410); //แสดง Text ในปุ่ม
isOverButtonStep = CheckOverButton( 480, 350, 190, 80 );
//กำหนดค่า isOverButtonStep ด้วยการเรียกฟังก์ชั่น CheckOverButton
if ( isOverButtonStep ) StartGameButton( 480, 350, 190, 80, 0, 255, 0 );
//ตรวจสอบว่า isOverButtonStep เป็นจริงหรือไม่ ให้เรียกฟังก์ชั่น StartGameButton เพื่อวาดปุ่ม
else StartGameButton( 480, 350, 190, 80, 255, 0, 0 );
textSize(50);
fill(0);
textAlign(LEFT);
text("Step", 525, 410);
}
void GamePage () //ฟังก์ชั่นใช้ในการทำงานของ gameplay
{
DrawBackground(); //เรียกฟังก์ชั่นใช้ในการวาดพื้นหลัง
DrawBuilding(); //เรียกฟังก์ชั่นใช้ในการวาดตึก
DrawAmbulance( 20, 0 ); //เรียกฟังก์ชั่นใช้ในการวาดรถพยาบาล
smoke(); //เรียกฟังก์ชั่นใช้ในการวาดควัน
if ( playerHealthPoint >= 3 ){
Health( -50 );
Health( 0 );
Health( 50 );
}
else if ( playerHealthPoint >= 2 ){
Health( -50 );
Health( 0 );
}
else if ( playerHealthPoint >= 1 ){
Health( -50 );
}
textSize( 20 );
fill( 0 );
text( "Score : " + playerScore, 610, 60 );
//Smooth
if ( gameSmooth ) //ตรวจสอบว่าเกมเป็น mode ใด smooth หรือ step
{
if ( gameIsStart ) //ตรวจสอบว่าเกมนั้นเริ่มแล้วหรือไม่
{
DrawHospitalMan( hotspitalManPosSmooth, -10 );
//เรียกฟังก์ชั่นเพื่อวาดตัวผู้เล่นหรือคนรับคนโดนตึก
DropperSmoothMove(); //เรียกฟังก์ชั่น DropperSmoothMove ที่ใช้ในการวาดตัวโดดตึกให้เคลื่อนที่
AddDropperSmooth(); //เรียกฟังก์ชั่น AddDropperSmooth ที่ใช้ในการเพิ่มตัวประโดดตึก
DisplayDropperSmooth(); //เรียกฟังก์ชั่น DisplaayDropperSmooth ที่ใช้วาดคนโดดตึก
}
}
// Step
else
{
if ( gameIsStart ) //ตรวจสอบว่าเกมนั้นเริ่มแล้วหรือไม่
{
ChangeStep(); //เรียกฟังก์ชั่น ChangeStep โดยเมื่อถึงเวลาจะเปลี่ยนตำแหน่งของตัวกระโดดตึก
AddDropperStep(); //เรียกฟังก์ชัน AddDropperStep ใช้ในการเพิ่มตัวกระโดดตึก
DisplayDropperStep(); //เรียกฟังก์ชั่น DisplayDropperStep ใช้ในการวาดตัวกระโดดตึก
HospitalManDisplay( hospitalManPos );
//เรียกฟังก์ชั่นเพื่อวาดตัวผู้เล่นหรือคนรับคนโดนตึกในตำแหน่งต่างๆ
}
}
if ( playerHealthPoint <= 0 )
//ตรวจสอบว่าหาก playerHealthPoint เท่ากับ 0 ให้ขึ้นคำว่า Gameover
{
gameIsStart = false; // เปลี่ยนค่า gameIsStart เป็น false
textSize( 50 );
fill( 255, 0, 0 ); //กำหนดตัวหนังสือให้เป็นสีแดง
textAlign(CENTER); //กำหนดการจัดวางของตัวหนังสือให้อยู่ตรงกลาง
text( "Gameover", width / 2, height / 2 ); //แสดง text คำว่า Gameover กลางหน้าจอ
}
}
//Menu
void StartGameButton ( int x, int y, int w, int h, int colorRed, int colorGreen, int colorBlue )
//ฟังก์ชั่นใช้ในการวาดปุ่มโดยการรับค่าตำแหน่งและสี
{
noStroke(); //กำหนดให้ปุ่มไม่มีเส้นขอบ
fill( colorRed, colorGreen, colorBlue ); //กำหนดสีให้ปุ่ม
rect( x, y, w, h ); //วาดสี่เหลี่ยมกลางปุ่ม
ellipse( x, y + ( h / 2 ), h, h ); //วาดวงกลมเพื่อให้ปุ่มดูสวยงาม
ellipse( x + w, y + ( h / 2 ), h, h ); //วาดวงกลมเพื่อให้ปุ่มดูสวยงาม
}
boolean CheckOverButton ( int x, int y, int w, int h )
//ตรวจสอบว่าเมาส์อยู่บนสี่เหลี่ยมของปุ่มหรือไม่ หากอยู่ให้ส่งค่า true กลับ หากไม่ให้ส่งค่า false
{
if ( mouseX >= x && mouseX < x + w && mouseY >= y && mouseY < y + h )
{
return true;
}
return false;
}
//Gameplay_Smooth
void AddDropperSmooth () //ฟังก์ชั่นใช้ในการสร้างตัวกระโดดตึกในเกมโหมด smooth
{
addDropperTimeCount += 1; //เพิ่มค่า addDropperTimeCount
if ( addDropperTimeCount >= addDropperTime )
//ตรวจสอบว่า addDropperTimeCount มากกว่า addDropperTime แล้วหรือไม่ ถ้ามากกว่า ให้สร้างตัวละครขึ้นมาใหม่
{
addDropperTimeCount = 0; //เปลี่ยนค่าเวลาเป็นเวลาเริ่มต้นเพื่อนับใหม่จนถึงรอบอีกครั้ง
if ( addDropperTime > 102f ) addDropperTime -= 60f;
//ตรวจสอบว่าเวลาสร้างน้อยกว่าค่ากำหนดหรือไม่ ถ้ามากกว่าให้ลดเวลาเกิดให้ไวขึ้น
float startPositionX = -200; //สร้างตัวแปรเพื่อกำหนดจุดเกิดแกน X
float startPositionY = -70; //สร้างตัวแปรเพื่อกำหนดจุดเกิดแกน Y
dropperPositionXSmooth = append( dropperPositionXSmooth, startPositionX );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บตำแหน่งแกน X ของตัวกระโดดตึกตัวใหม่
dropperPositionYSmooth = append( dropperPositionYSmooth, startPositionY );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บตำแหน่งแกน Y ของตัวกระโดดตึกตัวใหม่
dropperSmoothSpeed = append( dropperSmoothSpeed, 0 );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บความเร็วของตัวกระโดดตึกตัวใหม่
}
}
void DropperSmoothMove () //ฟังก์ชั่นใช้ในการทำให้ตัวกระโดดตึกเคลื่อนที่ในเกมโหมด smooth
{
float gravity = 0.1; //สร้างตัวแปร gravity เพื่อเก็บค่าสำหรับการคำนวณ
for ( int dropperCount = 0; dropperCount < dropperPositionXSmooth.length; dropperCount++ )
//วนลูปเพื่อสร้างตัวโดดตึกแบบ smooth
{
if ( dropperPositionYSmooth[ dropperCount ] < height )
//ตรวจสอบว่าตำแหน่งแต่ละตัวในแกน Y เกินความสุงหรือไม่ ถ้าเกินไม่ต้องทำลูปนี้
{
if ( dropperPositionYSmooth[ dropperCount ] <= 240 ) dropperPositionXSmooth[ dropperCount ] += 1.5f;
//เปลี่ยนตำแหน่งแกน X
dropperPositionYSmooth[ dropperCount ] += dropperSmoothSpeed[ dropperCount ];
//เปลี่ยนตำแหน่งแกน Y ของตัวกระโดดตึกแต่ละตัว
dropperSmoothSpeed[ dropperCount ] += gravity; //เปลี่ยนความเร็วของตัวกระโดดตึกแต่ละตัว
if ( dropperPositionYSmooth[ dropperCount ] > 230 && dropperPositionYSmooth[ dropperCount ] <= 240 && dropperPositionXSmooth[ dropperCount ] > hotspitalManPosSmooth && dropperPositionXSmooth[ dropperCount ] < hotspitalManPosSmooth + 100 )
//ตรวจสอบว่าตัวกระโดดตึกอยู่ในตำแหน่งที่กำหนดหรือไม่ ถ้าใช่ให้เด้งต่อไป
{
dropperSmoothSpeed[ dropperCount ] = dropperSmoothSpeed[ dropperCount ] * -0.95;
playerScore += 1;
}
else if ( dropperPositionYSmooth[ dropperCount ] > 180 && dropperPositionXSmooth[ dropperCount ] > 300 )
//ตรวจสอบว่าถ้าตำแหน่งเกินที่กำหนดให้เปลี่ยนค่าเพื่อให้ตัวกระโดดหายไป แล้วเพิ่มคะแนน(เมื่อเด้งถึงรถพยาบาล)
{
dropperPositionYSmooth[ dropperCount ] = height + 100;
playerScore += 1;
}
else if ( dropperPositionYSmooth[ dropperCount ] > 400 )
//ตรวจสอบว่าถ้าตำแหน่งเกินตำแหน่งที่กำหนด ให้เปลี่ยนค่าเพื่อให้ตัวกระโดดหายไปแล้วลดคะแนน(กรณีที่รับไม่ทัน)
{
dropperPositionYSmooth[ dropperCount ] = height + 100;
playerHealthPoint -=1 ;
}
}
}
}
void DisplayDropperSmooth () //ฟังก์ชั่นใช้ในการแสดงผลตัวกระโดดตึกในเกมโหมด smooth
{
for ( int dropperCount = 0; dropperCount < dropperPositionXSmooth.length; dropperCount++ )
//วนลูปเพื่อวาดตัวกระโดดตึกทุกตัว
{
DrawPeopleDownMiddle( dropperPositionXSmooth[ dropperCount ], dropperPositionYSmooth[ dropperCount ] );
//วาดตัวกระโดดตึกโดยการตรวจสอบจากตำแหน่งในตัวแปร
}
}
//Gameplay_Step
void AddDropperStep () //ฟังก์ชั่นใช้ในการสร้างตัวกระโดดตึกในเกมโหมด step
{
addDropperTimeCount += 1; //เพิ่มเวลาให้ถึงเวลาที่ใช้ในการสร้างตัว
if ( addDropperTimeCount >= addDropperTime )
//ตรวรสอบหากถึงเวลาที่ตัวกระโดดตึกจะโดดให้สร้างตัวกระโดดตึก
{
addDropperTimeCount = 0; //รีเซทเวลาในการนับที่ใช้สร้างตัวกระโดดตึก
if ( addDropperTime > 102f )
//ตรวจสอบว่าเวลาสร้างน้อยกว่าค่ากำหนดหรือไม่ ถ้ามากกว่าให้ลดเวลาสร้างตัวกระโดดตึกให้ไวขึ้น
addDropperTime -= 25f; //ลดเวลาสร้างตัวกระโดดตึก
dropPositionStep = append( dropPositionStep, 0 ); //เพิ่มอาเรย์ 1 ช่องเพื่อเก็บตำแหน่งตัวกระโดด
dropTimeStep = append( dropTimeStep, 0 );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บเวลาตัวกระโดดใช้ตรวจสอบในการเปลี่ยน step
currentDropTimeStep = append( currentDropTimeStep, 0 );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บเวลาที่ใช้นับในการเปลี่ยน step
dropTimeStep[ dropTimeStep.length - 1 ] = dropTimeStepSpeed;
//กำหนดค่าเริ่มต้นในการกระโดดแต่ละตัว
if ( dropTimeStepSpeed > 20 )
//ตรวจสอบว่าถ้าเวลายังไม่น้อยกว่าที่กำหนด ให้เพิมความเร็วในการเปลี่ยน step ของแต่ละตัว ( ความเร็วการเปลี่ยน step เร็วขึ้นเรือยๆ )
{
dropTimeStepSpeed -= 5; //ลดค่า dropTimeStepSpeed;
}
}
}
void ChangeStep () //ฟังก์ชั่นใช้ในการเปลี่ยนตำแหน่งของตัวกระโดดตึก
{
for ( int countDropper = 0; countDropper < dropPositionStep.length; countDropper++ )
//วนลูปเพื่อเปลี่ยนตำแหน่งของตัวกระโดดตึกแบบ step
{
currentDropTimeStep[ countDropper ] += 1f; //นับเวลาเพื่อเปลี่ยน step ของแต่ละตัว
if ( currentDropTimeStep[ countDropper ] >= dropTimeStep[ countDropper ] )
//ตรวจสอบถ้าเวลาถึงเวลาที่กำหนดให้เปลี่ยน step
{
if ( dropPositionStep[ countDropper ] < 100 )
//ตรวจสอบว่าถ้าตัวละครอยู่ในตำแหน่งที่เกินกำหนด ให้ไม่มีการเช็คเปลี่ยน step
{
currentDropTimeStep[ countDropper ] = 0f;
//รีเซทเวลาปัจจุบันที่นับอยู่ให้เริ่มนับใหม่ เพื่อเปลี่ยน step
dropPositionStep[ countDropper ] += 1; //เปลี่ยนตำแหน่งของตัวกระโดดตึก
if ( dropPositionStep[ countDropper ] == 51 || dropPositionStep[ countDropper ] == 61 || dropPositionStep[ countDropper ] == 71 )
//ตรวจสอบว่าตัวกระโดดตึกถึงจุดที่กำหนดให้ลดโอกาศพลาดผู้เล่น 1 ครั้ง
{
playerHealthPoint -=1; //ลดค่า playerHealthPoint
}
else if ( dropPositionStep[ countDropper ] == 52 || dropPositionStep[ countDropper ] == 62 || dropPositionStep[ countDropper ] == 72 )
//ตรวจสอบว่าถ้าตัวกระโดดตึกอยู่จุดที่กำหนดให้ออกจากฉาก
{
dropPositionStep[ countDropper ] = 100; //เอาตัวกระโดดตึกออกจากฉาก
}
if ( dropPositionStep[ countDropper ] == 3 && hospitalManPos == 0 )
//ตรวจสอบตัวกระโดดลงจุดที่กำหนดและตัวรับอยู่ในที่เดียวกัน ให้เพิ่มคะแนน
{
playerScore += 1; //เพิ่มคะแนน
}
else if ( dropPositionStep[ countDropper ] == 11 && hospitalManPos == 1 )
//ตรวจสอบตัวกระโดดลงจุดที่กำหนดและตัวรับอยู่ในที่เดียวกัน ให้เพิ่มคะแนน
{
playerScore += 1; //เพิ่มคะแนน
}
else if ( dropPositionStep[ countDropper ] == 18 && hospitalManPos == 2 )
//ตรวจสอบตัวกระโดดลงจุดที่กำหนดและตัวรับอยู่ในที่เดียวกัน ให้เพิ่มคะแนน
{
playerScore += 1; //เพิ่มคะแนน
}
else if ( dropPositionStep[ countDropper ] == 22 )
//ตรวจสอบตัวกระโดดลงที่จุดสุดท้าย (ตรงรถพยาบาล) ให้เพิ่มคะแนนแล้วนำตัวกระโดดตึกออกจากฉาก
{
playerScore += 1; //เพิ่มคะแนน
dropPositionStep[ countDropper ] = 100; //นำตัวกระโดดตึกออกจากฉาก
}
else if ( dropPositionStep[ countDropper ] == 3 && hospitalManPos != 0 )
//ตรวจสอบถ้ารับไม่ทัน ให้เปลี่ยนตำแหน่งไปที่ที่กำหนด
{
dropPositionStep[ countDropper ] = 50; //เปลี่ยนตำแหน่งตัวละคร ( แสดงผลจุดเดิม )
}
else if ( dropPositionStep[ countDropper ] == 11 && hospitalManPos != 1 )
//ตรวจสอบถ้ารับไม่ทัน ให้เปลี่ยนตำแหน่งไปที่ที่กำหนด
{
dropPositionStep[ countDropper ] = 60; //เปลี่ยนตำแหน่งตัวละคร ( แสดงผลจุดเดิม )
}
else if ( dropPositionStep[ countDropper ] == 18 && hospitalManPos != 2 )
//ตรวจสอบถ้ารับไม่ทัน ให้เปลี่ยนตำแหน่งไปที่ที่กำหนด
{
dropPositionStep[ countDropper ] = 70; //เปลี่ยนตำแหน่งตัวละคร ( แสดงผลจุดเดิม )
}
}
}
}
}
void DisplayDropperStep () //ฟังก์ชั่นใช้ในการแสดงผลของตัวกระโดดตึกในเกมโหมด step
{
for ( int dropper = 0; dropper < dropPositionStep.length; dropper++ )
{
DropperDisplayStep( dropPositionStep[ dropper ] ); //วาดตัวกระโดดตึกจากตำแหน่งในอาเรย์
}
}
//Display
void DropperDisplayStep ( int position )
//ฟังก์ชั่นใช้ในการตรวจสอบตำแหน่งของตัวกระโดดตึกในเกมโหมด step เพื่อวาดตัวกระโดดตึกในตำแหน่งต่างๆ
{
switch( position )
{
case 0 :
DrawPeopleFly( -210, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 1 :
DrawPeopleFly( -190, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 2 :
DrawPeopleDownMiddle( -170, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 3 :
DrawPeopleDownSide( -150, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขนอ้าปาก
break;
case 4 :
DrawPeopleFly( -120, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 5 :
DrawPeopleFly( -110, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 6 :
DrawPeopleFly( -80, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 7 :
DrawPeopleFly( -40, -100 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 8 :
DrawPeopleFly( 20, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 9 :
DrawPeopleFly( 40, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 10 :
DrawPeopleDownMiddle( 60, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 11 :
DrawPeopleDownMiddle( 80, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 12 :
DrawPeopleFly( 100, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 13 :
DrawPeopleFly( 120, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 14 :
DrawPeopleFly( 140, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 15 :
DrawPeopleFly( 170, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 16 :
DrawPeopleFly( 200, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 17 :
DrawPeopleFly( 230, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 18 :
DrawPeopleDownSide( 260, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 19 :
DrawPeopleFly( 310, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 20 :
DrawPeopleDownMiddle( 350, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 21 :
DrawPeopleDownMiddle( 390, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 50 :
DrawPeopleDownSide( -150, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 60 :
DrawPeopleDownMiddle( 80, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 70 :
DrawPeopleDownSide( 260, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 51 :
DrawPeopleDownMiddle( -150, 330 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 61 :
DrawPeopleDownMiddle( 80, 330 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 71 :
DrawPeopleDownMiddle( 260, 330 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
}
}
void HospitalManDisplay ( int nowHospitalManPos )
//ฟังก์ชั่นใช้ในการแสดงผลตัวรับในเกมแบบ step โดยกำหนดเป็นตำแหน่งต่างๆ
{
switch( nowHospitalManPos )
{
case 0 :
DrawHospitalMan( -180, -10 ); //เรียกฟังก์ชั่นวาดตัวรับตามตำแหน่ง
break;
case 1 :
DrawHospitalMan( 0, -10 ); //เรียกฟังก์ชั่นวาดตัวรับตามตำแหน่ง
break;
case 2 :
DrawHospitalMan( 140, -10 ); //เรียกฟังก์ชั่นวาดตัวรับตามตำแหน่ง
break;
}
}
//Display Menu
void startFire() { //ฟังก์ชั่นในการสร้างตัวอักษรหน้าแรกของเกมส์
textSize(120);
fill(0);
text("F RE", 300, 275);
textSize(20);
fill(100);
text("Nintendo Game&Watch", 400, 300);
}
void peopleI() { //ฟังก์ชั่นในการสร้างตัวคนหลังตัว F ในส่วนหน้าแรกของเกมส์
strokeWeight(1);
stroke(0);
fill(#FA0808);
ellipse(400, 195, 10, 10);
fill(0);
ellipse(400, 225, 25, 25);
ellipse(400, 250, 25, 35);
fill(255);
stroke(255);
ellipse(421, 246, 30, 30);
ellipse(380, 246, 30, 30);
stroke(0);
fill(0);
ellipse(430, 238, 12, 8);
ellipse(427, 235, 5, 10);
ellipse(375, 238, 12, 8);
ellipse(378, 235, 5, 10);
ellipse(370, 270, 12, 8);
ellipse(435, 267, 12, 8);
ellipse(400, 215, 10, 20);
fill(255);
stroke(255);
ellipse(400, 227, 13, 10);
ellipse(405, 225, 10, 12);
ellipse(395, 225, 10, 12);
stroke(0);
strokeWeight(5);
line(400, 245, 425, 238);
line(400, 245, 375, 238);
line(408, 260, 425, 255);
line(408, 260, 375, 255);
line(377, 255, 374, 268);
line(423, 255, 432, 268);
}
void topBuilt() { //ฟังก์ชั่นในการสร้างเครื่องหมายกากบาทบนยอดตึกในส่วนหน้าแรกของเกมส์
noStroke();
fill(#FA2605);
rect(267, 160, 20, 50);
rect(252, 175, 50, 20);
}
void build() { //ฟังก์ชั่นในการวาดตึกด้านหน้าตัว F ในส่วนหน้าแรกของเกมส์
strokeWeight(5);
stroke(0);
fill(0);
rect(220, 192, 50, 80);
fill(255);
rect(223, 195, 13, 13);
rect(238, 195, 13, 13);
rect(253, 195, 13, 13);
rect(223, 210, 13, 13);
rect(238, 210, 13, 13);
rect(253, 210, 13, 13);
rect(223, 225, 13, 13);
rect(238, 225, 13, 13);
rect(253, 225, 13, 13);
}
//Display Objects
void DrawBackground() { //ฟังก์ชั่นในการวาด backgroung ทั้งหมดของเกมส์
//floor
int count=0;
int n=4;
int x=0;
int y=0;
stroke(198, 108, 0);
strokeWeight(7);
line(0, 455, 800, 455);
line(0, 520, 800, 520);
line(0, 520, 120, 455);
while (count < n) {
//กำหนดเงื่อนไขการทำงาน loop While โดยจะทำงานก็ต่อเมื่อ count ยังมีค่าน้อยกว่า n
line(80+x, 520, 170+y, 455);
//วาดเส้นตรงโดยมีการเเปลี่ยนแปลงมีการกำหนดค่า x และ y เพิ่มเข้าไป ทำให้มีการวาดซ้ำคนละตำแหน่ง
count=count+1; //เพิ่มค่า count เพื่อไปเช็กกับเงื่อนไข while
x=x+170; //เพิ่มค่าของ x ทีละ 170
y=y+140; //เพิ่มค่าของ y ทีละ 140
}
strokeWeight(5);
line(0, 475, 800, 475);
int a=0;
int b=0;
int c=12;
strokeWeight(5);
while (a<c) {
line(170+b, 550, 195+b, 550);
a=a+1;
b=b+30;
}
//fire
noStroke();
fill(#E84509);
ellipse(110, 80, 60, 25);
ellipse(170, 88, 45, 15);
triangle(120, 90, 148, 60, 165, 90);
fill(255);
ellipse(138, 97, 45, 15);
ellipse(170, 65, 40, 35);
ellipse(125, 60, 40, 35);
fill(#E84509);
ellipse(185, 75, 35, 35);
ellipse(165, 65, 20, 20);
fill(255);
triangle(210, 50, 190, 80, 185, 50);
ellipse(194, 70, 10, 10);
ellipse(175, 60, 20, 20);
ellipse(170, 73, 20, 20);
fill(#E84509);
triangle(160, 58, 165, 48, 168, 65);
triangle(156, 80, 160, 65, 163, 65);
triangle(110, 85, 125, 65, 130, 85);
triangle(110, 45, 135, 30, 110, 70);
triangle(110, 35, 125, 28, 110, 45);
triangle(155, 30, 158, 45, 170, 30);
triangle(155, 30, 180, 15, 170, 30);
fill(255);
ellipse(155, 20, 25, 20);
ellipse(168, 40, 15, 15);
fill(#E84509);
ellipse(145, 20, 10, 10);
triangle(140, 20, 155, 10, 150, 20);
triangle(145, 20, 138, 35, 150, 20);
fill(255);
ellipse(150, 22, 7, 7);
//grass
fill(#00BC33);
int i=0;
int z=0;
int r=6;
while (i<r) { //กำหนดการทำงาน While loop โดยจะสร้างสามเหลี่ยมี้ในตำแหน่งที่แตกต่างกัน
triangle(170+z, 545, 185+z, 535, 190+z, 540);
triangle(175+z, 530, 185+z, 540, 195+z, 540);
triangle(175+z, 550, 185+z, 540, 195+z, 540);
triangle(190+z, 525, 190+z, 540, 200+z, 540);
triangle(190+z, 550, 190+z, 540, 200+z, 540);
triangle(200+z, 525, 195+z, 540, 210+z, 540);
triangle(215+z, 547, 195+z, 540, 210+z, 540);
triangle(225+z, 545, 200+z, 535, 210+z, 535);
triangle(235+z, 540, 210+z, 530, 210+z, 535);
triangle(225+z, 525, 200+z, 535, 210+z, 535);
i=i+1;
z=z+60;
}
}
void DrawBuilding() { //ฟังก์ชั่นในการวาดตึกที่เกิดไฟไหม้
pushMatrix();
scale( 2 );
stroke(0);
strokeCap(0);
strokeWeight(5);
fill(#BC7C13);
rect(-10, -10, 45, 243);
strokeWeight(8);
line(-3, 235, 50, 235);
strokeWeight(2);
fill(#49D7E8);
rect(-3, -3, 15, 20);
rect(-3, 48, 15, 20);
rect(-3, 98, 15, 20);
rect(-3, 148, 15, 20);
stroke(255);
line(11, 0, -3, 20);
line(11, 50, -3, 70);
line(11, 100, -3, 120);
line(11, 150, -3, 170);
stroke(0);
fill(#BC7C13);
rect(-10, 175, 65, 15);
rect(-10, 125, 65, 15);
rect(-10, 75, 65, 15);
rect(-10, 25, 65, 15);
line(-5, 165, 55, 165);
line(-5, 115, 55, 115);
line(-5, 65, 55, 65);
line(-5, 15, 55, 15);
line(55, 15, 55, 25);
line(55, 65, 55, 75);
line(55, 115, 55, 125);
line(55, 165, 55, 175);
line(45, 15, 45, 25);
line(45, 65, 45, 75);
line(45, 115, 45, 125);
line(45, 165, 45, 175);
line(25, 15, 25, 25);
line(25, 65, 25, 75);
line(25, 115, 25, 125);
line(25, 165, 25, 175);
line(5, 15, 5, 25);
line(5, 65, 5, 75);
line(5, 115, 5, 125);
line(5, 165, 5, 175);
popMatrix();
}
void DrawAmbulance( float posX, float posY ) { //ฟังก์ชั่นในการวาดรถพยาบาล
pushMatrix();
translate( posX, posY );
stroke(0);
strokeWeight(3);
fill(255);
rect(580, 330, 170, 130, 30, 55, 5, 5);
rect(570, 440, 30, 20, 5, 90, 5, 5);
rect(730, 440, 30, 20, 90, 30, 5, 5);
rect(580, 410, 15, 20, 0, 10, 10, 0);
rect(580, 350, 20, 40, 3, 10, 10, 0);
ellipse(615, 450, 40, 40);
ellipse(715, 450, 40, 40);
rect(740, 398, 10, 15, 5, 0, 0, 5);
rect(730, 398, 10, 15, 5, 5, 5, 5);
fill(255);
rect(700, 350, 48, 40, 5, 60, 5, 5);
fill(#63E5F0);
rect(620, 350, 60, 40, 5, 5, 5, 5);
stroke(255);
rect(723, 360, 20, 25, 0, 20, 0, 0);
line(723, 367, 745, 367);
fill(255);
triangle(623, 353, 645, 353, 623, 380);
strokeWeight(7);
line(645, 385, 670, 353);
strokeWeight(4);
line(623, 386, 675, 386);
line(623, 353, 675, 353);
line(675, 353, 675, 386);
stroke(0);
fill(0);
ellipse(615, 458, 33, 33);
ellipse(715, 458, 33, 33);
fill(255);
ellipse(615, 458, 20, 20);
ellipse(715, 458, 20, 20);
strokeWeight(5);
line(580, 400, 645, 400);
line(680, 400, 715, 400);
strokeWeight(1);
stroke(255, 0, 0);
fill(255, 0, 0);
rect(685, 303, 15, 25, 10, 10, 0, 0);
fill(255);
rect(695, 305, 5, 23, 0, 10, 0, 0);
strokeWeight(3);
stroke(0);
fill(255);
rect(685, 320, 15, 8);
stroke(255, 0, 0);
line(710, 315, 730, 315);
line(655, 315, 675, 315);
noStroke();
fill(255, 0, 0);
rect(655, 400, 20, 40);
rect(645, 410, 40, 20);
triangle(710, 305, 725, 300, 730, 305);
triangle(705, 300, 715, 290, 725, 290);
triangle(710-35, 305, 725-65, 300, 730-75, 305);
triangle(705-20, 300, 715-50, 290, 725-50, 290);
popMatrix();
}
void DrawHospitalMan( float posX, float posY ) { //ฟังก์ชั่นสำหรับสร้างตัวรับที่ผู้ใช้ใช้ในการเลื่อนรับตัวที่ตกจากตึก
pushMatrix();
translate( posX, posY );
stroke(0);
strokeWeight(2);
//body l
fill(0);
rect(338, 435, 10, 10);
ellipse(318, 447, 17, 20);
ellipse(335, 435, 27, 20);
ellipse(348, 447, 18, 10);
fill(255);
stroke(255);
ellipse(332, 450, 20, 17);
ellipse(323, 430, 17, 17);
ellipse(348, 430, 17, 17);
triangle(300, 450, 310, 437, 315, 453);
ellipse(320, 438, 4, 5);
ellipse(323, 450, 4, 4);
ellipse(337, 445, 10, 10);
ellipse(348, 439, 3, 3);
//body r
fill(0);
stroke(0);
rect(438, 435, 10, 10);
ellipse(418, 447, 17, 20);
ellipse(435, 435, 27, 20);
ellipse(448, 447, 18, 10);
fill(255);
stroke(255);
ellipse(432, 450, 20, 17);
ellipse(423, 430, 17, 17);
ellipse(448, 430, 17, 17);
triangle(400, 450, 410, 437, 415, 453);
ellipse(420, 438, 4, 5);
ellipse(423, 450, 4, 4);
ellipse(437, 445, 10, 10);
ellipse(448, 439, 3, 3);
//head
fill(0);
stroke(0);
ellipse(335, 422, 10, 10);
ellipse(435, 422, 10, 10);
fill(255);
stroke(255);
ellipse(343, 417, 10, 10);
ellipse(427, 417, 10, 10);
ellipse(443, 417, 10, 10);
fill(0);
stroke(0);
ellipse(330, 405, 25, 25);
ellipse(435, 405, 25, 25);
ellipse(336, 395, 8, 13);
ellipse(323, 400, 20, 20);
triangle(315, 400, 329, 385, 329, 400);
triangle(318, 400, 327, 422, 327, 400);
fill(255);
stroke(255);
ellipse(335, 408, 10, 8);
ellipse(346, 408, 10, 10);
ellipse(330, 398, 4, 4);
ellipse(320, 395, 5, 5);
fill(0);
stroke(0);
ellipse(440, 398, 20, 20);
ellipse(428, 392, 8, 12);
triangle(437, 382, 430, 400, 445, 400);
triangle(430, 400, 443, 420, 448, 400);
fill(255);
stroke(255);
ellipse(430, 408, 15, 9);
ellipse(420, 408, 12, 12);
ellipse(435, 397, 5, 5);
ellipse(443, 392, 6, 6);
//arm
fill(0);
stroke(0);
triangle(333, 423, 360, 423, 360, 430);
triangle(438, 423, 410, 423, 410, 430);
ellipse(360, 425, 13, 10);
ellipse(410, 425, 13, 10);
ellipse(357, 423, 5, 10);
ellipse(413, 423, 5, 10);
strokeWeight(5);
line(360, 425, 410, 425);
popMatrix();
}
void DrawPeopleFly(float x, float y) { //ฟังก์ชั่นที่ใช้สำหรับสร้างตัวที่กระโดดลงมาจากตึก
pushMatrix();
scale( 0.8f );
strokeWeight(1);
stroke(0);
fill(0);
ellipse(400+x, 225+y, 25, 25);
ellipse(400+x, 250+y, 25, 35);
fill(255);
stroke(255);
ellipse(421+x, 246+y, 30, 30);
ellipse(380+x, 246+y, 30, 30);
stroke(0);
fill(0);
ellipse(430+x, 238+y, 12, 8);
ellipse(427+x, 235+y, 5, 10);
ellipse(375+x, 238+y, 12, 8);
ellipse(378+x, 235+y, 5, 10);
ellipse(370+x, 270+y, 12, 8);
ellipse(435+x, 267+y, 12, 8);
ellipse(409+x, 217+y, 13, 10);
fill(255);
stroke(255);
ellipse(405+x, 227+y, 12, 8);
ellipse(415+x, 225+y, 10, 10);
fill(0);
stroke(0);
strokeWeight(5);
line(400+x, 245+y, 425+x, 238+y);
line(400+x, 245+y, 375+x, 238+y);
line(408+x, 260+y, 425+x, 255+y);
line(408+x, 260+y, 375+x, 255+y);
line(377+x, 255+y, 374+x, 268+y);
line(423+x, 255+y, 432+x, 268+y);
popMatrix();
}
void DrawPeopleDownSide(float x, float y) { //ฟังก์ชั่นสำหรับสร้างตัวที่ตกลงมาจากตึกในหน้าตรงกางแขนกางขา
pushMatrix();
scale( 0.8f );
strokeWeight(1);
stroke(0);
fill(0);
ellipse(400+x, 225+y, 25, 25);
ellipse(400+x, 250+y, 25, 35);
fill(255);
stroke(255);
ellipse(421+x, 246+y, 30, 30);
ellipse(380+x, 246+y, 30, 30);
stroke(0);
fill(0);
ellipse(430+x, 238+y, 12, 8);
ellipse(427+x, 235+y, 5, 10);
ellipse(375+x, 238+y, 12, 8);
ellipse(378+x, 235+y, 5, 10);
ellipse(370+x, 270+y, 12, 8);
ellipse(435+x, 267+y, 12, 8);
ellipse(400+x, 215+y, 10, 20);
fill(255);
stroke(255);
ellipse(400+x, 227+y, 13, 10);
ellipse(405+x, 225+y, 10, 12);
ellipse(395+x, 225+y, 10, 12);
stroke(0);
strokeWeight(5);
line(400+x, 245+y, 425+x, 238+y);
line(400+x, 245+y, 375+x, 238+y);
line(408+x, 260+y, 425+x, 255+y);
line(408+x, 260+y, 375+x, 255+y);
line(377+x, 255+y, 374+x, 268+y);
line(423+x, 255+y, 432+x, 268+y);
popMatrix();
}
void DrawPeopleDownMiddle(float x, float y) { //ฟังก์ชั่นสำหรับสร้างตัวที่ตกลงมาจากตึกในท่านั่ง
pushMatrix();
scale( 0.8f );
strokeWeight(1);
stroke(0);
fill(0);
ellipse(402+x, 245+y, 50, 50);
stroke(255);
fill(255);
ellipse(417+x, 238+y, 50, 50);
ellipse(407+x, 225+y, 50, 50);
stroke(0);
fill(0);
ellipse(382+x, 235+y, 25, 25);
ellipse(422+x, 235+y, 8, 12);
ellipse(430+x, 260+y, 8, 12);
ellipse(367+x, 265+y, 12, 8);
fill(255);
stroke(255);
ellipse(385+x, 236+y, 13, 10);
ellipse(392+x, 232+y, 10, 10);
stroke(0);
fill(0);
ellipse(389+x, 227+y, 8, 12);
strokeWeight(5);
line(402+x, 265+y, 415+x, 255+y);
line(412+x, 255+y, 429+x, 260+y);
line(397+x, 265+y, 407+x, 240+y);
line(407+x, 242+y, 427+x, 235+y);
line(380+x, 250+y, 367+x, 253+y);
line(369+x, 253+y, 370+x, 265+y);
fill(255);
strokeWeight(1);
stroke(255);
ellipse(417+x, 266+y, 15, 15);
ellipse(407+x, 270+y, 8, 8);
triangle(409+x, 263+y, 397+x, 273+y, 427+x, 270+y);
popMatrix();
}
void smoke() { //ฟังก์ชั่นสำหรับวาดควันไฟ
smokeTime++;
if ( smokeTime == 30 ){
smokeTime = 0;
smokeStep++;
if ( smokeStep == 3 ){
smokeStep = 0;
}
}
if ( smokeStep == 2 ){
strokeWeight(1);
stroke(0);
fill(0);
ellipse(275, 15, 30, 30);
ellipse(290, 20, 25, 25);
ellipse(300, 35, 25, 25);
ellipse(305, 55, 35, 25);
ellipse(300, 70, 25, 15);
stroke(255);
fill(255);
ellipse(273, 18, 25, 25);
ellipse(287, 23, 22, 22);
ellipse(295, 37, 20, 22);
ellipse(297, 57, 32, 22);
ellipse(295, 70, 18, 10);
ellipse(273, 27, 10, 10);
}
else if ( smokeStep == 1 ){
//smokeII
strokeWeight(1);
stroke(0);
fill(0);
ellipse(185, 15, 30, 30);
ellipse(205, 25, 27, 27);
ellipse(220, 23, 29, 29);
ellipse(240, 27, 25, 25);
ellipse(248, 32, 25, 25);
ellipse(252, 40, 30, 20);
ellipse(257, 55, 30, 30);
ellipse(252, 70, 20, 10);
ellipse(245, 75, 20, 10);
stroke(255);
fill(255);
ellipse(183, 19, 26, 26);
ellipse(202, 28, 24, 24);
ellipse(218, 26, 26, 26);
ellipse(238, 30, 22, 22);
ellipse(245, 35, 22, 22);
ellipse(248, 40, 25, 15);
ellipse(250, 55, 30, 22);
ellipse(248, 70, 17, 7);
ellipse(240, 73, 18, 8);
ellipse(215, 45, 55, 40);
}
else if ( smokeStep == 0 ){
//smokeI
strokeWeight(1);
stroke(0);
fill(0);
ellipse(190, 30, 20, 20);
ellipse(200, 35, 20, 20);
ellipse(217, 35, 20, 20);
ellipse(230, 45, 23, 23);
ellipse(220, 63, 25, 25);
ellipse(205, 70, 25, 25);
stroke(255);
fill(255);
ellipse(187, 33, 17, 17);
ellipse(197, 38, 17, 17);
ellipse(215, 40, 17, 17);
ellipse(225, 46, 20, 18);
ellipse(215, 63, 22, 18);
ellipse(200, 70, 25, 25);
ellipse(210, 50, 20, 20);
}
}
void Health(int x) { //ฟังก์ชั่นสำหรับวาดชีวิตคนในส่วนใต้ score
strokeWeight(1);
stroke(0);
fill(0);
ellipse(680+x, 80, 10, 10);
ellipse(680+x, 90, 13, 15);
fill(255);
stroke(255);
ellipse(670+x, 90, 13, 15);
ellipse(690+x, 90, 13, 15);
stroke(0);
fill(0);
ellipse(660+x, 82, 5, 3);
ellipse(662+x, 80, 1, 4);
ellipse(698+x, 82, 5, 3);
ellipse(696+x, 80, 1, 4);
ellipse(658+x, 102, 5, 3);
ellipse(703+x, 102, 5, 3);
ellipse(680+x, 75, 5, 8);
fill(255);
stroke(255);
ellipse(680+x, 81, 5, 3);
ellipse(678+x, 80, 3, 5);
ellipse(682+x, 80, 3, 5);
stroke(0);
strokeWeight(2);
line(680+x, 85, 660+x, 82);
line(680+x, 85, 695+x, 82);
line(680+x, 95, 665+x, 90);
line(680+x, 95, 692+x, 90);
line(665+x, 90, 660+x, 102);
line(692+x, 90, 700+x, 102);
}
เพื่อให้ในเวลาใช้ในฟังก์ชั่นนั้นใช้ได้สะดวกกว่า
boolean gameSmooth = true;
//ประกาศตัวแปร gameSmooth เพื่อบอกให้เกมทำงานแบบ smooth หรือ step ถ้า gameSmooth เป็น true ให้เกมทำงานแบบ smooth ถ้าเป็น false ให้เกมทำงานแบบ step
int playerHealthPoint = 3;
//ประกาศตัวแปร playerHealtPoint เพื่อบอกว่าผู้เล่นสามารถพลาดในการรับผู้ที่ตกลงมาจากตึกเป็นจำนวนเท่าใด
int playerScore = 0;
//ประกาศตัวแปร playerScore เพื่อบันทึกค่าคะแนนที่ผู้เล่นสามารถทำได้
int nowGamePage = 0;
//ประกาศตัวแปร nowGamePage เพื่อบอกให้เกมทำงานเป็นหน้าๆ โดยเมื่อ nowGamePage เท่ากับ 0 จะแสดงหน้าเมนู หากเท่ากับ 1 จะแสดงหน้าเล่นเกม
int hospitalManPos = 0;
//ประกาศตัวแปร hospitalManPos ใช้ในการทำเกมแบบ step เพื่อบอกว่า ตัวรับหรือผู้เล่นนั้นอยู่ในตำแหน่งใด
float addDropperTime = 500;
//ประกาศตัวแปร addDropperTime เพื่อกำหนดเวลาว่าเวลาใดจะให้คนโดดตึกลงมา
float addDropperTimeCount = 600f;
//ประกาศตัวแปร addDropperTimeCount เพื่อนับเวลาไปเทียบกับ addDropperTime ที่ใช้ในการสร้างตัวกระโดดตึก
int[] dropPositionStep = new int[ 0 ];
//ประกาศตัวแปร dropPositionStep เพื่อเก็บตำแหน่งของผู้ที่กระโดดตึกลงมา
float[] dropTimeStep = new float[ 0 ];
//ประกาศตัวแปร dropTimeStep เพื่อเก็บเวลาในการเปลี่ยน frame ของตัวที่กระโดดตึกลงมา
float[] currentDropTimeStep = new float[ 0 ];
//ประกาศตัวแปร currentDropTimeStep เพื่อนับเวลาไปเทียบกับ dropTimeStep ในการเปลี่ยน frame
float dropTimeStepSpeed = 50;
//ประกาศตัวแปร dropTimeStepSpeed เพื่อใช้กำหนดความเร็วเมื่อผู้เล่นเริ่มกระโดดตึกโดยจะลดลงเรื่อยๆภายในการเล่น
float hotspitalManPosSmooth = -180f;
//ประกาศตัวแปร hospitalManPosSmooth เพื่อเก็บตำแหน่งของผู้รับหรือตัวเล่นนั้นอยู่ในตำแหน่งใด
float[] dropperPositionXSmooth = new float[ 0 ];
//ประกาศตัวแปร dropperPositionXSmooth เพื่อเก็บค่าตำแหน่งตัวที่กระโดดในแกน X ในการเล่นแบบ smooth
float[] dropperPositionYSmooth = new float[ 0 ];
//ประกาศตัวแปร dropperPositionYSmooth เพื่อเก็บค่าตำแหน่งตัวที่กระโดดในแกน Y ในการเล่นแบบ smooth
float[] dropperSmoothSpeed = new float[ 0 ];
//ประกาศตัวแปร dropperSmoothSpeed เพิ่อกำหนดความเร็วตัวที่ตกลงมาจากตึกในการเล่นแบบ smooth
int startPlayerHealthPoint;
//ประกาศตัวแปรเพื่อเก็บค่าเริ่มต้นของ playerHealthPoint ไว้เพื่อใช้ในการ restart game
boolean gameIsStart = true;
//ประกาศตัวแปร gameIsStart เพื่อกำหนดว่าเกมเริ่มขึ้นหรือยัง
boolean isOverButtonStep = false;
//ประกาศตัวแปร isOverButtonStep เพื่อเก็บค่าไว้บอกเกี่ยวกับปุ่มการเล่นเกมแบบ step ในหน้าเมนู
boolean isOverButtonSmooth = false;
//ประกาศตัวแปร isOverButtonSmooth เพื่อเก็บค่าไว้บอกเกี่ยวกับปุ่มการเล่นเกมแบบ smooth ในหน้าเมนู
int smokeTime = 0;
//ประกาศตัวแปร smokeTime เพื่อกำหนดเวลาว่าเวลาใดจะให้เปลี่ยน frame ของควันไฟ
int smokeStep = 0;
//ประกาศตัวแปร smokeStep เพื่อใช้กำหนดตำแหน่งของควันไฟในแต่ละ step
int lightAmbulanceTimeCount = 0;
//ประกาศตัวแปร lightAmbulanceTimeCount เพื่อใช้นับเวลาของไฟกระพริบบริเวณรถพยาบาล
int lightAmbulanceStep = 0;
//ประกาศตัวแปร lightAmbulanceStep เพื่อใช้กำหนดเวลาให้ไฟกระพริบนานเท่าไหร่ โดยค่ายิ่งมาก ไฟก็ยิ่งกระพริบช้า
void setup ()
//เป็นฟังก์ชั่นเพื่อกำหนดค่าต่างๆของเกม
{
size( 800, 550 ); //กำหนดขนาดหน้าจอของเกมส์
startPlayerHealthPoint = playerHealthPoint; //เก็บจำนวนที่ผู้เล่นสามารถพลาดใส่ตัวแปร startPlayerHealthPoint เพื่อใช้ในการเริ่มเกมส์ใหม่
}
ฟังก์ชั่นมีจำนวนฟังก์ชั่นทั้งหมด 30ฟังก์ชั่น ซึ่งแต่ละฟังก์ชั่นก็มีชื่อที่บ่งบอกถึงการทำงานของฟังก์ชั่นนั้นได้ชัดเจนแต่ชื่อฟังก์ชั่นบางตัวอาจจะยาวเกินไปบางทีอาจสามารถแก้ไขชื่อฟังก์ชั่นบางตัวโดยการย่อชื่อฟังก์ชั่นได้ และชื่อฟังก์ชั่นบางตัวเมื่อได้อ่่านแล้วทำให้ไม่เข้าใจในความหมายของฟังก์ชั่นนั้นๆว่าใช้ทำอะไร อย่างเช่น droppositionstep(); ที่ไม่เข้าใจความหมายองฟังก์ชั่นนี้ว่าต้องการให้ทำไรอะไร
void draw () //เป็นฟังก์ชั่นที่ถูกเรียกใช้ในการ update สิ่งต่างๆที่เกิดขึ้นในทุกๆ frame
{
background( 255 ); //กำหนดสีของพิ้นหลัง
if ( nowGamePage == 0 )
//ตรวจสอบว่า nowGamePage มีค่าเท่าใด หากเป็น 0 เรียกฟังก์ชัน StartPage ส่วนหากเท่ากับ 1 ให้เรียกฟังก์ชัน GamePage
{
StartPage(); //เรียกฟังก์ขั่นเพื่อแสดงผลหน้าเมนู
}
else if ( nowGamePage == 1 )
{
GamePage(); //เรียกฟังก์ชั่นเพื่อแสดงผลหน้าเกม
}
}
void keyPressed () //เป็นฟังก์ชั่นที่ถูกเรียกใช้เมื่อกดปุ่ม
{
if ( !gameSmooth ) //ตรวจสอบว่าเกมเป็นประเภทใด smooth หรือ step
{
if ( keyCode == LEFT )
//ตรวจสอบว่าเมื่อกดปุ่มลูกศรซ้าย ให้ทำการเคลื่อนที่ตัวรับไปทางซ้าย 1 ตำแหน่ง โดยมีผลกับเกมแบบ step และตรวจสอบว่าไม่ได้อยู่ในตำแหน่งแรก
{
if ( hospitalManPos > 0 ) hospitalManPos--;
}
else if ( keyCode == RIGHT )
//ตรวจสอบว่าเมื่อกดปุ่มลูกศรขวา ให้ทำการเคลื่อนที่ตัวรับไปทางขวา 1 ตำแหน่ง โดยมีผลกับเกมแบบ step และไม่สามารถเคลื่อนเกินตำแหน่งสุดท้ายได้ ด้วยการกำหนดให้ตำแหน่งสุดท้ายคือตำแหน่งที่สาม
{
if ( hospitalManPos < 2 ) hospitalManPos++;
}
}
else
{
if ( keyCode == RIGHT )
//ตรวจสอบกว่าเมื่อกดปุ่มลูกศรขวา ให้ทำการเคลื่อนที่ ตัวรับไปทางขวา 10 หน่วย โดยมีผลกับเกมแบบ smooth และไม่สามารถเคลื่อนที่ได้เกินตำแหน่งที่กำหนด
{
if ( hotspitalManPosSmooth < 150 ) hotspitalManPosSmooth += 10f;
}
else if ( keyCode == LEFT )
//ตรวจสอบกว่าเมื่อกดปุ่มลูกศรซ้าย ให้ทำการเคลื่อนที่ ตัวรับไปทางซ้าย 10 หน่วย โดยมีผลกับเกมแบบ smooth และไม่สามารถเคลื่อนที่ได้เกินตำแหน่งที่กำหนด
{
if ( hotspitalManPosSmooth > -180f ) hotspitalManPosSmooth -= 10f;
}
}
}
void mousePressed () //เป็นฟังก์ชั่นที่เรียกใช้เมื่อทำการคลิกเมาส์
{
if ( isOverButtonStep )
//ตรวจสอบว่า isOverButtonStep เป็นจริงหรือไม่ หากเป็นจริงให้ทำการเปลี่ยนหน้าไปที่หน้าเกม และเลือกเกมเป็นแบบ step
{
gameSmooth = false; //แก้ไขค่า gameSmooth เป็น false
nowGamePage = 1; //แก้ไขค่า nowGamePage เป็น 1
}
if ( isOverButtonSmooth )
//ตวรจสอบว่า isOverButtonSmooth เป็นจริงหรือไม่ หากเป็นจริงให้ทำการเปลี่ยนหน้าไปที่หน้าเกม และเลือกเกมเป็นแบบ smooth
{
gameSmooth = true; //แก้ไขค่า gameSmooth เป็น true
nowGamePage = 1; //แก้ไขค่า nowGamePage เป็น 1
}
if ( !gameIsStart && nowGamePage == 1 )
//ตรวจสอบว่าเกมนั้นเริ่มไปแล้วหรือไม่ หากเกมจบ gameIsStart จะเป็น false และเกมยังอยู่ในหน้าเกม ให้เปลี่ยนไปที่หน้าแรกแล้วทำการเรียกฟังก์ชั่นเพื่อ เริ่มเกมส์ใหม่
{
nowGamePage = 0; //แก้ไขค่า nowGamePage เป็น 0
RestartGame(); //เรียกฟังก์ชั่นเพื่อเริ่มเกมส์ใหม่
}
}
void RestartGame () //ฟังก์ชั่นที่ใช้ในการเริ่มเกมส์ใหม่โดยการเปลี่ยนค่ากลับไปเป็นค่าเริ่มต้นทั้งหมด
{
isOverButtonStep = false; //เปลี่ยน isOverButtonStep เป็น false
isOverButtonSmooth = false; //เปลี่ยน isOverButtonStep เป็น false
playerScore = 0; //เปลี่ยน playerScore หรือ คะแนนของผู้เล่นเป็น 0
playerHealthPoint = startPlayerHealthPoint; //เปลี่ยนค่า playerHealthPoint เป็นค่าเริ่มต้นที่เก็บไว้ใน startPlayerHealthPoint
hospitalManPos = 0; //เปลี่ยนค่า hospitalManPos เป็นค่าเริ่มต้น
addDropperTime = 600f; //เปลี่ยนค่า addDropperTime เป็นค่าเริ่มต้น
addDropperTimeCount = 600f; //เปลี่ยนค่า addDropperTimeCount เป็นค่าเริ่มต้น
dropPositionStep = new int[ 0 ]; //เปลี่ยนค่า dropPositionStep เป็นค่าเริ่มต้น
dropTimeStep = new float[ 0 ]; //เปลี่ยนค่า dropTimeStep เป็นค่าเริ่มต้น
currentDropTimeStep = new float[ 0 ]; //เปลี่ยนค่า currentDropTimeStep เป็นค่าเริ่มต้น
dropTimeStepSpeed = 50; //เปลี่ยนค่า dropTimeStepSpeed เป็นค่าเริ่มต้น
hotspitalManPosSmooth = -180f; //เปลี่ยนค่า hotspitalManPosSmooth เป็นค่าเริ่มต้น
dropperPositionXSmooth = new float[ 0 ]; //เปลี่ยนค่า dropperPositionXSmooth เป็นค่าเริ่มต้น
dropperPositionYSmooth = new float[ 0 ]; //เปลี่ยนค่า dropperPositionYSmooth เป็นค่าเริ่มต้น
dropperSmoothSpeed = new float[ 0 ]; //เปลี่ยนค่า dropperSmoothSpeed เป็นค่าเริ่มต้น
gameIsStart = true; //เปลี่ยนค่า gameIsStart เป็นค่าเริ่มต้น
}
//Game logic
void StartPage () //ฟังก์ชั่นใช้ในการทำงานของหน้าเมนู
{
pushMatrix(); //เริ่มต้น matrix
translate( -100, -90 ); //ย้ายตำแหน่ง matrix ไปที่ -100, -90
scale( 1.2f ); //เปลี่ยนขนาดของ matrix
startFire();
peopleI();
topBuilt();
build();
popMatrix(); //จบการเปลี่ยนค่า matrix
isOverButtonSmooth = CheckOverButton( 140, 350, 190, 80 );
//กำหนดค่า isOverButtonSmooth ด้วยการเรียกฟังก์ชั่น CheckOverButton
if ( isOverButtonSmooth ) StartGameButton( 140, 350, 190, 80, 0, 255, 0 );
//ตรวจสอบว่า isOverButtonSmooth เป็นจริงหรือไม่ ให้เรียกฟังก์ชั่น StartGameButton เพื่อวาดปุ่ม
else StartGameButton( 140, 350, 190, 80, 255, 0, 0 );
textSize(50); //กำหนดขนาดตัวอักษร
fill(0); //ใส่สีให้ตัวอักษร
textAlign(LEFT); //เปลี่ยนให้ตัวหนังสือชิดซ้าย
text("Smooth", 145, 410); //แสดง Text ในปุ่ม
isOverButtonStep = CheckOverButton( 480, 350, 190, 80 );
//กำหนดค่า isOverButtonStep ด้วยการเรียกฟังก์ชั่น CheckOverButton
if ( isOverButtonStep ) StartGameButton( 480, 350, 190, 80, 0, 255, 0 );
//ตรวจสอบว่า isOverButtonStep เป็นจริงหรือไม่ ให้เรียกฟังก์ชั่น StartGameButton เพื่อวาดปุ่ม
else StartGameButton( 480, 350, 190, 80, 255, 0, 0 );
textSize(50);
fill(0);
textAlign(LEFT);
text("Step", 525, 410);
}
void GamePage () //ฟังก์ชั่นใช้ในการทำงานของ gameplay
{
DrawBackground(); //เรียกฟังก์ชั่นใช้ในการวาดพื้นหลัง
DrawBuilding(); //เรียกฟังก์ชั่นใช้ในการวาดตึก
DrawAmbulance( 20, 0 ); //เรียกฟังก์ชั่นใช้ในการวาดรถพยาบาล
smoke(); //เรียกฟังก์ชั่นใช้ในการวาดควัน
if ( playerHealthPoint >= 3 ){
Health( -50 );
Health( 0 );
Health( 50 );
}
else if ( playerHealthPoint >= 2 ){
Health( -50 );
Health( 0 );
}
else if ( playerHealthPoint >= 1 ){
Health( -50 );
}
textSize( 20 );
fill( 0 );
text( "Score : " + playerScore, 610, 60 );
//Smooth
if ( gameSmooth ) //ตรวจสอบว่าเกมเป็น mode ใด smooth หรือ step
{
if ( gameIsStart ) //ตรวจสอบว่าเกมนั้นเริ่มแล้วหรือไม่
{
DrawHospitalMan( hotspitalManPosSmooth, -10 );
//เรียกฟังก์ชั่นเพื่อวาดตัวผู้เล่นหรือคนรับคนโดนตึก
DropperSmoothMove(); //เรียกฟังก์ชั่น DropperSmoothMove ที่ใช้ในการวาดตัวโดดตึกให้เคลื่อนที่
AddDropperSmooth(); //เรียกฟังก์ชั่น AddDropperSmooth ที่ใช้ในการเพิ่มตัวประโดดตึก
DisplayDropperSmooth(); //เรียกฟังก์ชั่น DisplaayDropperSmooth ที่ใช้วาดคนโดดตึก
}
}
// Step
else
{
if ( gameIsStart ) //ตรวจสอบว่าเกมนั้นเริ่มแล้วหรือไม่
{
ChangeStep(); //เรียกฟังก์ชั่น ChangeStep โดยเมื่อถึงเวลาจะเปลี่ยนตำแหน่งของตัวกระโดดตึก
AddDropperStep(); //เรียกฟังก์ชัน AddDropperStep ใช้ในการเพิ่มตัวกระโดดตึก
DisplayDropperStep(); //เรียกฟังก์ชั่น DisplayDropperStep ใช้ในการวาดตัวกระโดดตึก
HospitalManDisplay( hospitalManPos );
//เรียกฟังก์ชั่นเพื่อวาดตัวผู้เล่นหรือคนรับคนโดนตึกในตำแหน่งต่างๆ
}
}
if ( playerHealthPoint <= 0 )
//ตรวจสอบว่าหาก playerHealthPoint เท่ากับ 0 ให้ขึ้นคำว่า Gameover
{
gameIsStart = false; // เปลี่ยนค่า gameIsStart เป็น false
textSize( 50 );
fill( 255, 0, 0 ); //กำหนดตัวหนังสือให้เป็นสีแดง
textAlign(CENTER); //กำหนดการจัดวางของตัวหนังสือให้อยู่ตรงกลาง
text( "Gameover", width / 2, height / 2 ); //แสดง text คำว่า Gameover กลางหน้าจอ
}
}
//Menu
void StartGameButton ( int x, int y, int w, int h, int colorRed, int colorGreen, int colorBlue )
//ฟังก์ชั่นใช้ในการวาดปุ่มโดยการรับค่าตำแหน่งและสี
{
noStroke(); //กำหนดให้ปุ่มไม่มีเส้นขอบ
fill( colorRed, colorGreen, colorBlue ); //กำหนดสีให้ปุ่ม
rect( x, y, w, h ); //วาดสี่เหลี่ยมกลางปุ่ม
ellipse( x, y + ( h / 2 ), h, h ); //วาดวงกลมเพื่อให้ปุ่มดูสวยงาม
ellipse( x + w, y + ( h / 2 ), h, h ); //วาดวงกลมเพื่อให้ปุ่มดูสวยงาม
}
boolean CheckOverButton ( int x, int y, int w, int h )
//ตรวจสอบว่าเมาส์อยู่บนสี่เหลี่ยมของปุ่มหรือไม่ หากอยู่ให้ส่งค่า true กลับ หากไม่ให้ส่งค่า false
{
if ( mouseX >= x && mouseX < x + w && mouseY >= y && mouseY < y + h )
{
return true;
}
return false;
}
//Gameplay_Smooth
void AddDropperSmooth () //ฟังก์ชั่นใช้ในการสร้างตัวกระโดดตึกในเกมโหมด smooth
{
addDropperTimeCount += 1; //เพิ่มค่า addDropperTimeCount
if ( addDropperTimeCount >= addDropperTime )
//ตรวจสอบว่า addDropperTimeCount มากกว่า addDropperTime แล้วหรือไม่ ถ้ามากกว่า ให้สร้างตัวละครขึ้นมาใหม่
{
addDropperTimeCount = 0; //เปลี่ยนค่าเวลาเป็นเวลาเริ่มต้นเพื่อนับใหม่จนถึงรอบอีกครั้ง
if ( addDropperTime > 102f ) addDropperTime -= 60f;
//ตรวจสอบว่าเวลาสร้างน้อยกว่าค่ากำหนดหรือไม่ ถ้ามากกว่าให้ลดเวลาเกิดให้ไวขึ้น
float startPositionX = -200; //สร้างตัวแปรเพื่อกำหนดจุดเกิดแกน X
float startPositionY = -70; //สร้างตัวแปรเพื่อกำหนดจุดเกิดแกน Y
dropperPositionXSmooth = append( dropperPositionXSmooth, startPositionX );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บตำแหน่งแกน X ของตัวกระโดดตึกตัวใหม่
dropperPositionYSmooth = append( dropperPositionYSmooth, startPositionY );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บตำแหน่งแกน Y ของตัวกระโดดตึกตัวใหม่
dropperSmoothSpeed = append( dropperSmoothSpeed, 0 );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บความเร็วของตัวกระโดดตึกตัวใหม่
}
}
void DropperSmoothMove () //ฟังก์ชั่นใช้ในการทำให้ตัวกระโดดตึกเคลื่อนที่ในเกมโหมด smooth
{
float gravity = 0.1; //สร้างตัวแปร gravity เพื่อเก็บค่าสำหรับการคำนวณ
for ( int dropperCount = 0; dropperCount < dropperPositionXSmooth.length; dropperCount++ )
//วนลูปเพื่อสร้างตัวโดดตึกแบบ smooth
{
if ( dropperPositionYSmooth[ dropperCount ] < height )
//ตรวจสอบว่าตำแหน่งแต่ละตัวในแกน Y เกินความสุงหรือไม่ ถ้าเกินไม่ต้องทำลูปนี้
{
if ( dropperPositionYSmooth[ dropperCount ] <= 240 ) dropperPositionXSmooth[ dropperCount ] += 1.5f;
//เปลี่ยนตำแหน่งแกน X
dropperPositionYSmooth[ dropperCount ] += dropperSmoothSpeed[ dropperCount ];
//เปลี่ยนตำแหน่งแกน Y ของตัวกระโดดตึกแต่ละตัว
dropperSmoothSpeed[ dropperCount ] += gravity; //เปลี่ยนความเร็วของตัวกระโดดตึกแต่ละตัว
if ( dropperPositionYSmooth[ dropperCount ] > 230 && dropperPositionYSmooth[ dropperCount ] <= 240 && dropperPositionXSmooth[ dropperCount ] > hotspitalManPosSmooth && dropperPositionXSmooth[ dropperCount ] < hotspitalManPosSmooth + 100 )
//ตรวจสอบว่าตัวกระโดดตึกอยู่ในตำแหน่งที่กำหนดหรือไม่ ถ้าใช่ให้เด้งต่อไป
{
dropperSmoothSpeed[ dropperCount ] = dropperSmoothSpeed[ dropperCount ] * -0.95;
playerScore += 1;
}
else if ( dropperPositionYSmooth[ dropperCount ] > 180 && dropperPositionXSmooth[ dropperCount ] > 300 )
//ตรวจสอบว่าถ้าตำแหน่งเกินที่กำหนดให้เปลี่ยนค่าเพื่อให้ตัวกระโดดหายไป แล้วเพิ่มคะแนน(เมื่อเด้งถึงรถพยาบาล)
{
dropperPositionYSmooth[ dropperCount ] = height + 100;
playerScore += 1;
}
else if ( dropperPositionYSmooth[ dropperCount ] > 400 )
//ตรวจสอบว่าถ้าตำแหน่งเกินตำแหน่งที่กำหนด ให้เปลี่ยนค่าเพื่อให้ตัวกระโดดหายไปแล้วลดคะแนน(กรณีที่รับไม่ทัน)
{
dropperPositionYSmooth[ dropperCount ] = height + 100;
playerHealthPoint -=1 ;
}
}
}
}
void DisplayDropperSmooth () //ฟังก์ชั่นใช้ในการแสดงผลตัวกระโดดตึกในเกมโหมด smooth
{
for ( int dropperCount = 0; dropperCount < dropperPositionXSmooth.length; dropperCount++ )
//วนลูปเพื่อวาดตัวกระโดดตึกทุกตัว
{
DrawPeopleDownMiddle( dropperPositionXSmooth[ dropperCount ], dropperPositionYSmooth[ dropperCount ] );
//วาดตัวกระโดดตึกโดยการตรวจสอบจากตำแหน่งในตัวแปร
}
}
//Gameplay_Step
void AddDropperStep () //ฟังก์ชั่นใช้ในการสร้างตัวกระโดดตึกในเกมโหมด step
{
addDropperTimeCount += 1; //เพิ่มเวลาให้ถึงเวลาที่ใช้ในการสร้างตัว
if ( addDropperTimeCount >= addDropperTime )
//ตรวรสอบหากถึงเวลาที่ตัวกระโดดตึกจะโดดให้สร้างตัวกระโดดตึก
{
addDropperTimeCount = 0; //รีเซทเวลาในการนับที่ใช้สร้างตัวกระโดดตึก
if ( addDropperTime > 102f )
//ตรวจสอบว่าเวลาสร้างน้อยกว่าค่ากำหนดหรือไม่ ถ้ามากกว่าให้ลดเวลาสร้างตัวกระโดดตึกให้ไวขึ้น
addDropperTime -= 25f; //ลดเวลาสร้างตัวกระโดดตึก
dropPositionStep = append( dropPositionStep, 0 ); //เพิ่มอาเรย์ 1 ช่องเพื่อเก็บตำแหน่งตัวกระโดด
dropTimeStep = append( dropTimeStep, 0 );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บเวลาตัวกระโดดใช้ตรวจสอบในการเปลี่ยน step
currentDropTimeStep = append( currentDropTimeStep, 0 );
//เพิ่มอาเรย์ 1 ช่องเพื่อเก็บเวลาที่ใช้นับในการเปลี่ยน step
dropTimeStep[ dropTimeStep.length - 1 ] = dropTimeStepSpeed;
//กำหนดค่าเริ่มต้นในการกระโดดแต่ละตัว
if ( dropTimeStepSpeed > 20 )
//ตรวจสอบว่าถ้าเวลายังไม่น้อยกว่าที่กำหนด ให้เพิมความเร็วในการเปลี่ยน step ของแต่ละตัว ( ความเร็วการเปลี่ยน step เร็วขึ้นเรือยๆ )
{
dropTimeStepSpeed -= 5; //ลดค่า dropTimeStepSpeed;
}
}
}
void ChangeStep () //ฟังก์ชั่นใช้ในการเปลี่ยนตำแหน่งของตัวกระโดดตึก
{
for ( int countDropper = 0; countDropper < dropPositionStep.length; countDropper++ )
//วนลูปเพื่อเปลี่ยนตำแหน่งของตัวกระโดดตึกแบบ step
{
currentDropTimeStep[ countDropper ] += 1f; //นับเวลาเพื่อเปลี่ยน step ของแต่ละตัว
if ( currentDropTimeStep[ countDropper ] >= dropTimeStep[ countDropper ] )
//ตรวจสอบถ้าเวลาถึงเวลาที่กำหนดให้เปลี่ยน step
{
if ( dropPositionStep[ countDropper ] < 100 )
//ตรวจสอบว่าถ้าตัวละครอยู่ในตำแหน่งที่เกินกำหนด ให้ไม่มีการเช็คเปลี่ยน step
{
currentDropTimeStep[ countDropper ] = 0f;
//รีเซทเวลาปัจจุบันที่นับอยู่ให้เริ่มนับใหม่ เพื่อเปลี่ยน step
dropPositionStep[ countDropper ] += 1; //เปลี่ยนตำแหน่งของตัวกระโดดตึก
if ( dropPositionStep[ countDropper ] == 51 || dropPositionStep[ countDropper ] == 61 || dropPositionStep[ countDropper ] == 71 )
//ตรวจสอบว่าตัวกระโดดตึกถึงจุดที่กำหนดให้ลดโอกาศพลาดผู้เล่น 1 ครั้ง
{
playerHealthPoint -=1; //ลดค่า playerHealthPoint
}
else if ( dropPositionStep[ countDropper ] == 52 || dropPositionStep[ countDropper ] == 62 || dropPositionStep[ countDropper ] == 72 )
//ตรวจสอบว่าถ้าตัวกระโดดตึกอยู่จุดที่กำหนดให้ออกจากฉาก
{
dropPositionStep[ countDropper ] = 100; //เอาตัวกระโดดตึกออกจากฉาก
}
if ( dropPositionStep[ countDropper ] == 3 && hospitalManPos == 0 )
//ตรวจสอบตัวกระโดดลงจุดที่กำหนดและตัวรับอยู่ในที่เดียวกัน ให้เพิ่มคะแนน
{
playerScore += 1; //เพิ่มคะแนน
}
else if ( dropPositionStep[ countDropper ] == 11 && hospitalManPos == 1 )
//ตรวจสอบตัวกระโดดลงจุดที่กำหนดและตัวรับอยู่ในที่เดียวกัน ให้เพิ่มคะแนน
{
playerScore += 1; //เพิ่มคะแนน
}
else if ( dropPositionStep[ countDropper ] == 18 && hospitalManPos == 2 )
//ตรวจสอบตัวกระโดดลงจุดที่กำหนดและตัวรับอยู่ในที่เดียวกัน ให้เพิ่มคะแนน
{
playerScore += 1; //เพิ่มคะแนน
}
else if ( dropPositionStep[ countDropper ] == 22 )
//ตรวจสอบตัวกระโดดลงที่จุดสุดท้าย (ตรงรถพยาบาล) ให้เพิ่มคะแนนแล้วนำตัวกระโดดตึกออกจากฉาก
{
playerScore += 1; //เพิ่มคะแนน
dropPositionStep[ countDropper ] = 100; //นำตัวกระโดดตึกออกจากฉาก
}
else if ( dropPositionStep[ countDropper ] == 3 && hospitalManPos != 0 )
//ตรวจสอบถ้ารับไม่ทัน ให้เปลี่ยนตำแหน่งไปที่ที่กำหนด
{
dropPositionStep[ countDropper ] = 50; //เปลี่ยนตำแหน่งตัวละคร ( แสดงผลจุดเดิม )
}
else if ( dropPositionStep[ countDropper ] == 11 && hospitalManPos != 1 )
//ตรวจสอบถ้ารับไม่ทัน ให้เปลี่ยนตำแหน่งไปที่ที่กำหนด
{
dropPositionStep[ countDropper ] = 60; //เปลี่ยนตำแหน่งตัวละคร ( แสดงผลจุดเดิม )
}
else if ( dropPositionStep[ countDropper ] == 18 && hospitalManPos != 2 )
//ตรวจสอบถ้ารับไม่ทัน ให้เปลี่ยนตำแหน่งไปที่ที่กำหนด
{
dropPositionStep[ countDropper ] = 70; //เปลี่ยนตำแหน่งตัวละคร ( แสดงผลจุดเดิม )
}
}
}
}
}
void DisplayDropperStep () //ฟังก์ชั่นใช้ในการแสดงผลของตัวกระโดดตึกในเกมโหมด step
{
for ( int dropper = 0; dropper < dropPositionStep.length; dropper++ )
{
DropperDisplayStep( dropPositionStep[ dropper ] ); //วาดตัวกระโดดตึกจากตำแหน่งในอาเรย์
}
}
//Display
void DropperDisplayStep ( int position )
//ฟังก์ชั่นใช้ในการตรวจสอบตำแหน่งของตัวกระโดดตึกในเกมโหมด step เพื่อวาดตัวกระโดดตึกในตำแหน่งต่างๆ
{
switch( position )
{
case 0 :
DrawPeopleFly( -210, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 1 :
DrawPeopleFly( -190, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 2 :
DrawPeopleDownMiddle( -170, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 3 :
DrawPeopleDownSide( -150, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขนอ้าปาก
break;
case 4 :
DrawPeopleFly( -120, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 5 :
DrawPeopleFly( -110, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 6 :
DrawPeopleFly( -80, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 7 :
DrawPeopleFly( -40, -100 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 8 :
DrawPeopleFly( 20, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 9 :
DrawPeopleFly( 40, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 10 :
DrawPeopleDownMiddle( 60, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 11 :
DrawPeopleDownMiddle( 80, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 12 :
DrawPeopleFly( 100, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 13 :
DrawPeopleFly( 120, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 14 :
DrawPeopleFly( 140, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 15 :
DrawPeopleFly( 170, -20 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 16 :
DrawPeopleFly( 200, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 17 :
DrawPeopleFly( 230, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 18 :
DrawPeopleDownSide( 260, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 19 :
DrawPeopleFly( 310, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกกางแขน
break;
case 20 :
DrawPeopleDownMiddle( 350, 60 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 21 :
DrawPeopleDownMiddle( 390, 140 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break;
case 50 :
DrawPeopleDownSide( -150, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 60 :
DrawPeopleDownMiddle( 80, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 70 :
DrawPeopleDownSide( 260, 220 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 51 :
DrawPeopleDownMiddle( -150, 330 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 61 :
DrawPeopleDownMiddle( 80, 330 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
case 71 :
DrawPeopleDownMiddle( 260, 330 ); //เรียกฟังก์ชั่นวาดตัวกระโดดตึกท่านั่ง
break; //Failed
}
}
void HospitalManDisplay ( int nowHospitalManPos )
//ฟังก์ชั่นใช้ในการแสดงผลตัวรับในเกมแบบ step โดยกำหนดเป็นตำแหน่งต่างๆ
{
switch( nowHospitalManPos )
{
case 0 :
DrawHospitalMan( -180, -10 ); //เรียกฟังก์ชั่นวาดตัวรับตามตำแหน่ง
break;
case 1 :
DrawHospitalMan( 0, -10 ); //เรียกฟังก์ชั่นวาดตัวรับตามตำแหน่ง
break;
case 2 :
DrawHospitalMan( 140, -10 ); //เรียกฟังก์ชั่นวาดตัวรับตามตำแหน่ง
break;
}
}
//Display Menu
void startFire() { //ฟังก์ชั่นในการสร้างตัวอักษรหน้าแรกของเกมส์
textSize(120);
fill(0);
text("F RE", 300, 275);
textSize(20);
fill(100);
text("Nintendo Game&Watch", 400, 300);
}
void peopleI() { //ฟังก์ชั่นในการสร้างตัวคนหลังตัว F ในส่วนหน้าแรกของเกมส์
strokeWeight(1);
stroke(0);
fill(#FA0808);
ellipse(400, 195, 10, 10);
fill(0);
ellipse(400, 225, 25, 25);
ellipse(400, 250, 25, 35);
fill(255);
stroke(255);
ellipse(421, 246, 30, 30);
ellipse(380, 246, 30, 30);
stroke(0);
fill(0);
ellipse(430, 238, 12, 8);
ellipse(427, 235, 5, 10);
ellipse(375, 238, 12, 8);
ellipse(378, 235, 5, 10);
ellipse(370, 270, 12, 8);
ellipse(435, 267, 12, 8);
ellipse(400, 215, 10, 20);
fill(255);
stroke(255);
ellipse(400, 227, 13, 10);
ellipse(405, 225, 10, 12);
ellipse(395, 225, 10, 12);
stroke(0);
strokeWeight(5);
line(400, 245, 425, 238);
line(400, 245, 375, 238);
line(408, 260, 425, 255);
line(408, 260, 375, 255);
line(377, 255, 374, 268);
line(423, 255, 432, 268);
}
void topBuilt() { //ฟังก์ชั่นในการสร้างเครื่องหมายกากบาทบนยอดตึกในส่วนหน้าแรกของเกมส์
noStroke();
fill(#FA2605);
rect(267, 160, 20, 50);
rect(252, 175, 50, 20);
}
void build() { //ฟังก์ชั่นในการวาดตึกด้านหน้าตัว F ในส่วนหน้าแรกของเกมส์
strokeWeight(5);
stroke(0);
fill(0);
rect(220, 192, 50, 80);
fill(255);
rect(223, 195, 13, 13);
rect(238, 195, 13, 13);
rect(253, 195, 13, 13);
rect(223, 210, 13, 13);
rect(238, 210, 13, 13);
rect(253, 210, 13, 13);
rect(223, 225, 13, 13);
rect(238, 225, 13, 13);
rect(253, 225, 13, 13);
}
//Display Objects
void DrawBackground() { //ฟังก์ชั่นในการวาด backgroung ทั้งหมดของเกมส์
//floor
int count=0;
int n=4;
int x=0;
int y=0;
stroke(198, 108, 0);
strokeWeight(7);
line(0, 455, 800, 455);
line(0, 520, 800, 520);
line(0, 520, 120, 455);
while (count < n) {
//กำหนดเงื่อนไขการทำงาน loop While โดยจะทำงานก็ต่อเมื่อ count ยังมีค่าน้อยกว่า n
line(80+x, 520, 170+y, 455);
//วาดเส้นตรงโดยมีการเเปลี่ยนแปลงมีการกำหนดค่า x และ y เพิ่มเข้าไป ทำให้มีการวาดซ้ำคนละตำแหน่ง
count=count+1; //เพิ่มค่า count เพื่อไปเช็กกับเงื่อนไข while
x=x+170; //เพิ่มค่าของ x ทีละ 170
y=y+140; //เพิ่มค่าของ y ทีละ 140
}
strokeWeight(5);
line(0, 475, 800, 475);
int a=0;
int b=0;
int c=12;
strokeWeight(5);
while (a<c) {
line(170+b, 550, 195+b, 550);
a=a+1;
b=b+30;
}
//fire
noStroke();
fill(#E84509);
ellipse(110, 80, 60, 25);
ellipse(170, 88, 45, 15);
triangle(120, 90, 148, 60, 165, 90);
fill(255);
ellipse(138, 97, 45, 15);
ellipse(170, 65, 40, 35);
ellipse(125, 60, 40, 35);
fill(#E84509);
ellipse(185, 75, 35, 35);
ellipse(165, 65, 20, 20);
fill(255);
triangle(210, 50, 190, 80, 185, 50);
ellipse(194, 70, 10, 10);
ellipse(175, 60, 20, 20);
ellipse(170, 73, 20, 20);
fill(#E84509);
triangle(160, 58, 165, 48, 168, 65);
triangle(156, 80, 160, 65, 163, 65);
triangle(110, 85, 125, 65, 130, 85);
triangle(110, 45, 135, 30, 110, 70);
triangle(110, 35, 125, 28, 110, 45);
triangle(155, 30, 158, 45, 170, 30);
triangle(155, 30, 180, 15, 170, 30);
fill(255);
ellipse(155, 20, 25, 20);
ellipse(168, 40, 15, 15);
fill(#E84509);
ellipse(145, 20, 10, 10);
triangle(140, 20, 155, 10, 150, 20);
triangle(145, 20, 138, 35, 150, 20);
fill(255);
ellipse(150, 22, 7, 7);
//grass
fill(#00BC33);
int i=0;
int z=0;
int r=6;
while (i<r) { //กำหนดการทำงาน While loop โดยจะสร้างสามเหลี่ยมี้ในตำแหน่งที่แตกต่างกัน
triangle(170+z, 545, 185+z, 535, 190+z, 540);
triangle(175+z, 530, 185+z, 540, 195+z, 540);
triangle(175+z, 550, 185+z, 540, 195+z, 540);
triangle(190+z, 525, 190+z, 540, 200+z, 540);
triangle(190+z, 550, 190+z, 540, 200+z, 540);
triangle(200+z, 525, 195+z, 540, 210+z, 540);
triangle(215+z, 547, 195+z, 540, 210+z, 540);
triangle(225+z, 545, 200+z, 535, 210+z, 535);
triangle(235+z, 540, 210+z, 530, 210+z, 535);
triangle(225+z, 525, 200+z, 535, 210+z, 535);
i=i+1;
z=z+60;
}
}
void DrawBuilding() { //ฟังก์ชั่นในการวาดตึกที่เกิดไฟไหม้
pushMatrix();
scale( 2 );
stroke(0);
strokeCap(0);
strokeWeight(5);
fill(#BC7C13);
rect(-10, -10, 45, 243);
strokeWeight(8);
line(-3, 235, 50, 235);
strokeWeight(2);
fill(#49D7E8);
rect(-3, -3, 15, 20);
rect(-3, 48, 15, 20);
rect(-3, 98, 15, 20);
rect(-3, 148, 15, 20);
stroke(255);
line(11, 0, -3, 20);
line(11, 50, -3, 70);
line(11, 100, -3, 120);
line(11, 150, -3, 170);
stroke(0);
fill(#BC7C13);
rect(-10, 175, 65, 15);
rect(-10, 125, 65, 15);
rect(-10, 75, 65, 15);
rect(-10, 25, 65, 15);
line(-5, 165, 55, 165);
line(-5, 115, 55, 115);
line(-5, 65, 55, 65);
line(-5, 15, 55, 15);
line(55, 15, 55, 25);
line(55, 65, 55, 75);
line(55, 115, 55, 125);
line(55, 165, 55, 175);
line(45, 15, 45, 25);
line(45, 65, 45, 75);
line(45, 115, 45, 125);
line(45, 165, 45, 175);
line(25, 15, 25, 25);
line(25, 65, 25, 75);
line(25, 115, 25, 125);
line(25, 165, 25, 175);
line(5, 15, 5, 25);
line(5, 65, 5, 75);
line(5, 115, 5, 125);
line(5, 165, 5, 175);
popMatrix();
}
void DrawAmbulance( float posX, float posY ) { //ฟังก์ชั่นในการวาดรถพยาบาล
pushMatrix();
translate( posX, posY );
stroke(0);
strokeWeight(3);
fill(255);
rect(580, 330, 170, 130, 30, 55, 5, 5);
rect(570, 440, 30, 20, 5, 90, 5, 5);
rect(730, 440, 30, 20, 90, 30, 5, 5);
rect(580, 410, 15, 20, 0, 10, 10, 0);
rect(580, 350, 20, 40, 3, 10, 10, 0);
ellipse(615, 450, 40, 40);
ellipse(715, 450, 40, 40);
rect(740, 398, 10, 15, 5, 0, 0, 5);
rect(730, 398, 10, 15, 5, 5, 5, 5);
fill(255);
rect(700, 350, 48, 40, 5, 60, 5, 5);
fill(#63E5F0);
rect(620, 350, 60, 40, 5, 5, 5, 5);
stroke(255);
rect(723, 360, 20, 25, 0, 20, 0, 0);
line(723, 367, 745, 367);
fill(255);
triangle(623, 353, 645, 353, 623, 380);
strokeWeight(7);
line(645, 385, 670, 353);
strokeWeight(4);
line(623, 386, 675, 386);
line(623, 353, 675, 353);
line(675, 353, 675, 386);
stroke(0);
fill(0);
ellipse(615, 458, 33, 33);
ellipse(715, 458, 33, 33);
fill(255);
ellipse(615, 458, 20, 20);
ellipse(715, 458, 20, 20);
strokeWeight(5);
line(580, 400, 645, 400);
line(680, 400, 715, 400);
strokeWeight(1);
stroke(255, 0, 0);
fill(255, 0, 0);
rect(685, 303, 15, 25, 10, 10, 0, 0);
fill(255);
rect(695, 305, 5, 23, 0, 10, 0, 0);
strokeWeight(3);
stroke(0);
fill(255);
rect(685, 320, 15, 8);
stroke(255, 0, 0);
line(710, 315, 730, 315);
line(655, 315, 675, 315);
noStroke();
fill(255, 0, 0);
rect(655, 400, 20, 40);
rect(645, 410, 40, 20);
triangle(710, 305, 725, 300, 730, 305);
triangle(705, 300, 715, 290, 725, 290);
triangle(710-35, 305, 725-65, 300, 730-75, 305);
triangle(705-20, 300, 715-50, 290, 725-50, 290);
popMatrix();
}
void DrawHospitalMan( float posX, float posY ) { //ฟังก์ชั่นสำหรับสร้างตัวรับที่ผู้ใช้ใช้ในการเลื่อนรับตัวที่ตกจากตึก
pushMatrix();
translate( posX, posY );
stroke(0);
strokeWeight(2);
//body l
fill(0);
rect(338, 435, 10, 10);
ellipse(318, 447, 17, 20);
ellipse(335, 435, 27, 20);
ellipse(348, 447, 18, 10);
fill(255);
stroke(255);
ellipse(332, 450, 20, 17);
ellipse(323, 430, 17, 17);
ellipse(348, 430, 17, 17);
triangle(300, 450, 310, 437, 315, 453);
ellipse(320, 438, 4, 5);
ellipse(323, 450, 4, 4);
ellipse(337, 445, 10, 10);
ellipse(348, 439, 3, 3);
//body r
fill(0);
stroke(0);
rect(438, 435, 10, 10);
ellipse(418, 447, 17, 20);
ellipse(435, 435, 27, 20);
ellipse(448, 447, 18, 10);
fill(255);
stroke(255);
ellipse(432, 450, 20, 17);
ellipse(423, 430, 17, 17);
ellipse(448, 430, 17, 17);
triangle(400, 450, 410, 437, 415, 453);
ellipse(420, 438, 4, 5);
ellipse(423, 450, 4, 4);
ellipse(437, 445, 10, 10);
ellipse(448, 439, 3, 3);
//head
fill(0);
stroke(0);
ellipse(335, 422, 10, 10);
ellipse(435, 422, 10, 10);
fill(255);
stroke(255);
ellipse(343, 417, 10, 10);
ellipse(427, 417, 10, 10);
ellipse(443, 417, 10, 10);
fill(0);
stroke(0);
ellipse(330, 405, 25, 25);
ellipse(435, 405, 25, 25);
ellipse(336, 395, 8, 13);
ellipse(323, 400, 20, 20);
triangle(315, 400, 329, 385, 329, 400);
triangle(318, 400, 327, 422, 327, 400);
fill(255);
stroke(255);
ellipse(335, 408, 10, 8);
ellipse(346, 408, 10, 10);
ellipse(330, 398, 4, 4);
ellipse(320, 395, 5, 5);
fill(0);
stroke(0);
ellipse(440, 398, 20, 20);
ellipse(428, 392, 8, 12);
triangle(437, 382, 430, 400, 445, 400);
triangle(430, 400, 443, 420, 448, 400);
fill(255);
stroke(255);
ellipse(430, 408, 15, 9);
ellipse(420, 408, 12, 12);
ellipse(435, 397, 5, 5);
ellipse(443, 392, 6, 6);
//arm
fill(0);
stroke(0);
triangle(333, 423, 360, 423, 360, 430);
triangle(438, 423, 410, 423, 410, 430);
ellipse(360, 425, 13, 10);
ellipse(410, 425, 13, 10);
ellipse(357, 423, 5, 10);
ellipse(413, 423, 5, 10);
strokeWeight(5);
line(360, 425, 410, 425);
popMatrix();
}
void DrawPeopleFly(float x, float y) { //ฟังก์ชั่นที่ใช้สำหรับสร้างตัวที่กระโดดลงมาจากตึก
pushMatrix();
scale( 0.8f );
strokeWeight(1);
stroke(0);
fill(0);
ellipse(400+x, 225+y, 25, 25);
ellipse(400+x, 250+y, 25, 35);
fill(255);
stroke(255);
ellipse(421+x, 246+y, 30, 30);
ellipse(380+x, 246+y, 30, 30);
stroke(0);
fill(0);
ellipse(430+x, 238+y, 12, 8);
ellipse(427+x, 235+y, 5, 10);
ellipse(375+x, 238+y, 12, 8);
ellipse(378+x, 235+y, 5, 10);
ellipse(370+x, 270+y, 12, 8);
ellipse(435+x, 267+y, 12, 8);
ellipse(409+x, 217+y, 13, 10);
fill(255);
stroke(255);
ellipse(405+x, 227+y, 12, 8);
ellipse(415+x, 225+y, 10, 10);
fill(0);
stroke(0);
strokeWeight(5);
line(400+x, 245+y, 425+x, 238+y);
line(400+x, 245+y, 375+x, 238+y);
line(408+x, 260+y, 425+x, 255+y);
line(408+x, 260+y, 375+x, 255+y);
line(377+x, 255+y, 374+x, 268+y);
line(423+x, 255+y, 432+x, 268+y);
popMatrix();
}
void DrawPeopleDownSide(float x, float y) { //ฟังก์ชั่นสำหรับสร้างตัวที่ตกลงมาจากตึกในหน้าตรงกางแขนกางขา
pushMatrix();
scale( 0.8f );
strokeWeight(1);
stroke(0);
fill(0);
ellipse(400+x, 225+y, 25, 25);
ellipse(400+x, 250+y, 25, 35);
fill(255);
stroke(255);
ellipse(421+x, 246+y, 30, 30);
ellipse(380+x, 246+y, 30, 30);
stroke(0);
fill(0);
ellipse(430+x, 238+y, 12, 8);
ellipse(427+x, 235+y, 5, 10);
ellipse(375+x, 238+y, 12, 8);
ellipse(378+x, 235+y, 5, 10);
ellipse(370+x, 270+y, 12, 8);
ellipse(435+x, 267+y, 12, 8);
ellipse(400+x, 215+y, 10, 20);
fill(255);
stroke(255);
ellipse(400+x, 227+y, 13, 10);
ellipse(405+x, 225+y, 10, 12);
ellipse(395+x, 225+y, 10, 12);
stroke(0);
strokeWeight(5);
line(400+x, 245+y, 425+x, 238+y);
line(400+x, 245+y, 375+x, 238+y);
line(408+x, 260+y, 425+x, 255+y);
line(408+x, 260+y, 375+x, 255+y);
line(377+x, 255+y, 374+x, 268+y);
line(423+x, 255+y, 432+x, 268+y);
popMatrix();
}
void DrawPeopleDownMiddle(float x, float y) { //ฟังก์ชั่นสำหรับสร้างตัวที่ตกลงมาจากตึกในท่านั่ง
pushMatrix();
scale( 0.8f );
strokeWeight(1);
stroke(0);
fill(0);
ellipse(402+x, 245+y, 50, 50);
stroke(255);
fill(255);
ellipse(417+x, 238+y, 50, 50);
ellipse(407+x, 225+y, 50, 50);
stroke(0);
fill(0);
ellipse(382+x, 235+y, 25, 25);
ellipse(422+x, 235+y, 8, 12);
ellipse(430+x, 260+y, 8, 12);
ellipse(367+x, 265+y, 12, 8);
fill(255);
stroke(255);
ellipse(385+x, 236+y, 13, 10);
ellipse(392+x, 232+y, 10, 10);
stroke(0);
fill(0);
ellipse(389+x, 227+y, 8, 12);
strokeWeight(5);
line(402+x, 265+y, 415+x, 255+y);
line(412+x, 255+y, 429+x, 260+y);
line(397+x, 265+y, 407+x, 240+y);
line(407+x, 242+y, 427+x, 235+y);
line(380+x, 250+y, 367+x, 253+y);
line(369+x, 253+y, 370+x, 265+y);
fill(255);
strokeWeight(1);
stroke(255);
ellipse(417+x, 266+y, 15, 15);
ellipse(407+x, 270+y, 8, 8);
triangle(409+x, 263+y, 397+x, 273+y, 427+x, 270+y);
popMatrix();
}
void smoke() { //ฟังก์ชั่นสำหรับวาดควันไฟ
smokeTime++;
if ( smokeTime == 30 ){
smokeTime = 0;
smokeStep++;
if ( smokeStep == 3 ){
smokeStep = 0;
}
}
if ( smokeStep == 2 ){
strokeWeight(1);
stroke(0);
fill(0);
ellipse(275, 15, 30, 30);
ellipse(290, 20, 25, 25);
ellipse(300, 35, 25, 25);
ellipse(305, 55, 35, 25);
ellipse(300, 70, 25, 15);
stroke(255);
fill(255);
ellipse(273, 18, 25, 25);
ellipse(287, 23, 22, 22);
ellipse(295, 37, 20, 22);
ellipse(297, 57, 32, 22);
ellipse(295, 70, 18, 10);
ellipse(273, 27, 10, 10);
}
else if ( smokeStep == 1 ){
//smokeII
strokeWeight(1);
stroke(0);
fill(0);
ellipse(185, 15, 30, 30);
ellipse(205, 25, 27, 27);
ellipse(220, 23, 29, 29);
ellipse(240, 27, 25, 25);
ellipse(248, 32, 25, 25);
ellipse(252, 40, 30, 20);
ellipse(257, 55, 30, 30);
ellipse(252, 70, 20, 10);
ellipse(245, 75, 20, 10);
stroke(255);
fill(255);
ellipse(183, 19, 26, 26);
ellipse(202, 28, 24, 24);
ellipse(218, 26, 26, 26);
ellipse(238, 30, 22, 22);
ellipse(245, 35, 22, 22);
ellipse(248, 40, 25, 15);
ellipse(250, 55, 30, 22);
ellipse(248, 70, 17, 7);
ellipse(240, 73, 18, 8);
ellipse(215, 45, 55, 40);
}
else if ( smokeStep == 0 ){
//smokeI
strokeWeight(1);
stroke(0);
fill(0);
ellipse(190, 30, 20, 20);
ellipse(200, 35, 20, 20);
ellipse(217, 35, 20, 20);
ellipse(230, 45, 23, 23);
ellipse(220, 63, 25, 25);
ellipse(205, 70, 25, 25);
stroke(255);
fill(255);
ellipse(187, 33, 17, 17);
ellipse(197, 38, 17, 17);
ellipse(215, 40, 17, 17);
ellipse(225, 46, 20, 18);
ellipse(215, 63, 22, 18);
ellipse(200, 70, 25, 25);
ellipse(210, 50, 20, 20);
}
}
void Health(int x) { //ฟังก์ชั่นสำหรับวาดชีวิตคนในส่วนใต้ score
strokeWeight(1);
stroke(0);
fill(0);
ellipse(680+x, 80, 10, 10);
ellipse(680+x, 90, 13, 15);
fill(255);
stroke(255);
ellipse(670+x, 90, 13, 15);
ellipse(690+x, 90, 13, 15);
stroke(0);
fill(0);
ellipse(660+x, 82, 5, 3);
ellipse(662+x, 80, 1, 4);
ellipse(698+x, 82, 5, 3);
ellipse(696+x, 80, 1, 4);
ellipse(658+x, 102, 5, 3);
ellipse(703+x, 102, 5, 3);
ellipse(680+x, 75, 5, 8);
fill(255);
stroke(255);
ellipse(680+x, 81, 5, 3);
ellipse(678+x, 80, 3, 5);
ellipse(682+x, 80, 3, 5);
stroke(0);
strokeWeight(2);
line(680+x, 85, 660+x, 82);
line(680+x, 85, 695+x, 82);
line(680+x, 95, 665+x, 90);
line(680+x, 95, 692+x, 90);
line(665+x, 90, 660+x, 102);
line(692+x, 90, 700+x, 102);
}
สมัครสมาชิก:
บทความ (Atom)