Modify a text file: $/scottButtons.pde
$/scottButtons.pde
// coding using objects test // Scott McCoskery // CST 112 Button start, stop, shoot, left, right; Button quit; Button[] b= new Button[6]; int numbuttons= b.length; float zoogX=100, zoogY=100, zoogDX=0, zoogDY=0; void setup() { size(800, 600); start = new Button("START", 10, 10, 100, 255, 100, false); stop = new Button("STOP", 690, 10, 255, 100, 100, false); shoot = new Button("SHOOT", 350, 530, 190, 120, 30, false); left = new Button("LEFT", 150, 530, 230, 230, 255, false); right = new Button("RIGHT", 550, 530, 230, 230, 255, false); quit = new Button("QUIT", 550, 400, 230, 130, 50, false); // b[0]= start; b[1]= stop; b[2]= shoot; b[3]= left; b[4]= right; b[5]= quit; } void draw() { background(50,50,100); /* start.update(); stop.update(); shoot.update(); left.update(); right.update(); // */ for (int j=0; j
width) zoogDX= -zoogDX; zoogY += zoogDY; ellipse( zoogX, zoogY, 60, 30 ); } void mousePressed() { if (start.clicked()) { zoogDX= 2; zoogDY= 1; } if (stop.clicked()) { zoogDX= 0; zoogDY= 0; } if (shoot.clicked()) { zoogDX= -2; zoogDY= -1; } if (left.clicked()) { zoogX= 0; zoogDX= 2; } if (right.clicked()) { zoogX= width; zoogDX= -2; } if (quit.clicked()) { exit(); } } class Button { float x, y; float w = 100, h = 60; String s; boolean clicked; int r, g, b; int grow=0, glow=0; //CONSTRUCTORS Button(String s, float x, float y, int r, int g, int b, boolean clicked) { this.x = x; this.y = y; this.s = s; this.r = r; this.g = g; this.b = b; this.clicked = clicked; } void update() { //-- check(); // Hover. grow=0; glow=0; if ( over(mouseX, mouseY) ) { grow=20; glow=100; } show(); } void show() { strokeWeight(3); fill(r, g, b+glow); rect(x-grow/2, y-grow/2, w+grow, h+grow, 50); fill(0); textSize(18); text(s, x+20, y+35); } // Return tru if xx,yy is over. boolean over( float xx, float yy) { return xx >= x && xx <= x+100 && yy >= y && yy <= y+60; } boolean clicked() { //-- if (mousePressed && clicked == false && mouseX >= x && mouseX <= x+100 //-- && mouseY >= y && mouseY <= y+60) if (mousePressed && over(mouseX, mouseY)) //-- && mouseX >= x && mouseX <= x+100 //-- && mouseY >= y && mouseY <= y+60) { return true; } else { return false; } } }