bethdps

Detecção

Oct 11th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. int rectX = 100;
  2. int rectY = 300;
  3. int rectSize = 200;
  4.  
  5. int bolaX = 600;
  6. int bolaY = 400;
  7. int bolaSize = 200;
  8.  
  9. void setup(){
  10.   size(800,800);
  11.  
  12. }
  13.  
  14. void draw() {
  15.   if (collisionRect()){
  16.     fill(255);
  17.     println("Estou no quadrado");
  18.   }else{
  19.     fill(0);
  20.    
  21.   }
  22.   rect(rectX,rectY,rectSize,rectSize);
  23.  
  24.   if(collisionCircle()){
  25.     fill(0);
  26.     println("Estou no círculo");
  27.   }else{
  28.     fill(255);
  29.   }
  30.   ellipse(bolaX,bolaY,bolaSize,bolaSize);  
  31. }
  32.  
  33. boolean collisionRect(){
  34.   if(((mouseX >= rectX) && (mouseX <= rectX + rectSize) && ((mouseY >= rectY) && (mouseY <= rectY + rectSize)))){
  35.     return true;
  36.   }
  37.   return false;
  38. }
  39.  
  40. boolean collisionCircle(){
  41.   if(dist2D(mouseX,mouseY,bolaX,bolaY) <= bolaSize/2){
  42.     return true;
  43.   }
  44.   return false;
  45. }
  46.  
  47.  
  48. int dist2D(int p1X,int p1Y,int p2X,int p2Y){
  49.   return round(sqrt( pow( abs(p1X - p2X) , 2 ) + pow( abs(p1Y - p2Y) , 2 ) ) );
  50. }
Add Comment
Please, Sign In to add comment