SHARE
TWEET

Untitled

a guest Sep 13th, 2014 163 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.aftersomemath.Screens;
  2.  
  3. import World.ObjectManager;
  4. import World.Renderer;
  5.  
  6. import com.badlogic.gdx.Screen;
  7. import com.badlogic.gdx.graphics.OrthographicCamera;
  8. import com.badlogic.gdx.math.Vector2;
  9. import com.badlogic.gdx.physics.box2d.Body;
  10. import com.badlogic.gdx.physics.box2d.BodyDef;
  11. import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
  12. import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
  13. import com.badlogic.gdx.physics.box2d.CircleShape;
  14. import com.badlogic.gdx.physics.box2d.Fixture;
  15. import com.badlogic.gdx.physics.box2d.FixtureDef;
  16. import com.badlogic.gdx.physics.box2d.PolygonShape;
  17. import com.badlogic.gdx.physics.box2d.World;
  18.  
  19. public class TestBox2d implements Screen {
  20.         private ObjectManager objects;
  21.         private Renderer renderer;
  22.         private float runTime;
  23.        
  24.         private World world = new World(new Vector2(0, -10), true);
  25.         private Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();
  26.         private OrthographicCamera camera;
  27.  
  28.        
  29.         public TestBox2d() {
  30.                 camera = new OrthographicCamera();
  31.                 camera.setToOrtho(true, 20.0f, 20.0f);         
  32.                
  33.                 // First we create a body definition
  34.                 BodyDef bodyDef = new BodyDef();
  35.                 // We set our body to dynamic, for something like ground which doesn't move we would set it to StaticBody
  36.                 bodyDef.type = BodyType.DynamicBody;
  37.                 // Set our body's starting position in the world
  38.                 bodyDef.position.set(10, 15);
  39.  
  40.                 // Create our body in the world using our body definition
  41.                 Body body = world.createBody(bodyDef);
  42.  
  43.                 // Create a circle shape and set its radius to 6
  44.                 CircleShape circle = new CircleShape();
  45.                 circle.setRadius(6f);
  46.  
  47.                 // Create a fixture definition to apply our shape to
  48.                 FixtureDef fixtureDef = new FixtureDef();
  49.                 fixtureDef.shape = circle;
  50.                 fixtureDef.density = 0.5f;
  51.                 fixtureDef.friction = 0.4f;
  52.                 fixtureDef.restitution = 0.6f; // Make it bounce a little bit
  53.  
  54.                 // Create our fixture and attach it to the body
  55.                 Fixture fixture = body.createFixture(fixtureDef);
  56.  
  57.                 // Remember to dispose of any shapes after you're done with them!
  58.                 // BodyDef and FixtureDef don't need disposing, but shapes do.
  59.                 circle.dispose();
  60.                
  61.                 // Create our body definition
  62.                 BodyDef groundBodyDef =new BodyDef();  
  63.                 // Set its world position
  64.                 groundBodyDef.position.set(new Vector2(0, 10));  
  65.  
  66.                 // Create a body from the defintion and add it to the world
  67.                 Body groundBody = world.createBody(groundBodyDef);  
  68.  
  69.                 // Create a polygon shape
  70.                 PolygonShape groundBox = new PolygonShape();  
  71.                 // Set the polygon shape as a box which is twice the size of our view port and 20 high
  72.                 // (setAsBox takes half-width and half-height as arguments)
  73.                 groundBox.setAsBox(camera.viewportWidth, 10.0f);
  74.                 // Create a fixture from our polygon shape and add it to our ground body  
  75.                 groundBody.createFixture(groundBox, 0.0f);
  76.                 // Clean up after ourselves
  77.                 groundBox.dispose();
  78.                
  79.         }
  80.        
  81.         public void show() {
  82.  
  83.         }
  84.  
  85.         @Override
  86.         public void render(float delta) {
  87.                 debugRenderer.render(world, camera.combined);
  88.                 world.step(1/10f, 6, 2);
  89.         }
  90.  
  91.         @Override
  92.         public void resize(int width, int height) {
  93.  
  94.         }
  95.  
  96.         @Override
  97.         public void hide() {
  98.                 // TODO Auto-generated method stub
  99.  
  100.         }
  101.  
  102.         @Override
  103.         public void pause() {
  104.                 // TODO Auto-generated method stub
  105.  
  106.         }
  107.        
  108.         @Override
  109.         public void resume() {
  110.                 // TODO Auto-generated method stub
  111.  
  112.         }
  113.  
  114.         @Override
  115.         public void dispose() {
  116.                 // TODO Auto-generated method stub
  117.  
  118.         }
  119.        
  120. }
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