iMackshun

Original Without Error

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