//microdev.gr //(C) Panos Papazoglou //January 2023 int cx=width/2; int cy=width/2; int cw=30; int dx=8, dy=8; int ymin=0, xmin=0; int xmax,ymax; int pax=0, pay=0, paw=20, pah=200; int pbx, pby=0, pbw=20, pbh=200; int left=0, right=0; boolean a=false,z=false,up=false,s=false, down=false; void setup() { size(1200, 1000); ymax=height; xmax=width; pbx=xmax-pbw; surface.setTitle("A Pong game like 1972 - microdev.gr"); } void draw() { background(0); print_score(); if (s==false) { textSize(50); fill(0,128,0); text("Press 1 to start..., 2 to exit",(width/2)-300, height/2); fill(128,128,0); textSize(25); text("Panos Papazoglou-Microdev.gr",(width/2)-250, height-20); } else { stroke(0,0,128); line(width/2,0,width/2,height); cx+=dx; cy+=dy; if ((cx>xmax) || (cx<0)) dx=-dx; if ((cy>ymax) || (cy<0)) dy=-dy; fill(255,0,0); circle(cx,cy,cw); draw_r(); if ((a==true) && (pay>10)) pay=pay-10; if ((z==true) && (pay10)) pby=pby-10; if ((down==true) && (pby=pay) && (cy<=pay+pah)) dx=-dx; else if ((cx>xmax-pbw) && (cy>=pby) && (cy<=pby+pbh)) dx=-dx; else if (cx<0) {right=right+1; s=false;} else if (cx>xmax) {left=left+1; s=false;} } } void draw_r() { fill(0,128,0); rect(pax,pay,paw,pah); fill(128,50,128); rect(pbx,pby,pbw,pbh); } void print_score() { textSize(100);fill(255); text(str(left),(width/2)-100, 100); text(str(right),(width/2)+100, 100); } void keyPressed() { if (key=='a') a=true; if (key=='z') z=true; if (keyCode==UP) up=true; if (keyCode==DOWN) down=true; if (key=='1') s=true; if (key=='2') exit(); } void keyReleased() { if (key=='a') a=false; if (key=='z') z=false; if (keyCode==UP) up=false; if (keyCode==DOWN) down=false; }