iMackshun

Update

Oct 29th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.27 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.         player.update();
  38.         camera.update();
  39.         debugRenderer.render(world, camera.combined);
  40.     }
  41.  
  42.     @Override
  43.     public void resize(int width, int height) {
  44.         camera.viewportWidth = width/10;
  45.         camera.viewportHeight = height/10;
  46.         camera.update();
  47.     }
  48.  
  49.     @Override
  50.     public void show() {
  51.         world = new World(new Vector2(0, -9.8f), true);
  52.         debugRenderer = new Box2DDebugRenderer();
  53.         camera = new OrthographicCamera();
  54.         Gdx.input.setInputProcessor(player);
  55.         // Objects
  56.         BodyDef bodyDef = new BodyDef();
  57.         FixtureDef fixtureDef = new FixtureDef();
  58.         // Player
  59.         player = new Player(world, fixtureDef, -50, 1, 2, 2);
  60.        
  61.         //Box of Reference
  62.         // Create the Body
  63.         PolygonShape CrateShape = new PolygonShape();
  64.         CrateShape.setAsBox(2, 2);
  65.         //Body Definition and Creation
  66.         bodyDef.type = BodyType.DynamicBody;
  67.         bodyDef.position.set(-6, 3);
  68.         BoxBody = world.createBody(bodyDef);
  69.         //FixtureDefinition and Binding Shape to Body
  70.         fixtureDef.shape = CrateShape;
  71.         fixtureDef.restitution = 0.05f;
  72.         fixtureDef.density = 1.0f;
  73.         fixtureDef.friction = 0.6f;
  74.         Fixture BoxFixture = BoxBody.createFixture(fixtureDef);
  75.         //Disposal
  76.         CrateShape.dispose();
  77.        
  78.         // Ground!
  79.         bodyDef.type = BodyType.StaticBody;
  80.         bodyDef.position.set(0, -30);
  81.         // Shape
  82.         ChainShape groundshape = new ChainShape();
  83.         groundshape.createChain(new Vector2[] { new Vector2(-500, 0),
  84.                 new Vector2(500, 0) });
  85.         // Fixture Definition
  86.         fixtureDef.shape = groundshape;
  87.         fixtureDef.friction = 1f;
  88.         fixtureDef.restitution = 0;
  89.         world.createBody(bodyDef).createFixture(fixtureDef);
  90.  
  91.         groundshape.dispose();
  92.        
  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. }
Advertisement
Add Comment
Please, Sign In to add comment