Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RectangleBlock extends BlockCommon {
- protected PolygonShape shape;
- @Override
- public void create(float blockPosX, float blockPosY, float blockSizeX, float blockSizeY, float angle) {
- super.create(blockPosX,blockPosY,blockSizeX,blockSizeY,angle);
- entity_subType = BlockFactory.SHAPE_RECTANGLE;
- body = GameScreen.getInstance().getWorld().createBody(bodyDef);
- body.setTransform(this.getX() + this.getWidth() / 2, this.getY() + this.getHeight() / 2, (float) Math.toRadians(this.getRotation()));
- body.setUserData(this);
- PolygonShape shape = new PolygonShape();
- shape.setAsBox(this.getWidth() / 2, this.getHeight() / 2);
- fixtureDef.shape = shape;
- body.createFixture(fixtureDef);
- shape.dispose();
- for (int x = 0; x < blockSizeX; x++) {
- for (int y = 0; y < blockSizeY; y++) {
- Image blockTexture = new Image();
- blockTexture.setSize(GameScreen.BLOC_SIZE, GameScreen.BLOC_SIZE);
- blockTexture.setPosition(x*GameScreen.BLOC_SIZE, y*GameScreen.BLOC_SIZE);
- blockTexture.setOrigin(GameScreen.BLOC_SIZE/2,GameScreen.BLOC_SIZE/2);
- if (blockSizeX == 1 && blockSizeY == 1) {
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_square)));
- }
- else if(blockSizeY == 1 && x==0){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_end)));
- }
- else if(blockSizeY == 1 && x==blockSizeX-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_end)));
- blockTexture.rotateBy(180);
- }
- else if(blockSizeY == 1 && x<blockSizeX-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_tube)));
- }
- else if(blockSizeX == 1 && y==0){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_end)));
- blockTexture.rotateBy(90);
- }
- else if(blockSizeX == 1 && y==blockSizeY-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_end)));
- blockTexture.rotateBy(-90);
- }
- else if(blockSizeX == 1 && y<blockSizeY-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_tube)));
- blockTexture.rotateBy(90);
- }
- else if(x==0 && y==0){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_angle)));
- blockTexture.rotateBy(90);
- }
- else if(x==blockSizeX-1 && y==0){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_angle)));
- blockTexture.rotateBy(180);
- }
- else if(x==0 && y==blockSizeY-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_angle)));
- // blockTexture.rotateBy(-90);
- }
- else if(x==blockSizeX-1 && y==blockSizeY-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_angle)));
- blockTexture.rotateBy(-90);
- }
- else if(y==0 && x > 0 && x < blockSizeX-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_edge)));
- blockTexture.rotateBy(-180);
- }
- else if(y==blockSizeY-1 && x > 0 && x < blockSizeX-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_edge)));
- // blockTexture.rotateBy(-180);
- }
- else if(x==0 && y > 0 && y < blockSizeY-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_edge)));
- blockTexture.rotateBy(90);
- }
- else if(x==blockSizeX-1 && y > 0 && y < blockSizeY-1){
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_edge)));
- blockTexture.rotateBy(-90);
- }
- else{
- blockTexture.setDrawable(new TextureRegionDrawable(Assets.getInstance().getTexture(Assets.TEXTURE_block_square_empty)));
- }
- this.addActor(blockTexture);
- }
- }
- }
- @Override
- public void act(float delta) {
- super.act(delta);
- Vector2 v = this.localToStageCoordinates(new Vector2(this.getWidth() / 2, this.getHeight() / 2));
- //body.setTransform(this.getX()+this.getWidth()/2,this.getY()+this.getHeight()/2,(float)Math.toRadians(this.getRotation()));
- if(this.hasParent()) {
- body.setTransform(v.x, v.y, (float) Math.toRadians(this.getParent().getRotation() + this.getRotation()));
- }
- else{
- body.setTransform(this.getX() +this.getWidth()/2, this.getY()+this.getHeight()/2, (float) Math.toRadians(this.getRotation()));
- }
- }
- @Override
- public void addActor (Actor actor) {
- super.addActor(actor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement