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; let score_a=0;let score_b=0; let time=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('1. A fair start',0.5*width,0.5*height); pop(); fill(172,212,255); //rect(0,0,width,0.56*height); //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); rect(30,0.4*height+12,(250-count_a)*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); rect(width-30,0.4*height+12,-(250-count_b)*0.56,10); text('Buff:',width-30,0.5*height); text('/',width-30,0.5*height+20); pop(); //General push(); fill(255,130,130); textSize(18); text('Touch this laser beam first or die',0.5*width,H-330); strokeWeight(4); stroke(255,130,130); line(Wa-6,H-315,Wb+86,H-315); pop(); //red-line time+=1; fill(255, 255, 255); textSize(18); textAlign(CENTER); if (time<20){ textSize(15); }else { textSize(18); } if (time==40){ time=0; } text('Press A', Wa+40, H1+60); text('Press L', Wb+40, H1+60); //control if (count_a>=250 && count_b=250 && count_b>count_a){ fill(255,130,130); rect(Wa+36,H,8,-count_a); fill(68, 58, 112); rect(Wa+62, H1-70,-78,-20); rect(Wa,H-360,500,40); fill(255,130,130); textSize(18); text('Purple flower won',0.5*width,H-330); score_b++; fill(255); beginShape(); vertex(Wa-16,H1-88); vertex(Wa+62,H1-80); vertex(Wa-16,H1-72); endShape(); noLoop(); } //win push(); textSize(16); textAlign(LEFT); 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 } function keyTyped() { if (key === 'a') { count_a+=10; } if (key === 'l') { count_b+=10; } } 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); }