//Adam Kochen //Project 8 //classes float buttonX = 10; float buttonS = 120; int table = 0; Ball[] koc = new Ball [5]; Button[] adam = new Button [5]; void setup() { size (800,600); koc[0]= new Ball(255,0,0); koc[0].y = 100; koc[1]= new Ball(0,255,0); koc[1].y = 200; koc[2]= new Ball(0,0,255); koc[2].y = 300; koc[3]= new Ball(0,0,0); koc[3].y = 400; koc[4]= new Ball(255,255,255); koc[4].y = 500; adam[0] = new Button(buttonX,height-40,80,40,"Red"); adam[1] = new Button(buttonX+buttonS,height-40,80,40,"Blue"); adam[2] = new Button(buttonX+buttonS*2,height-40,80,40,"Green"); adam[3] = new Button(buttonX+buttonS*3,height-40,80,40,"Table"); adam[4] = new Button(buttonX+buttonS*4,height-40,80,40,"Crash"); } void draw() { noStroke(); background(150,110,80); if(table%2==0){//table colour swap fill(0,100,0);//green } else{ fill(255,120,170);//pink } rect(50,50,700,500); moveBalls(); makeButtons(); } void makeButtons(){ for(int draw=0;draw0 && koc[b].mX<0 || koc[h].mX<0 && koc[b].mX>0){ koc[b].mX= -koc[b].mX; koc[h].mX= -koc[h].mX; } if(koc[h].mY>0 && koc[b].mY<0 || koc[h].mY<0 && koc[b].mY>0){ koc[h].mY= -koc[h].mY; koc[b].mY= -koc[b].mY; } } } } } boolean bounce( Ball h, Ball b) { //check for hit return dist( h.x,h.y, b.x,b.y) < 30; } class Ball { //Ball float x =100 , y =100; float mX =random(2,4)-.5 , mY =random(3,5)-.5; int w = 30, h = 30; float r = 0, g = 0, b = 0; //constructor Ball(int rr, int gg, int bb) { colours(rr,gg,bb); } void colours(int rr, int gg, int bb) { r=rr; g=gg; b=bb; } //methods void move() { roll(); make(); } void roll() { if (x<65 || x>width-65) mX= -mX; x += mX; if (y<65 || y>height-65) mY= -mY; y += mY; if(mY == 0 ){mY = 3;} } void make() { noStroke(); fill(r,g,b); ellipseMode(CENTER); ellipse(x,y,w,h); } void resetB() { x = 100; y = 100; } void resetH() { x = 100; y = 200; } } class Button { float x,y,w,h; String text; //-Constructor-// Button(float x, float y, float w, float h,String text){ this.x = x; this.y = y; this.text = text; this.w = w; this.h = h; } //-Methods-// void draw(){ fill(255); rect(x,y,w,h,15,15,0,0); fill(0); text(text,x+h/2,y+w/3); } boolean mouseOn(){ if(mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) { return true; } else { return false; } } }