Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package screens;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input;
- import com.badlogic.gdx.Screen;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.math.Vector2;
- import com.badlogic.gdx.physics.box2d.*;
- import com.santivaldez.ropistgame.entities.Rope;
- /**
- * Created by SantiValdez on 10-Aug-16.
- */
- public class GamePlay implements Screen{
- private OrthographicCamera cam;
- private Box2DDebugRenderer debugRenderer;
- private World world;
- private Body playerBody;
- private Body ceilingBody;
- private Rope rope;
- @Override
- public void show() {
- world = new World(new Vector2(0, -9.81f), true);
- cam = new OrthographicCamera();
- debugRenderer = new Box2DDebugRenderer();
- rope = new Rope(world);
- BodyDef bdef = new BodyDef();
- FixtureDef fdef = new FixtureDef();
- //bodydef
- bdef.type = BodyDef.BodyType.StaticBody;
- bdef.position.set(0, 2.4f);
- //shape
- PolygonShape ceilingShape = new PolygonShape();
- ceilingShape.setAsBox(15, 0.25f);
- //fixturedef
- fdef.shape = ceilingShape;
- //create it
- ceilingBody = world.createBody(bdef);
- ceilingBody.createFixture(fdef);
- bdef.position.set(0, -10);
- world.createBody(bdef).createFixture(fdef); // TEMPORARY FLOOR
- //reuse for player
- bdef.type = BodyDef.BodyType.DynamicBody;
- bdef.position.set(-5, 1.5f);
- CircleShape playerShape = new CircleShape();
- playerShape.setRadius(0.15f); //half
- fdef.shape = playerShape;
- fdef.density = 0.1f;
- fdef.restitution = 0.5f;
- fdef.friction = 0.2f;
- playerBody = world.createBody(bdef);
- playerBody.createFixture(fdef);
- rope.create(ceilingBody, playerBody, 10);
- }
- @Override
- public void render(float delta) {
- Gdx.gl.glClearColor(0f, 0.4f, 0.7f, 1f);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- world.step(1f / 60f, 8, 3);
- cam.update();
- debugRenderer.render(world, cam.combined);
- if(Gdx.input.isKeyPressed(Input.Keys.SPACE)){
- playerBody.applyLinearImpulse(0.008f, 0.008f, 0, 0, true);
- //world.destroyBody(playerBody);
- if(!world.isLocked()) {
- rope.destroyRope();
- }
- }
- }
- @Override
- public void dispose() {
- world.dispose();
- debugRenderer.dispose();
- }
- @Override
- public void pause() {}
- @Override
- public void resize(int width, int height) {
- cam.viewportWidth = width / 100; // 1pixel >> 100m pixel ratio
- cam.viewportHeight = height / 100;
- }
- @Override
- public void resume() {}
- @Override
- public void hide() {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement