Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1.  
  2. import com.badlogic.gdx.math.Rectangle;
  3. import com.badlogic.gdx.math.Vector2;
  4. import com.mygdx.game.MyGdxGame00;
  5.  
  6. import com.mygdx.game.strumenti.CameraTavola;
  7.  
  8. public class SpostaRettangolo {
  9.     ElemQ e;
  10.     Rectangle m,r;
  11.      CameraTavola ct;
  12.      Vector2 mouse, rettangolo;
  13.      boolean inizioSpostamento;
  14.      final int costante = 10;
  15.    
  16.     public SpostaRettangolo(CameraTavola ct,ElemQ e) {
  17.         this.e=e;
  18.         this.ct = ct;
  19.         this.init();
  20.     }
  21.    
  22.     private void init() {
  23.         m = new Rectangle();
  24.         m.width = 20;
  25.         m.height = 20;
  26.         e.posX(400);
  27.         e.posY(200);
  28.         mouse = new Vector2();
  29.         rettangolo = new Vector2();
  30.         inizioSpostamento = false;
  31.     }
  32.    
  33.     public void muovi(float corX, float corY) {
  34.         if (e.getR().overlaps(m)) {
  35.             e.setX(0);
  36.             e.setY(0);
  37.             inizioSpostamento = false;
  38.         } else {
  39.             inizioSpostamento = true;
  40.  
  41.             mouse.set(corX, corY);
  42.             rettangolo.set(e.getR().x, e.getR().y);
  43.             m.x = ct.getVettore().x;
  44.             m.y = ct.getVettore().y;
  45.  
  46.             if (inizioSpostamento) {
  47.                 this.sposta();
  48.             }else{
  49.                 e.setX(0);
  50.                 e.setY(0);
  51.             }
  52.  
  53.         }
  54.  
  55.     }
  56.    
  57.     private void sposta() {
  58.           e.setX(MyGdxGame00.getDistanzaX(mouse, rettangolo) * costante);
  59.           e.setY(MyGdxGame00.getDistanzaY(mouse, rettangolo) * costante);
  60.        
  61.  
  62.     }
  63.    
  64.    
  65.    
  66.    
  67.    
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement