Advertisement
iMackshun

NullPointerException???

Oct 29th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.28 KB | None | 0 0
  1. package com.iMackshun.Games.PixelFormer.Screens;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.Screen;
  5. import com.badlogic.gdx.graphics.GL10;
  6. import com.badlogic.gdx.graphics.OrthographicCamera;
  7. import com.badlogic.gdx.math.Vector2;
  8. import com.badlogic.gdx.physics.box2d.Body;
  9. import com.badlogic.gdx.physics.box2d.BodyDef;
  10. import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
  11. import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
  12. import com.badlogic.gdx.physics.box2d.ChainShape;
  13. import com.badlogic.gdx.physics.box2d.Fixture;
  14. import com.badlogic.gdx.physics.box2d.FixtureDef;
  15. import com.badlogic.gdx.physics.box2d.PolygonShape;
  16. import com.badlogic.gdx.physics.box2d.World;
  17. import com.iMackshun.Games.PixelFormer.Objects.InputController;
  18. import com.iMackshun.Games.PixelFormer.Objects.Player;
  19.  
  20. public class Level1 implements Screen {
  21.     // Class Declaraction
  22.     private World world  = new World(new Vector2(0, -9.8f), true);;
  23.     static final float WORLD_TO_BOX = 0.01f;
  24.     static final float BOX_TO_WORLD = 100f;
  25.     private Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();
  26.     private OrthographicCamera camera = new OrthographicCamera();
  27.     private Body PlayerBody, GroundBody, BoxBody;
  28.     private int Speed = 10;
  29.     private Vector2 MovementVelocity;
  30.     private BodyDef bodyDef = new BodyDef();
  31.     private FixtureDef fixtureDef = new FixtureDef();
  32.     private Player player = new Player(world, fixtureDef, -50, 1, 2, 2);
  33.  
  34.     @Override
  35.     public void render(float delta) {
  36.         Gdx.gl.glClearColor(0, 0, 0, 1);
  37.         Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  38.         player.update();
  39.         world.step(1 / 45f, 6, 2);
  40.         camera.update();
  41.         debugRenderer.render(world, camera.combined);
  42.     }
  43.  
  44.     @Override
  45.     public void resize(int width, int height) {
  46.         camera.viewportWidth = width/10;
  47.         camera.viewportHeight = height/10;
  48.         camera.update();
  49.     }
  50.  
  51.     @Override
  52.     public void show() {
  53.         Gdx.input.setInputProcessor(player);
  54.         //Box of Reference
  55.         // Create the Body
  56.         PolygonShape CrateShape = new PolygonShape();
  57.         CrateShape.setAsBox(2, 2);
  58.         //Body Definition and Creation
  59.         bodyDef.type = BodyType.DynamicBody;
  60.         bodyDef.position.set(-6, 3);
  61.         BoxBody = world.createBody(bodyDef);
  62.         //FixtureDefinition and Binding Shape to Body
  63.         fixtureDef.shape = CrateShape;
  64.         fixtureDef.restitution = 0.05f;
  65.         fixtureDef.density = 1.0f;
  66.         fixtureDef.friction = 0.6f;
  67.         Fixture BoxFixture = BoxBody.createFixture(fixtureDef);
  68.         //Disposal
  69.         CrateShape.dispose();
  70.        
  71.         // Ground!
  72.         bodyDef.type = BodyType.StaticBody;
  73.         bodyDef.position.set(0, -30);
  74.         // Shape
  75.         ChainShape groundshape = new ChainShape();
  76.         groundshape.createChain(new Vector2[] { new Vector2(-500, 0),
  77.                 new Vector2(500, 0) });
  78.         // Fixture Definition
  79.         fixtureDef.shape = groundshape;
  80.         fixtureDef.friction = 1f;
  81.         fixtureDef.restitution = 0;
  82.         world.createBody(bodyDef).createFixture(fixtureDef);
  83.  
  84.         groundshape.dispose();
  85.        
  86.         //Input
  87.                 Gdx.input.setInputProcessor(new InputController() {
  88.                    
  89.                 });
  90.     }
  91.  
  92.     @Override
  93.     public void hide() {
  94.         // TODO Auto-generated method stub
  95.  
  96.     }
  97.  
  98.     @Override
  99.     public void pause() {
  100.         // TODO Auto-generated method stub
  101.  
  102.     }
  103.  
  104.     @Override
  105.     public void resume() {
  106.         // TODO Auto-generated method stub
  107.  
  108.     }
  109.  
  110.     @Override
  111.     public void dispose() {
  112.         // TODO Auto-generated method stub
  113.  
  114.     }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement