int x=-100;
int r_smooth = 80;
int r_step = 80;
int x_butt=0;
int chk_SMOOTH=0;
int chk_STEP=0;
int a, b, g;
float dx, dy, total;
int highscore;
int c = 90;
int c1 = 90;
int j = 0;
int j1 = 0;
int inc = 1;
int count = 0;
int rounds = 1;
int s = 0; // ตัวนับจังหวะ
int d =50; // ตัวหาร
int k = 320; // ระยะของปุ่มกด start
int k1 = 50; // ระยะของปุ่มกด TryAgain
int ytop = 125;
int xtop = -100;
int xbot = 470;
int ybot = 275;
void setup() {
size(400, 400);
}
void draw() {
startpage();
if (j >=1 ) {
background(255);
backgrounds(180);
backgrounds(330);
drawMan();
changeSmooth();
keyPressed();
gameover();
}
if (j1 >= 1) {
background(255);
backgrounds(180);
backgrounds(330);
drawMan();
changeStep();
keyPressed();
gameover();
}
s++;
}
void mousePressed() {
if (mouseX>=100 && mouseX<= 140) {
dx = mouseX-120;
dy = mouseY-330;
total = sqrt((dx*dx)+(dy*dy));
if (total <= r_smooth /2 ) {
j++;
}
}
if (mouseX>=210 && mouseX<= 350) {
dx = mouseX-280;
dy = mouseY-330;
total = sqrt((dx*dx)+(dy*dy));
if (total <= r_step /2 ) {
j1++;
}
}
}
void startpage() {
background(0);
PFont font;
a= (int)random(0, 255);
b = (int)random(0, 255);
g = (int )random(0, 255);
fill(a, b, g);
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, 260);
x+= 1;
if (x >=400) {
x = -200;
}
strokeWeight(10);
stroke(#48D0F7);
smooth_butt();
step_butt();
}
void smooth_butt() {
fill(0);
stroke(#FFDF24);
fill(#F20F0F);
ellipse(120, 330, r_smooth, r_smooth);
fill(255);
PFont font;
textSize(14);
text("SMOOTH", 90, 340);
dx = mouseX-120;
dy = mouseY-330;
total = sqrt((dx*dx)+(dy*dy));
if (total<= r_smooth/2) {
r_smooth= 100;
}
else {
r_smooth = 80;
}
}
void step_butt() {
fill(0);
fill(#F20F0F);
ellipse(280, 330, r_step, r_step);
fill(255);
PFont font;
textSize(17);
text("STEP", 263, 340);
dx = mouseX-280;
dy = mouseY-330;
total = sqrt((dx*dx)+(dy*dy));
if (total<= r_step/2) {
r_step= 100;
}
else {
r_step = 80;
}
}
void tryAgain() {
int y = 50;
fill(#1BE3A8);
noStroke();
fill(#B2FCEF);
rect(k1-30, 320, y+80, y+10);
fill(#1BE3A8);
rect(k1-20, 325, y+60, y);
fill(0);
textSize(19);
text("TryAgain", k1-10, 355);
}
void highScore() {
text("HIGH SCORE = "+highscore, 250, 20);
if (highscore <count) {
highscore = count;
}
}
void backgrounds(int y) {
fill(0);
textSize(15);
text("Miss ",100,20);
text("Score = "+ count, 300, 50);
highScore();
stroke(#5A2E01);
strokeWeight(10);
line(0, y, 78, y);
noStroke();
fill(#A77413);
rect(0, y, 80, 50);
stroke(#5A2E01);
strokeWeight(10);
line(152, y, 228, y);
noStroke();
fill(#A77413);
rect(150, y, 80, 50);
fill(255);
ellipse(230, y+30, 50, 60);
ellipse(150, y+30, 50, 60);
ellipse(0, y+30, 50, 60);
ellipse(80, y+30, 50, 60);
fill(#2BDED0);
ellipse(95, y+50, 20, 5);
ellipse(109, y+45, 20, 5);
ellipse(120, y+50, 20, 5);
ellipse(135, y+45, 20, 5);
stroke(#5A2E01);
strokeWeight(10);
line(302, y, 398, y);
noStroke();
fill(#A77413);
rect(300, y, 100, 50);
fill(255);
ellipse(300, y+30, 50, 60);
fill(255);
ellipse(400, y+30, 50, 60);
fill(#2BDED0);
ellipse(245, y+50, 20, 5);
ellipse(260, y+45, 20, 5);
ellipse(275, y+50, 20, 5);
ellipse(290, y+45, 20, 5);
fill(#A4F0F2); // sky
ellipse(50, 30, 70, 40);
ellipse(80, 40, 60, 30);
ellipse(20, 40, 50, 30);
ellipse(200, 60, 50, 30);
ellipse(230, 50, 80, 50);
ellipse(260, 60, 60, 30);
}
void miss(int x,int 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);
strokeWeight(5);
}
void drawMan() {
fill(0);
ellipse(xtop, ytop, 30, 25); //หัว
ellipse(xtop+15, ytop, 10, 5);// จมูก
fill(255);
noStroke();
ellipse(xtop, ytop+7, 25, 10);// ปาก
stroke(0);
strokeWeight(1);
line(xtop-2, ytop, xtop-2, ytop+13);// ฟัน
line(xtop-8, ytop, xtop-8, ytop+10);
line(xtop-5, ytop, xtop-5, ytop+12);
line(xtop+1, ytop, xtop+1, ytop+12);
line(xtop+4, ytop, xtop+4, ytop+10);
line(xtop+7, ytop, xtop+7, ytop+10);
ellipse(xtop-1, ytop-5, 8, 10); // ตา
ellipse(xtop+7, ytop-5, 7, 10);
fill(0);
ellipse(xtop, ytop-5, 4, 4);
ellipse(xtop+8, ytop-5, 4, 4);
strokeWeight(5);
line(xtop, ytop+15, xtop, ytop+20);// คอ
ellipse(xtop, ytop+27, 20, 15);// ตัว
line(xtop-5, ytop+38, xtop-10, ytop+45); // ขา
line(xtop+5, ytop+38, xtop+10, ytop+45);
line(xtop-14, ytop+23, xtop-25, ytop+12); // แขน
ellipse(xtop-25, ytop+12, 5, 5);
line(xtop+13, ytop+23, xtop+25, ytop+12); // แขน
ellipse(xtop+25, ytop+12, 5, 5);
line(xtop-20, ytop+48, xtop-5, ytop+48);// เท้า
line(xtop+5, ytop+48, xtop+20, ytop+48);
}
void drawMan2() {
fill(0);
ellipse(xbot, ybot, 30, 25); //หัว
ellipse(xbot-15, ybot, 10, 5);// จมูก
fill(255);
noStroke();
ellipse(xbot, ybot+7, 25, 10);// ปาก
stroke(0);
strokeWeight(1);
line(xbot-2, ybot, xbot-2, ybot+13);// ฟัน
line(xbot-8, ybot, xbot-8, ybot+10);
line(xbot-5, ybot, xbot-5, ybot+12);
line(xbot+1, ybot, xbot+1, ybot+12);
line(xbot+4, ybot, xbot+4, ybot+10);
line(xbot+7, ybot, xbot+7, ybot+10);
ellipse(xbot-8, ybot-5, 8, 10); // ตา
ellipse(xbot, ybot-5, 7, 10);
fill(0);
ellipse(xbot-10, ybot-5, 4, 4);
ellipse(xbot-2, ybot-5, 4, 4);
strokeWeight(5);
line(xbot, ybot+15, xbot, ybot+20);// คอ
ellipse(xbot, ybot+27, 20, 15);// ตัว
line(xbot-5, ybot+38, xbot-10, ybot+45); // ขา
line(xbot+5, ybot+38, xbot+10, ybot+45);
line(xbot-14, ybot+23, xbot-25, ybot+12); // แขน
ellipse(xbot-25, ybot+12, 5, 5);
line(xbot+13, ybot+23, xbot+25, ybot+30); // แขน
ellipse(xbot+25, ybot+30, 5, 5);
line(xbot-20, ybot+48, xbot-5, ybot+48);// เท้า
line(xbot+5, ybot+48, xbot+20, ybot+48);
}
void manhold(int x, int 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);
}
void manfall(int x, int y) {
fill(0);
strokeWeight(15);// ตัว
line(x+5, y+18, x+20, y+25);
strokeWeight(1);
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(255);
noStroke();
ellipse(x-20, y+25, 15, 15);
ellipse(x+42, y+14, 15, 10);
}
void changeSmooth() {
drawMan();
if (xtop+15<= width+80 && ytop == 125) {
xtop+= inc;
}
if (xtop+15>width+60 && ytop == 125 ) {
drawMan2();
xbot-=inc;
}
if (xbot+15 <= -80 && ybot == 275 ) {
xtop = -50;
xbot = 470;
}
if (xbot <= -20) {
rounds++;
xbot = 470;
xtop = -50;
}
}
void changeStep() {
inc = 70;
drawMan();
if (xtop+15<= width+80 && ytop == 125) {
if (s%d==5) {
xtop+= inc;
}
}
if (xtop+15>width+60 && ytop == 125 ) {
drawMan2();
if (s%d==5) {
xbot-=inc;
}
}
if (xbot+15 <= -80 && ybot == 275 ) {
if (s%d==5) {
xtop = -50;
xbot = 470;
}
}
if (xbot <= -20) {
if (s%d==5) {
rounds++;
xbot = 470;
xtop = -100;
}
}
}
void keyPressed() {
int a = 110;
int b = 190;
if (key == 'w' ) {
if (xtop%5==0 ) {
if (xtop >= c && xtop <= c+40) {
if (ytop == 125 ) {
count = count + 1;
}
c = 0;
}
}
stroke(0);
strokeWeight(7);
line(a-23, b-12, a+29, b-12);
strokeWeight(1);
manhold(150, 190);
}
if (key == 'd' ) {
a = 125;
b = 335;
if (xbot%5==0 ) {
if (xbot >= c+260 && xbot <= c+285) {
if (ybot == 275) {
count = count + 1;
}
c=-235;
}
}
stroke(0);
strokeWeight(7);
line(a-38, b-7, a+17, b-7);
strokeWeight(1);
manhold(150, 340);
}
if (key == 'o' ) {
a = 245;
b = 190;
if (xtop%5==0 ) {
if (xtop >= c+250 && xtop <= c+290) {
if (ytop == 125) {
count = count + 1;
}
c=-50;
}
}
stroke(0);
strokeWeight(7);
line(a-8, b-12, a+47, b-12);
strokeWeight(1);
manhold(290, 190);
}
if (key == 'k' ) {
a = 240;
b = 335;
if (xbot%5==0 ) {
if (xbot >= c+300 && xbot <=c+320) {
if (ybot == 275) {
count = count + 1;
}
c = -150;
}
}
stroke(0);
strokeWeight(7);
line(a-3, b-7, a+52, b-7);
strokeWeight(1);
manhold(290, 340);
}
if ( c==-235) {
c = 90;
}
}
void gameover() {
if (key != 'w') {
if (xtop >= 87&& xtop<=165 ) {
xtop=95;
ytop+=1;
}
}
if (key != 'o') {
if (xtop >= 250&& xtop<=300) {
xtop=250;
ytop+=1;
}
}
if (key != 'k') {
if (xbot >= 230&& xbot<=290) {
xbot = 275;
ybot+=1;
}
}
if (key != 'd') {
if (xbot >= 87&& xbot<=140) {
xbot = 130;
ybot+=1;
}
}
if (ytop >= 140 || ybot >=330 ) {
if (xtop == 95) {
ytop = 450;
manfall(110, 190);
miss(100,50);
}
if (xtop == 250) {
ytop = 450;
manfall(255, 190);
}
if (xbot == 130) {
ybot = 450;
manfall(110, 340);
}
if (xbot == 275) {
ybot = 450;
manfall(255, 340);
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น