Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.iMackshun.Games.PixelFormer.Screens;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Screen;
- import com.badlogic.gdx.graphics.GL10;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.math.Vector2;
- import com.badlogic.gdx.physics.box2d.Body;
- import com.badlogic.gdx.physics.box2d.BodyDef;
- import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
- import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
- import com.badlogic.gdx.physics.box2d.ChainShape;
- import com.badlogic.gdx.physics.box2d.Fixture;
- import com.badlogic.gdx.physics.box2d.FixtureDef;
- import com.badlogic.gdx.physics.box2d.PolygonShape;
- import com.badlogic.gdx.physics.box2d.World;
- import com.iMackshun.Games.PixelFormer.Objects.InputController;
- import com.iMackshun.Games.PixelFormer.Objects.Player;
- public class Level1 implements Screen {
- // Class Declaraction
- private World world = new World(new Vector2(0, -9.8f), true);;
- static final float WORLD_TO_BOX = 0.01f;
- static final float BOX_TO_WORLD = 100f;
- private Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();
- private OrthographicCamera camera = new OrthographicCamera();
- private Body PlayerBody, GroundBody, BoxBody;
- private int Speed = 10;
- private Vector2 MovementVelocity;
- private BodyDef bodyDef = new BodyDef();
- private FixtureDef fixtureDef = new FixtureDef();
- private Player player = new Player(world, fixtureDef, -50, 1, 2, 2);
- @Override
- public void render(float delta) {
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- player.update();
- world.step(1 / 45f, 6, 2);
- camera.update();
- debugRenderer.render(world, camera.combined);
- }
- @Override
- public void resize(int width, int height) {
- camera.viewportWidth = width/10;
- camera.viewportHeight = height/10;
- camera.update();
- }
- @Override
- public void show() {
- Gdx.input.setInputProcessor(player);
- //Box of Reference
- // Create the Body
- PolygonShape CrateShape = new PolygonShape();
- CrateShape.setAsBox(2, 2);
- //Body Definition and Creation
- bodyDef.type = BodyType.DynamicBody;
- bodyDef.position.set(-6, 3);
- BoxBody = world.createBody(bodyDef);
- //FixtureDefinition and Binding Shape to Body
- fixtureDef.shape = CrateShape;
- fixtureDef.restitution = 0.05f;
- fixtureDef.density = 1.0f;
- fixtureDef.friction = 0.6f;
- Fixture BoxFixture = BoxBody.createFixture(fixtureDef);
- //Disposal
- CrateShape.dispose();
- // Ground!
- bodyDef.type = BodyType.StaticBody;
- bodyDef.position.set(0, -30);
- // Shape
- ChainShape groundshape = new ChainShape();
- groundshape.createChain(new Vector2[] { new Vector2(-500, 0),
- new Vector2(500, 0) });
- // Fixture Definition
- fixtureDef.shape = groundshape;
- fixtureDef.friction = 1f;
- fixtureDef.restitution = 0;
- world.createBody(bodyDef).createFixture(fixtureDef);
- groundshape.dispose();
- //Input
- Gdx.input.setInputProcessor(new InputController() {
- });
- }
- @Override
- public void hide() {
- // TODO Auto-generated method stub
- }
- @Override
- public void pause() {
- // TODO Auto-generated method stub
- }
- @Override
- public void resume() {
- // TODO Auto-generated method stub
- }
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement