here's all my code. plz be gentle...
i know it can be cut down by 40-60% but it's my first...
Code:
import processing.serial.*;
ImageButtons button;
ImageButtonsb buttonb;
ImageButtonsl buttonl;
ImageButtonsr buttonr;
Serial port;
void setup()
{
size(500, 500);
background(0);
// FWD
PImage b = loadImage("baseF.gif");
PImage r = loadImage("rollF.gif");
int x = width/2 - b.width/2;
int y = height/2 - (b.height +100);
int w = b.width;
int h = b.height;
button = new ImageButtons(x, y, w, h, b, r);
// BWD
PImage bb = loadImage("baseB.gif");
PImage rb = loadImage("rollB.gif");
int xb = width/2 - bb.width/2;
int yb = height/2 - (bb.height - 200);
int wb = bb.width;
int hb = bb.height;
buttonb = new ImageButtonsb(xb, yb, wb, hb, bb, rb);
// LEFT
PImage bl = loadImage("baseL.gif");
PImage rl = loadImage("rollL.gif");
int xl = width/2 - (bl.width + 100);
int yl = height/2 - (bl.height - 50);
int wl = bl.width;
int hl = bl.height;
buttonl = new ImageButtonsl(xl, yl, wl, hl, bl, rl);
// RIGHT
PImage br = loadImage("baseR.gif");
PImage rr = loadImage("rollR.gif");
int xr = width/2 - (br.width - 200);
int yr = height/2 - (br.height - 50);
int wr = br.width;
int hr = br.height;
buttonr = new ImageButtonsr(xr, yr, wr, hr, br, rr);
// Serial
println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600);
}
void draw()
{
button.update();
button.display();
buttonb.update();
buttonb.display();
buttonl.update();
buttonl.display();
buttonr.update();
buttonr.display();
}
// FWD Class
class Button
{
int x, y;
int w, h;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean overRect(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
}
else {
return false;
}
}
}
// BWD Class
class Buttonb
{
int xb, yb;
int wb, hb;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean overRect(int xb, int yb, int width, int height) {
if (mouseX >= xb && mouseX <= xb+width &&
mouseY >= yb && mouseY <= yb+height) {
return true;
}
else {
return false;
}
}
}
// LEFT Class
class Buttonl
{
int xl, yl;
int wl, hl;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean overRect(int xl, int yl, int width, int height) {
if (mouseX >= xl && mouseX <= xl+width &&
mouseY >= yl && mouseY <= yl+height) {
return true;
}
else {
return false;
}
}
}
// RIGHT Class
class Buttonr
{
int xr, yr;
int wr, hr;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean overRect(int xr, int yr, int width, int height) {
if (mouseX >= xr && mouseX <= xr+width &&
mouseY >= yr && mouseY <= yr+height) {
return true;
}
else {
return false;
}
}
}
// End for FWD
class ImageButtons extends Button
{
PImage base;
PImage roll;
PImage currentimage;
ImageButtons(int ix, int iy, int iw, int ih, PImage ibase, PImage iroll)
{
x = ix;
y = iy;
w = iw;
h = ih;
base = ibase;
roll = iroll;
currentimage = base;
}
void update()
{
over();
if (over){
currentimage = roll;
port.write('F');
}
else {
currentimage = base;
port.write('f');
}
}
void over()
{
if( overRect(x, y, w, h) ) {
over = true;
}
else {
over = false;
}
}
void display()
{
image(currentimage, x, y);
}
}
// End for BWD
class ImageButtonsb extends Buttonb
{
PImage base;
PImage roll;
PImage currentimage;
ImageButtonsb(int ixb, int iyb, int iwb, int ihb, PImage ibase, PImage iroll)
{
xb = ixb;
yb = iyb;
wb = iwb;
hb = ihb;
base = ibase;
roll = iroll;
currentimage = base;
}
void update()
{
over();
if (over){
currentimage = roll;
port.write('B');
}
else {
currentimage = base;
port.write('b');
}
}
void over()
{
if( overRect(xb, yb, wb, hb) ) {
over = true;
}
else {
over = false;
}
}
void display()
{
image(currentimage, xb, yb);
}
}
// End for LEFT
class ImageButtonsl extends Buttonl
{
PImage base;
PImage roll;
PImage currentimage;
ImageButtonsl(int ixl, int iyl, int iwl, int ihl, PImage ibase, PImage iroll)
{
xl = ixl;
yl = iyl;
wl = iwl;
hl = ihl;
base = ibase;
roll = iroll;
currentimage = base;
}
void update()
{
over();
if (over){
currentimage = roll;
port.write('L');
}
else {
currentimage = base;
port.write('l');
}
}
void over()
{
if( overRect(xl, yl, wl, hl) ) {
over = true;
}
else {
over = false;
}
}
void display()
{
image(currentimage, xl, yl);
}
}
// End for RIGHT
class ImageButtonsr extends Buttonr
{
PImage base;
PImage roll;
PImage currentimage;
ImageButtonsr(int ixr, int iyr, int iwr, int ihr, PImage ibase, PImage iroll)
{
xr = ixr;
yr = iyr;
wr = iwr;
hr = ihr;
base = ibase;
roll = iroll;
currentimage = base;
}
void update()
{
over();
if (over){
currentimage = roll;
port.write('R');
}
else {
currentimage = base;
port.write('r');
}
}
void over()
{
if( overRect(xr, yr, wr, hr) ) {
over = true;
}