# Nafis Sabir HW 4.1

This isn’t finished. I was having a really hard time trying to figure out how to get the ball/mouse location correct, among other things. I was having such a hard time locking that down, I didn’t even try to wrap my mind around the triangle ad quad. Did get them moving though. The color change for the background also has some bugs. Hours and hours…

http://www.openprocessing.org/sketch/90531

/*Nafis S Sabir
Prof. Calli Higgins
HW 4.1*/
int state = 0;
int x = 300;//rect x location
float y = random(500);//random rect y location
int speed = 2;//x-axis speed change
int bounce = 2;//y-axis speed change
int bspeed = 2;//x-axis speed change
int bbounce = 2;//y-axis speed change
int tspeed = -2;//x-axis speed change
int tbounce = -2;//y-axis speed change
int qspeed = -3;//x-axis speed change
int qbounce = -3;//y-axis speed change
int rx = 100;//ball x
int ry = 500;//ball y
int rw = 100;//ball width
int rh = 100;//ball height
int w1 = 100;//width of small square
int h1 = 100;//height of small square
//int w2 = 300;//width of small square
//int h2 = 300;//height of small square
int tx1 = 200;//traingle x1
int ty1 = 200;//triangle y1
int tx2 = 320;//triangle x2
int ty2 = 100;//triangle y2
int tx3 = 350;//triangle x3
int ty3 = 300;//triangle y3
int qx1 = 200;//quad x1
int qy1 = 231;//quad y1
int qx2 = 320;//quad x2
int qy2 = 210;//quad y2
int qx3 = 363;//quad x3
int qy3 = 350;//quad y3
int qx4 = 210;//quad x4
int qy4 = 356;//quad y4

float color1 = random(50);//random float color
boolean button = false;

void setup() {
size(600, 600);//screen size
}

void draw() {
if (!button) {
background(0);
state = 0;
}
else if (mousePressed) {//background change on mousepress isn’t working completely had issues with button and mousePress
background(0, 255, 0);
state = 1;
}
else if (state == 1) {

state = 2;
}
else if (state == 2) {
background(0, 0, 255);
}
else if (button) {
state = 3;
}
else if (state == 3) {
background(155, 255, 0);
}
else if (!button) {
state = 4;
}
else if (state == 4) {
background(138, 0, 255);
}
else if (button) {
state = 0;
}

if ((button) && (mouseX > x && mouseX y && mouseY width && mouseX height && mouseY width * .84) {//keeps square from exceeding width
speed = speed * -1;//if the square touches the right boundary it changes direction
}
else if (x height *.84) {//keeps square from touches height
bounce = bounce * -1;//if the square touches the top boundary it changes direction
}
else if (y width * .92) {
bspeed = bspeed * -1;//if the ball touches the right boundary it changes direction
}
else if (rx height *.92) {
bbounce = bbounce * -1;//if the ball touches the top boundary it changes direction
}
else if (ry width) {
tspeed = tspeed * -1;//if the triangle touches the right boundary it changes direction
}
else if (tx1 height) {
tbounce = tbounce * -1;//if the striangle touches the top boundary it changes direction
}
else if (ty2 width) {
qspeed = qspeed * -1;//if the quad touches the right boundary it changes direction
}
else if (qx1 height) {
qbounce = qbounce * -1;//if the quad touches the top boundary it changes direction
}
else if (qy2 < 0) {
qbounce = qbounce * -1;//if the quad touches the bottom boundary it changes direction
}
}

void mousePressed() {

button = !button;//changes button state to false
}

This entry was posted in Uncategorized. Bookmark the permalink.