SHARE
TWEET

Untitled

a guest Oct 19th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class RectangleBlock extends BlockCommon {
  2.  
  3.     protected PolygonShape shape;
  4.  
  5.     @Override
  6.     public void create(float blockPosX, float blockPosY, float blockSizeX, float blockSizeY, float angle) {
  7.         super.create(blockPosX,blockPosY,blockSizeX,blockSizeY,angle);
  8.         entity_subType = BlockFactory.SHAPE_RECTANGLE;
  9.         body = GameScreen.getInstance().getWorld().createBody(bodyDef);
  10.         body.setTransform(this.getX() + this.getWidth() / 2, this.getY() + this.getHeight() / 2, (float) Math.toRadians(this.getRotation()));
  11.         body.setUserData(this);
  12.  
  13.         PolygonShape shape = new PolygonShape();
  14.         shape.setAsBox(this.getWidth() / 2, this.getHeight() / 2);
  15.         fixtureDef.shape = shape;
  16.         body.createFixture(fixtureDef);
  17.         shape.dispose();
  18.  
  19.         for (int x = 0; x < blockSizeX; x++) {
  20.             for (int y = 0; y < blockSizeY; y++) {
  21.  
  22.                 Image blockTexture = new Image();
  23.                 blockTexture.setSize(GameScreen.BLOC_SIZE, GameScreen.BLOC_SIZE);
  24.                 blockTexture.setPosition(x*GameScreen.BLOC_SIZE, y*GameScreen.BLOC_SIZE);
  25.                 blockTexture.setOrigin(GameScreen.BLOC_SIZE/2,GameScreen.BLOC_SIZE/2);
  26.                 if (blockSizeX == 1 && blockSizeY == 1) {
  27.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_square)));
  28.                 }
  29.                 else if(blockSizeY == 1 && x==0){
  30.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_end)));
  31.                 }
  32.                 else if(blockSizeY == 1 && x==blockSizeX-1){
  33.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_end)));
  34.                     blockTexture.rotateBy(180);
  35.                 }
  36.                 else if(blockSizeY == 1 && x<blockSizeX-1){
  37.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_tube)));
  38.                 }
  39.                 else if(blockSizeX == 1 && y==0){
  40.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_end)));
  41.                     blockTexture.rotateBy(90);
  42.                 }
  43.                 else if(blockSizeX == 1 && y==blockSizeY-1){
  44.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_end)));
  45.                     blockTexture.rotateBy(-90);
  46.                 }
  47.                 else if(blockSizeX == 1 && y<blockSizeY-1){
  48.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_tube)));
  49.                     blockTexture.rotateBy(90);
  50.                 }
  51.                 else if(x==0  && y==0){
  52.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_angle)));
  53.                     blockTexture.rotateBy(90);
  54.  
  55.                 }
  56.                 else if(x==blockSizeX-1 && y==0){
  57.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_angle)));
  58.                     blockTexture.rotateBy(180);
  59.                 }
  60.                 else if(x==0 && y==blockSizeY-1){
  61.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_angle)));
  62.                     //    blockTexture.rotateBy(-90);
  63.                 }
  64.                 else if(x==blockSizeX-1 && y==blockSizeY-1){
  65.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_angle)));
  66.                     blockTexture.rotateBy(-90);
  67.                 }
  68.                 else if(y==0 && x > 0 && x < blockSizeX-1){
  69.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_edge)));
  70.                     blockTexture.rotateBy(-180);
  71.                 }
  72.                 else if(y==blockSizeY-1 && x > 0 && x < blockSizeX-1){
  73.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_edge)));
  74.                     //   blockTexture.rotateBy(-180);
  75.                 }
  76.                 else if(x==0 && y > 0 && y < blockSizeY-1){
  77.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_edge)));
  78.                     blockTexture.rotateBy(90);
  79.                 }
  80.                 else if(x==blockSizeX-1 && y > 0 && y < blockSizeY-1){
  81.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_edge)));
  82.                     blockTexture.rotateBy(-90);
  83.                 }
  84.                 else{
  85.                     blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_square_empty)));
  86.                 }
  87.                 this.addActor(blockTexture);
  88.             }
  89.         }
  90.     }
  91.  
  92.     @Override
  93.     public void act(float delta) {
  94.         super.act(delta);
  95.         Vector2 v = this.localToStageCoordinates(new Vector2(this.getWidth() / 2, this.getHeight() / 2));
  96.  
  97.         //body.setTransform(this.getX()+this.getWidth()/2,this.getY()+this.getHeight()/2,(float)Math.toRadians(this.getRotation()));
  98.         if(this.hasParent()) {
  99.             body.setTransform(v.x, v.y, (float) Math.toRadians(this.getParent().getRotation() + this.getRotation()));
  100.         }
  101.         else{
  102.             body.setTransform(this.getX() +this.getWidth()/2, this.getY()+this.getHeight()/2, (float) Math.toRadians(this.getRotation()));
  103.         }
  104.     }
  105.  
  106.     @Override
  107.     public void addActor (Actor actor) {
  108.       super.addActor(actor);
  109.  
  110.     }
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top