java - if object collides with the same object -


i cant figure out how make collision same object same arraylist, not in lbgdx. possible? , how do that?

how create objects:

private static list<tree> objects = new arraylist<tree>();   (int = 0; i<400 ; i++ ) {         objects.add(new tree());         } 

they spawn randomly around "player" , they're on top each other.

tree class:

public class tree { public textureregion sprite; public vector2 position; private int x, y, varx, vary; public int size; private random r; public boolean injunglex, injungley = false; public int mylevel; public rectangle objrect, objrectup; public rectangle playerrect; public boolean active = false; private int random, tolis=700; public tree() {     gamerender.medis++;     size = gamerender.tilesize*5;     position = new vector2(x, y);     r = new random();     random = r.nextint(2);     int zenkas = r.nextint(2);     if(assetloader.load){     position.y = assetloader.getint("treey"+gamerender.medis);     position.x = assetloader.getint("treex"+gamerender.medis);       }else{         position.y = getpositiony();         position.x = getposition();          while(position.y>gamerender.playery-100&&position.y<gamerender.playery+100             &&position.x>gamerender.playerx-100&&position.x<gamerender.playerx+100){         position.y = getpositiony2();         position.x = getposition2();        }     } } public int getposition() {     int x;     int zenkasx = r.nextint(2);     int renkam = r.nextint(2);     int renkam2;     if(renkam==1){renkam=r.nextint(50); renkam2=0;} else {renkam=0; renkam2=r.nextint(50);}     if(zenkasx==0){         x = gamerender.playerx+renkam+(r.nextint(tolis));     }else x = gamerender.playerx-renkam2-(r.nextint(tolis));     return x; } public int getposition2() {     int x;     int zenkasx = r.nextint(2);     int renkam = r.nextint(2);     int renkam2;     if(renkam==1){renkam=0; renkam2=+r.nextint(100);} else {renkam=r.nextint(100); renkam2=0;}     if(zenkasx==0){         x = gamerender.playerx+renkam+(r.nextint(tolis));     }else x = gamerender.playerx-renkam2-(r.nextint(tolis));     return x; } public int getpositiony() {     int x;     int zenkasx = r.nextint(2);     int renkam = r.nextint(2);     int renkam2;     if(renkam==1){renkam=r.nextint(50); renkam2=0;} else {renkam=0; renkam2=r.nextint(50);}     if(zenkasx==0){         x = gamerender.playery+renkam+(r.nextint(tolis));     }else x = gamerender.playery-renkam2-(r.nextint(tolis));     return x; } public int getpositiony2() {     int x;     int zenkasx = r.nextint(2);     int renkam = r.nextint(2);     int renkam2;     if(renkam==1){renkam=100; renkam2=+r.nextint(200);} else {renkam=r.nextint(200); renkam2=100;}     if(zenkasx==0){         x = gamerender.playery+renkam+(r.nextint(tolis/3));     }else x = gamerender.playery-renkam2-(r.nextint(tolis/3));     return x; } private textureregion getsprite() {     int medis = r.nextint(3)+1;          if(medis==1) sprite = assetloader.tree1;     else if(medis==2) sprite = assetloader.tree2;     else if(medis==3) sprite = assetloader.tree3;     return sprite; }  public void createme() {     gamerender.batch.draw(sprite, position.x, position.y, size, size);   } 

}

your question unclear

i want know there way create rectangle around tree , if rectange overlaps other tree same rectangle: something.

but best can:

you create 2 boxes tree. checking if (object.box() overlaps otherobject.box())

however, have far more detailed collision box using double[][][] , storing coordinate.

basically, put coordinates in double[][][], , check if other tree within double[][][], , if is, have collided. set 1 coordinate, , 0 air.

so example, if (double[treex][treey][treez] == 1) collision stuff here.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -