Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1. package com.mygdx.game;
  2.  
  3. import com.badlogic.gdx.ApplicationAdapter;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.graphics.GL20;
  6. import com.badlogic.gdx.graphics.Texture;
  7. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  8.  
  9. public class MyGdxGame extends ApplicationAdapter {
  10.     SpriteBatch batch;
  11.     Texture bottomLeft;
  12.     Texture bottomRight;
  13.     Texture topLeft;
  14.     Texture topRight;
  15.     Texture handle;
  16.     Texture rightPadding, leftPadding, topPadding, bottomPadding;
  17.     Texture centerPadding;
  18.    
  19.     @Override
  20.     public void create () {
  21.         batch = new SpriteBatch();
  22.         bottomLeft = new Texture("bottomleft.png");
  23.         bottomRight = new Texture("bottomright.png");
  24.         topLeft = new Texture("topleft.png");
  25.         topRight = new Texture("topright.png");
  26.         handle = new Texture("handle.png");
  27.         rightPadding = new Texture("rightpadding.png");
  28.         leftPadding = new Texture("leftpadding.png");
  29.         topPadding = new Texture("toppadding.png");
  30.         bottomPadding = new Texture("bottompadding.png");
  31.         centerPadding = new Texture("center.png");
  32.     }
  33.  
  34.     public void drawCabinet(SpriteBatch batch, int width, int height) {
  35.         int vertDistance = height - topRight.getHeight() - bottomRight.getHeight();
  36.         int horizDistance = width - topRight.getWidth() - topLeft.getWidth();
  37.         batch.draw(bottomLeft, 0, 0);
  38.         batch.draw(topLeft,0,bottomLeft.getHeight() + vertDistance);
  39.         batch.draw(bottomRight, bottomLeft.getWidth() + horizDistance, 0);
  40.         batch.draw(topRight, bottomLeft.getWidth() + horizDistance, bottomRight.getHeight() + vertDistance);
  41.         for (int spaces = vertDistance; spaces > 0; spaces--) {
  42.             batch.draw(rightPadding, bottomLeft.getWidth() + horizDistance, bottomRight.getHeight() + spaces - 1);
  43.         }
  44.         for (int spaces = vertDistance; spaces > 0; spaces--) {
  45.             batch.draw(leftPadding, 0, bottomLeft.getHeight() + spaces - 1);
  46.         }
  47.         for (int spaces = horizDistance; spaces > 0; spaces--) {
  48.             batch.draw(bottomPadding, bottomLeft.getWidth() + spaces - 1, 0);
  49.         }
  50.         for (int spaces = horizDistance; spaces > 0; spaces--) {
  51.             batch.draw(topPadding, topLeft.getWidth() + spaces - 1, bottomLeft.getHeight() + vertDistance + topLeft.getHeight() - topPadding.getHeight());
  52.         }
  53.         batch.draw(centerPadding, bottomLeft.getWidth(), bottomPadding.getHeight(), horizDistance, height - topPadding.getHeight() - bottomPadding.getHeight());
  54.         batch.draw(handle, bottomLeft.getWidth() + horizDistance + bottomRight.getWidth() - handle.getWidth(), (bottomRight.getHeight() + vertDistance + topRight.getHeight()) / 2 - handle.getHeight() / 2);
  55.     }
  56.  
  57.     @Override
  58.     public void render () {
  59.         Gdx.gl.glClearColor(1, 0, 0, 1);
  60.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  61.         batch.begin();
  62.         drawCabinet(batch, 80, 100);
  63.         batch.end();
  64.     }
  65.    
  66.     @Override
  67.     public void dispose () {
  68.         batch.dispose();
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement