/* Billiard Table Jenna Klima 12/12/14 For Bruce Alan Martin Sorry guys I'm full of it. Arrays and classes and boundaries for things are so difficult! >.< Well I didn't make it anything special. Hopefully I pass this project. I'm going to make study props for the final. I'll do the rest of this and the last project afterward. Hopefully both will be accepted as complete when they're finished And hopefully I pass the final. And that my overall grade is B- or higher. @BAM: Why did you change my takehome from an A- to a C+? I did better on the takehome than the midterm. My midterm was a B-. */ //floats //integers int score = 0; //booleans //strings //classes class billiard { //billiard color c; float x = 0, y = 0;//-------------------position of this billiard float dx = 10, dy = 10;//---------------velocity (pixels per frame) //CONSTRUCTORS billiard ( color c0, float x0, float y0 ) { //3-arg constructor sets color & position c = c0; x = x0; y = y0; } billiard ( ) { //Default constructor must be defined if any others are defined } //METHODS void move ( ) { //move billiard by ( dx, dy ) x = x + dx; y = y + dy; //bounce off walls if ( x < 75 ) { dx = -dx; } if ( x > 525 ) { dx = -dx; } if ( y < 75 ) { dy = -dy; } if ( y > 325 ) { dy = -dy; } } void show ( ) { //draw at ( x, y ) fill ( c ); //-- text ( c, x, y + 30 ); ellipseMode ( CENTER ); ellipse ( x, y, 25, 25 );//-----------diameter is 20 } } //arrays //instantiate billiards billiard [ ] billiards = new billiard [ 3 ]; void setup ( ) { //setup background and playscreen size background ( 50 ); size ( 700, 500 ); //initialize 3 billiards billiards [ 0 ] = new billiard ( color ( 255, 0, 0 ), 100, 100 ); billiards [ 1 ] = new billiard ( color ( 0, 225, 0 ), 100, 130 ); billiards [ 2 ] = new billiard ( color ( 0, 0, 225 ), 100, 160 ); } void initializeRed ( ) { //randomize billiard positions billiards [ 0 ] .x = 100 + random ( 100 ); billiards [ 0 ] .y = 100; } void initializeGreen ( ) { billiards [ 1 ] .x = 100 + random ( 100 ); billiards [ 1 ] .y = 130; } void initializeBlue ( ) { billiards [ 2 ] .x = 100 + random ( 100 ); billiards [ 2 ] .y = 160; } void draw ( ) { //draw these things scene ( ); titleInstructions ( ); scoring ( ); buttons ( ); table ( ); boundaries ( ); billiards ( ); physics ( ); } void scene ( ) { //draw a background rectangle over the background to create corner effect noStroke ( ); fill ( 75 ); rect ( 0, 0, width, height, 100 ); } void titleInstructions ( ) { //all text is here textSize ( 20 ); fill ( 255 ); text ( "Billiard Table", width / 2 - 70, height / 15 ); fill ( 150 ); text ( "Instructions", width / 14, height / 2 + 200 ); textSize ( 12 ); text ( "Press 1 to restart red, 2 to restart green, or 3 to restart blue. The buttons do similarly.", width / 14, height / 2 + 220 ); } void scoring( ) { //scoring system is here } void buttons ( ) { //buttons system is here } void table ( ) { //the pool table is here stroke ( 25, 12, 0 );//-----------------brown rail strokeWeight ( 25 ); fill ( 100, 50, 255 );//----------------light blue table rect ( width / 6 - 25, height / 6, 500, 300, 6 );//---------table w/ rail //6 pockets for ( int j = 0; j < 6; j++ ) { fill ( 0 ); } } void boundaries ( ) { //the location constrain on the billiards is here } void billiards ( ) { //the billiards are here for ( int k = 0; k < 3; k++ ) { billiards [ k ] .show ( ); } } void physics ( ) { //how the billiards move is here for ( int j = 0; j < 3; j++ ) { billiards [ j ] .move ( ); } //check for collisions check ( billiards [ 0 ], billiards [ 1 ] ); check ( billiards [ 0 ], billiards [ 2 ] ); check ( billiards [ 1 ], billiards [ 2 ] ); } void check (billiard p, billiard q ) { //eliminate "ringing" by moving both in new direction if ( dist ( p.x, p.y, q.x, q.y ) < 20 ) { p.x += 2 * p.dx; p.y += 2 * p.dy; q.x += 2 * q.dx; q.y += 2 * q.dy; } } void mousePressed ( ) { //this is what will happen when the buttons are pressed } void keyPressed ( ) { //this is what will happen when the 1, 2, 3, & Q keys are pressed //"1" restarts red billiard if ( key == '1' ) { initializeRed ( ); } //"2" restarts green billiard if ( key == '2' ) { initializeGreen ( ); } //"3" restarts blue billiard if ( key == '3' ) { initializeBlue ( ); } //"Q" quits game if ( key == 'q' ) { exit ( ); } }