Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.badlogic.gdx.math.Rectangle;
- import com.badlogic.gdx.math.Vector2;
- import com.mygdx.game.MyGdxGame00;
- import com.mygdx.game.strumenti.CameraTavola;
- public class SpostaRettangolo {
- ElemQ e;
- Rectangle m,r;
- CameraTavola ct;
- Vector2 mouse, rettangolo;
- boolean inizioSpostamento;
- final int costante = 10;
- public SpostaRettangolo(CameraTavola ct,ElemQ e) {
- this.e=e;
- this.ct = ct;
- this.init();
- }
- private void init() {
- m = new Rectangle();
- m.width = 20;
- m.height = 20;
- e.posX(400);
- e.posY(200);
- mouse = new Vector2();
- rettangolo = new Vector2();
- inizioSpostamento = false;
- }
- public void muovi(float corX, float corY) {
- if (e.getR().overlaps(m)) {
- e.setX(0);
- e.setY(0);
- inizioSpostamento = false;
- } else {
- inizioSpostamento = true;
- mouse.set(corX, corY);
- rettangolo.set(e.getR().x, e.getR().y);
- m.x = ct.getVettore().x;
- m.y = ct.getVettore().y;
- if (inizioSpostamento) {
- this.sposta();
- }else{
- e.setX(0);
- e.setY(0);
- }
- }
- }
- private void sposta() {
- e.setX(MyGdxGame00.getDistanzaX(mouse, rettangolo) * costante);
- e.setY(MyGdxGame00.getDistanzaY(mouse, rettangolo) * costante);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement