let Wa=0.25*1024;Wb=0.75*1024-80; H=0.7*600; H1=0.8*600; let count_a=0;count_b=0;count_c=0; let score_a=0;let score_b=0; let time=0; let n=0;n1=0; let myFont; function preload() { myFont = loadFont('pixelmix.ttf'); } function setup() { createCanvas(1024, 600); textFont(myFont); } function draw() { background(68, 58, 112); push(); textSize(24); fill(172,212,255); textAlign(CENTER); text('9. Co-exist',0.5*width,0.5*height); pop(); if(keyIsDown(83)){ fill(34,255,193); }else{ fill(255);} rect(Wa+40,0.5*(H+H1),200,4); if(keyIsDown(75)){ fill(34,255,193); }else{ fill(255);} rect(Wb+40,0.5*(H+H1),-200,4); //第三者 fill(255, 255, 255); noStroke(); beginShape(); vertex(0.5*width-40,H); vertex(0.5*width+40,H); vertex(0.5*width+25,H1); vertex(0.5*width-25,H1); endShape(CLOSE); //pot push(); fill(180, 172, 80); rect(0.5*width-4,H,8,-count_c); pop(); //stem //Player-a: fill(255, 255, 255); noStroke(); beginShape(); vertex(Wa,H); vertex(Wa+80,H); vertex(Wa+65,H1); vertex(Wa+15,H1); endShape(CLOSE); //pot fill(255); rect(Wa-80,H1,210,-2); rect(Wa-30,H1,8,-390); rect(Wa-36,H1-60,20,-40); rect(Wa-36,H1-360,20,-30); rect(Wa-36,H1-370,30,-10); beginShape(); vertex(Wa-16,H1-90); vertex(Wa+62,H1-90); vertex(Wa-16,H1-80); endShape(); push(); fill(180, 172, 80); rect(Wa+36,H,8,-count_a); pop(); //stem beginShape(); vertex(Wa-16,H1-70); vertex(Wa+62,H1-70); vertex(Wa-16,H1-80); endShape(); //scissor push(); textSize(12); textAlign(LEFT); text('Nutrient:',30,0.4*height); if(count_c>160){ rect(30,0.4*height+12,(150-count_a+n1)*0.56,10); }else{ rect(30,0.4*height+12,(150-count_a-n)*0.56,10); } text('Buff:',30,0.5*height); text('/',30,0.5*height+20); pop(); //player-b fill(255, 255, 255); noStroke(); beginShape(); vertex(Wb,H); vertex(Wb+80,H); vertex(Wb+65,H1); vertex(Wb+15,H1); endShape(CLOSE); //pot fill(255); rect(Wb+160,H1,-210,-2);//base rect(Wb+110,H1,-8,-390);//pole rect(Wb+116,H1-60,-20,-40);//scissor holder rect(Wb+116,H1-360,-20,-30); rect(Wb+116,H1-370,-30,-10);//beam beginShape(); vertex(Wb+96,H1-90); vertex(Wb+18,H1-90); vertex(Wb+96,H1-80); endShape(); push(); fill(180, 172, 80); rect(Wb+36,H,8,-count_b); pop(); //stem beginShape(); vertex(Wb+96,H1-70); vertex(Wb+18,H1-70); vertex(Wb+96,H1-80); endShape(); //scissor push(); textSize(12); textAlign(RIGHT); text('Nutrient:',width-30,0.4*height); if(count_c>160){ rect(width-30,0.4*height+12,-(150-count_b+n1)*0.56,10); }else{ rect(width-30,0.4*height+12,-(150-count_b-n)*0.56,10); } text('Buff:',width-30,0.5*height); text('/',width-30,0.5*height+20); pop(); //General push(); fill(34,255,193); textSize(18); text('Touch this laser beam together',0.5*width,H-330); strokeWeight(4); stroke(34,255,193); line(Wa-6,H-315,Wb+86,H-315); pop(); //red-line fill(255, 255, 255); textSize(18); textAlign(CENTER); textSize(18); text('Press A', Wa+40, H1+60); text('Press L', Wb+40, H1+60); text('Press S or K', 0.5*width, H1+60); //control textSize(15); fill(68, 58, 112); text('HELP!', 0.5*width, H1-25); //if let a=150-count_a-n; let b=150-count_b-n; if(a<=0 && b<=0){ noLoop(); fill(68, 58, 112); rect(Wa,H-360,500,40) fill(250,130,130); textSize(18); text('You starved to death',0.5*width,H-330); } time++; if (time==1000){ fill(68, 58, 112); rect(Wa,H-360,500,40); fill(34,255,193); textSize(18); text('Why compete but not co-exist?',0.5*width,H-330); score_a++; score_b++; noLoop(); fill(34,255,193); beginShape(); vertex(Wa,H); vertex(Wa+80,H); vertex(Wa+65,H1); vertex(Wa+15,H1); endShape(CLOSE); //pot beginShape(); vertex(0.5*width-40,H); vertex(0.5*width+40,H); vertex(0.5*width+25,H1); vertex(0.5*width-25,H1); endShape(CLOSE); //pot beginShape(); vertex(Wb,H); vertex(Wb+80,H); vertex(Wb+65,H1); vertex(Wb+15,H1); endShape(CLOSE); //pot rect(Wa+40,0.5*(H+H1),200,4); rect(Wb+40,0.5*(H+H1),-200,4); } //win push(); textSize(16); textAlign(LEFT); fill(255); text('Score:',30,H-335); textSize(28); text(score_a+'/'+score_b,30,H-300); pop(); fill(255, 228, 150); star(Wa+40, H-25-count_a, 40, 25, 20);//outside fill(200, 120, 0, 80); ellipse(Wa+40,H-25-count_a,32);//inside //flowera fill(169, 156, 255); star(Wb+40, H-25-count_b, 40, 25, 20);//outside fill(145, 127, 255); ellipse(Wb+40,H-25-count_b,32);//inside //flowerb fill(255); star(0.5*width, H-25-count_c, 40, 25, 20);//outside fill(172,212,255); ellipse(0.5*width,H-25-count_c,32);//inside //flowerc fill(68, 58, 112); rect(0,0,30,height); rect(width-30,0,30,height); //margin } function keyTyped() { if (key === 'a') { count_a+=10; } if (key === 'l') { count_b+=10; } if (key === 's') { if(count_c>160){ n1+=5; count_c+=5; } else { n+=10; count_c+=5} } if (key === 'k') { if(count_c>160){ n1+=5; count_c+=5; } else { n+=5; count_c+=5} } } function star(x, y, radius1, radius2, npoints) { let angle = TWO_PI / npoints; let halfAngle = angle / 2.0; beginShape(); for (let a = 0; a < TWO_PI; a += angle) { let sx = x + cos(a) * radius2; let sy = y + sin(a) * radius2; vertex(sx, sy); sx = x + cos(a + halfAngle) * radius1; sy = y + sin(a + halfAngle) * radius1; vertex(sx, sy); } endShape(CLOSE); }