Everett - Project 2

By Everett Pelayo
float x; // X-coordinate float y; // Y-coordinate float angle = PI/4; // Direction of motion float speed = 0; // Speed of motion float velocity; float direction = 1; float radius = 12; float distance = 100*100; boolean beenHit = false; int counter=1; targetBall tb1; targetBall tb2; targetBall tb3; targetBall tb4; targetBall tb5; targetBall tb6; targetBall tb7; targetBall tb8; int page = 0; PFont font; //main font void setup() { size(600, 400); smooth(); background(255); stroke(0); ellipseMode(RADIUS); font = loadFont ("CellularTall-SansBold-16.vlw"); textFont(font); x = width/2; y = height/2; tb1 = new targetBall(); tb2 = new targetBall(); tb3 = new targetBall(); tb4 = new targetBall(); tb5 = new targetBall(); tb6 = new targetBall(); tb7 = new targetBall(); tb8 = new targetBall(); tb1.assignValues(10, 380, 8, false); tb2.assignValues(50, 200, 8, false); tb3.assignValues(100, 20, 8, false); tb4.assignValues(150, 100, 8, false); tb5.assignValues(200, 75, 8, false); tb6.assignValues(450, 120, 8, false); tb7.assignValues(300, 150, 8, false); tb8.assignValues(590, 20, 8, false); } void draw() { // frameRate(60); noCursor(); background(255); if (page == 0) { fill(0); text("PRESS ENTER TO START", 210, 200); text("OBJECTION: TRY TO TURN ALL THE DOTS RED BY RUNNING OVER THEM BUT BE CAREFUL, BY GOING OVER THE SAME DOT TWICE CAN DEACTIVATE IT. USE ENTER TO CHOOSE ANGLE AND VELOCITY", 50, 50, 500, 150); } else if (page == 1) { tb1.move(); tb1.display(); tb2.move(); tb2.display(); tb3.move(); tb3.display(); tb4.move(); tb4.display(); tb5.move(); tb5.display(); tb6.move(); tb6.display(); tb7.move(); tb7.display(); tb8.move(); tb8.display(); if ((keyPressed == true) && (key == ENTER)) { pushMatrix(); translate(x, y); rotate(angle); line(0, 0, 20, 0); line(20, 0, 15, 3); line(20, 0, 15, -3); fill(0); ellipse(0, 0, radius, radius); counter = 1; distance= 100*100; speed +=1; if (speed == 100) { speed = 0; } if ((keyPressed == true) && (key == ENTER)){ velocity = speed; direction = 3; } popMatrix() ; rect(50, 380, speed*5, 3); // println(velocity); } else { if (velocity >= .5) { velocity = velocity*0.95; x += (cos(angle) * velocity); // Update x-coordinate y += (sin(angle) * velocity); // Update y-coordinate translate(x, y); // rotate(angle); // line(0, -20, 0, 20); fill(0); ellipse(0, 0, radius, radius); // angle += 0.1; speed = 0; } else { translate(x, y); rotate(angle); line(0, 0, 20, 0); line(20, 0, 15, 3); line(20, 0, 15, -3); fill(0); ellipse(0, 0, radius, radius); angle += 0.1; if (angle >= TWO_PI){ angle = 0; } } //HITTING THE RIGHT WALL if (x > (width-radius)) { if ((angle > 0) && (angle < HALF_PI)) { angle = PI-angle; } if (( angle > (HALF_PI+PI)) && (angle < TWO_PI)) { angle = PI+(TWO_PI-angle); } if ((angle==0) || (angle==TWO_PI)) { angle = PI; } } //HITTING THE LEFT WALL if (x < radius) { if ((angle > PI) && (angle < (PI+HALF_PI))){ angle = (TWO_PI)-(angle-PI); } if ((angle < PI) && (angle > HALF_PI)){ angle = PI-angle; } if (angle == PI) { angle = 0; } } //HITTING THE BOTTOM WALL if ((y > height-radius)) { if ((angle > HALF_PI) && (angle < PI)) { angle = (PI+HALF_PI) - (angle-HALF_PI); } if ((angle < HALF_PI) && (angle > 0)) { angle = TWO_PI - angle; } if (angle == HALF_PI) { angle = (PI+HALF_PI); } } //HITTING THE TOP WALL if (y < radius) { if ((angle > (PI+HALF_PI)) && (angle < TWO_PI)) { angle = HALF_PI - (angle-(PI+HALF_PI)); } if ((angle < (PI+HALF_PI)) && (angle > PI)) { angle = HALF_PI+ ((PI+HALF_PI)-angle); } if (angle == (PI+HALF_PI)) { angle = HALF_PI; } } counter +=1; } } } void keyPressed() { if (page == 0) { if ((key == ENTER) || (key == RETURN)) { page = 1; } } } class targetBall { boolean beenHit = false; float tx; float ty; float tRadius; targetBall other; targetBall() { } void assignValues(float locationX, float locationY, float rad, boolean hit) { tx = locationX; ty = locationY; tRadius = rad; beenHit = hit; } void move() { if (!beenHit) { float d = dist(x, y, tx, ty); if (d < radius) { beenHit = true; } } else if (beenHit = true){ float d = dist(x, y, tx, ty); if (d < radius) { beenHit = false; } } } void display () { if (beenHit == true) { fill(255, 0, 0); } else { fill(255); } ellipse(tx, ty, tRadius, tRadius); } }

2 Comments

  1. Posted November 26, 2008 at 4:31 pm | Permalink

    OK. So I took some time and I’ve gotten pretty good at the task. After that, it was disappointing to not see a change after all circles were flipped.

  2. Posted November 26, 2008 at 4:32 pm | Permalink

    Also, please upload the rest of the code. I can’t grade it without it.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*