banna 
		
		YaBB Newbies
		 
		Offline 
		
		
		Posts: 6
		
		
		
		
 
	 
	
		
			
				probably easy to answer mousePressed-question  
				 Mar 16th , 2010, 7:45pm 
			 
			
				
	  
			 
		
		
			Hi, I'm making a game that is kinda similar to pool - I have the player rotate the cuestick around a ball, and they click the mouse to make the cuestick stay in place of the direction they'd like it to be. In order to go to the next level, the player presses a button("go to the next level!") and go through the whole rotating cuestick process. I'm having trouble rotating the cuestick again in the next level... I think because you have to click the button with the mouse to go to the next level which also freezes the cuestick for the next level. So the cuestick in the next level is just frozen. If someone could tell me how to rotate it again, that would be greatly appreciated! Here is my code: //x-axis of ball = float ballx //y-axis of ball = float bally //radius of ball = balld //placement of pocket = float pocketx, float pockety //radius of pocket = float pocketr int mode = 0; float ballx = 320; float bally = 380; float cuex = ballx; float cuey = bally; float balld = 15; float ballangle = 0; float ballspeedx = 8.0; float ballspeedy = 8.0; float angle; boolean rotation = true; float pocketx = 550; float pockety = 100; float pocketr = 50; int b1x = 210;   // Button 1 x-coordinate int b1y = 215;  // Button 1 y-coordinate int b1w = 220;  // Button 1 width int b1h = 50;   // Button 1 height PFont f; PFont f48; void setup() {   size(640, 480);   smooth();   ellipseMode(RADIUS);   f = loadFont("ZebrawoodStd-Fill-28.vlw");   f48 = loadFont("ZebrawoodStd-Fill-48.vlw");   textFont(f);   textAlign(CENTER); } void draw() {   background(204);   strokeCap(ROUND);   strokeWeight(2);   fill(255);      if (mode == 0) {     modeZero();    }    else if (mode == 1) {     modeOne();   }    else if (mode == 2) {     modeTwo();   }   else if (mode == 3) {     modeThree();   }   else if (mode == 4) {     modeFour();   }   else if (mode == 5) {     modeFive();   } } void mousePressed() {   if (mode == 1) {     rotation = false;    }   if (mode == 3) {     if (overButton(b1x, b1y, b1w, b1h) == true) {     mode = 4;     }   } } void keyPressed() {     if (mode == 0) {     mode = 1;   }   if (mode == 1 && rotation == false) {     mode = 2;     ballangle = angle - PI;   } } boolean overButton(int x, int y, int w, int h) {   if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {     return true;    }    else {     return false;    } } void modeZero() {   textFont(f48);   fill(0);   text("Poolio", 320, 70);   textFont(f);   text("1. move mouse left and right", 320, 140);   text("to rotate cuestick", 320, 170);   text("2. click mouse to freeze aim", 320, 230);   text("3. press the space bar to shoot", 320, 290);   fill(#A71111);   text("press any key to start playing!", 320, 350); } void modeOne() {   pushMatrix();   translate(cuex, cuey);   rotate(angle);   line(balld/2 + 13, 0, balld/2 + 200, 0);//cuestick   popMatrix();      fill(0);   ellipse(pocketx, pockety, pocketr, pocketr); //pocket      fill(255);   ellipse(ballx, bally, balld, balld); //cueball   if (rotation) {     angle = map(mouseX, 20, 620, 0, PI*3);    }      fill(0);   text("Level 1", 70, 465); } void modeTwo() {      fill(0);   ellipse(pocketx, pockety, pocketr, pocketr); //pocket   // Draw the ball   pushMatrix();   fill(255);   translate(ballx, bally);   rotate(ballangle);   ellipse(0, 0, balld, balld);   popMatrix();   // Update position and bounce off walls   ballx += cos(ballangle) * ballspeedx;   bally += sin(ballangle) * ballspeedy;   checkWalls();         if (circleIntersect(ballx, bally, balld, pocketx, pockety, pocketr) == true) {    mode = 3;   }      // Slow down   ballspeedx *= 0.99;   ballspeedy *= 0.99;      fill(0);   text("Level 1", 70, 465); } void checkWalls() {   if (ballx > width-balld) {     ballx = width-balld;     ballspeedx *= -1;   }   else if (ballx < balld) {     ballx = balld;     ballspeedx *= -1;   }   else if (bally > height-balld) {     bally = height-balld;     ballspeedy *= -1;   }   else if (bally < balld) {     bally = balld;     ballspeedy *= -1;   } } void modeThree() {   fill(0);   ellipse(pocketx, pockety, pocketr, pocketr); //pocket    // Draw the ball   pushMatrix();   translate(ballx, bally);   rotate(ballangle);   stroke(0, 0);   fill(0, 0);   ellipse(0, 0, balld, balld);   popMatrix();      if (overButton(b1x, b1y, b1w, b1h) == true) {     stroke(0);     fill(255);   }    else {     stroke(0);     fill(153);    }   rect(b1x, b1y, b1w, b1h);   textAlign(CENTER);   fill(0);   text("Go to level 2", b1x + b1w/2, b1y + 32);      fill(0);   text("Level 1", 70, 465);   stroke(0, 0);  } boolean circleIntersect(float bx, float by, float br, float px, float py, float pr) {   if (dist(bx, by, px, py) < br-10 + pr-10) {     return true;   } else {     return false;   } } void modeFour() {      stroke(0);   fill(0);   ellipse(pocketx, pockety, pocketr, pocketr); //pocket    // Draw the ball       pushMatrix();   translate(cuex, cuey);   rotate(angle);   line(balld/2 + 13, 0, balld/2 + 200, 0);//cuestick   popMatrix();      fill(255);   ellipse(ballx, bally, balld, balld); //cueball   if (rotation) {     angle = map(mouseX, 20, 620, 0, PI*3);    } } void modeFive() {   stroke(0);   fill(0);   ellipse(pocketx, pockety, pocketr, pocketr); //pocket    // Draw the ball       pushMatrix();   translate(cuex, cuey);   rotate(angle);   line(balld/2 + 13, 0, balld/2 + 200, 0);//cuestick   popMatrix();      fill(255);   ellipse(ballx, bally, balld, balld); //cueball   if (rotation) {     angle = map(mouseX, 20, 620, 0, PI*3);    } }