Exemple #1
0
  public GameScreen(int level) {
    instance = this;

    levelNum = level;

    atlas = new TextureAtlas(Gdx.files.internal("textures/nerdshooter.pack"));

    font = new BitmapFont();

    if (level == -1) {
      GameScreen.useGameDebugRenderer = true;
    } else {
      GameScreen.useGameDebugRenderer = false;
    }

    controlLeft = atlas.findRegion("HUDLeft");
    controlRight = atlas.findRegion("HUDRight");
    controlUp = atlas.findRegion("HUDJump");

    world = new World(level);
    blocks = world.getBlocks(world.getLevel().getWidth(), world.getLevel().getHeight());

    button = new ShapeRenderer();
    batch = new SpriteBatch();

    left = new Rectangle();
    right = new Rectangle();

    jump = new Rectangle();
  }
Exemple #2
0
  public void render(float delta) {
    gameTicks++;

    long seconds = (long) ((gameTicks / 60D) * 10L);

    Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
    Gdx.gl.glClear(Gdx.gl.GL_COLOR_BUFFER_BIT);

    controller.update(delta);
    updateEntities(delta);
    renderer.render();

    button.begin(ShapeRenderer.ShapeType.Filled);
    {
      if (Gdx.app.getType().equals(Application.ApplicationType.Android)) {
        Gdx.gl.glEnable(Gdx.gl20.GL_BLEND);
        Gdx.gl.glBlendFunc(Gdx.gl20.GL_SRC_ALPHA, Gdx.gl20.GL_ONE_MINUS_SRC_ALPHA);

        button.setColor(0.0F, 0.5F, 0.5F, 0.5F);
        button.rect(left.x, left.y, left.width, left.height);
        button.rect(right.x, right.y, right.width, right.height);

        button.setColor(1.0F, 1.0F, 1.0F, 0.5F);
        button.rect(jump.x, jump.y, jump.width, jump.height);
      }

      world.getJaxon().inventory.renderGUI(button, width, height, buttonSize * 0.75F);
    }
    button.end();

    batch.begin();
    {
      if (Gdx.app.getType().equals(Application.ApplicationType.Android)) {
        batch.draw(controlLeft, left.x, left.y, left.width, left.height);
        batch.draw(controlRight, right.x, right.y, right.width, right.height);
        batch.draw(controlUp, jump.x, jump.y, jump.width, jump.height);
      }

      world.getJaxon().inventory.renderItems(batch, width, height, buttonSize * 0.75F);
      font.draw(
          batch,
          "Time: " + (seconds / 10D) + " ticks, FPS: " + Gdx.graphics.getFramesPerSecond(),
          0,
          height - 10);
    }
    batch.end();
  }
Exemple #3
0
  private void createGeometryAtPos(Vector2 pos) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(pos);

    Body body = world.createBody(bodyDef);
    if (spawnBoxes) {
      createBoxAtPos(body);
    } else {
      createCircleAtPos(body);
    }
  }
Exemple #4
0
  @Override
  public void render() {

    if (platform.getPosition().x > 10) {
      platform.setLinearVelocity(-PLATFORM_VELOCITY, 0);
    } else if (platform.getPosition().x < -10) {
      platform.setLinearVelocity(PLATFORM_VELOCITY, 0);
    }

    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    world.step(1 / 60f, 6, 2);
    dDebugRenderer.render(world, cam.combined);
  }
Exemple #5
0
 public void updateEntities(float delta) {
   for (Entity e : world.getEntities()) {
     e.update(delta);
   }
 }
Exemple #6
0
  @Override
  public void create() {
    cam = new OrthographicCamera(48, 32);
    cam.position.set(0, 15, 0);
    cam.update();

    Box2D.init();
    world = new World(new Vector2(0, -9.8f), true);
    dDebugRenderer = new Box2DDebugRenderer();

    spawnBoxes = false;
    // GROUND
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    bodyDef.position.set(0, 0);

    ground = world.createBody(bodyDef);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(15, 1);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = 0f;

    ground.createFixture(fixtureDef);

    // CIRCLE
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(0, 10);

    circle = world.createBody(bodyDef);

    CircleShape circleShape = new CircleShape();
    circleShape.setRadius(1);

    fixtureDef.shape = circleShape;
    fixtureDef.density = 10;
    fixtureDef.restitution = 1;

    circle.createFixture(fixtureDef);

    // BOX
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(0, 15);

    box = world.createBody(bodyDef);

    bodyDef.bullet = false;
    shape.setAsBox(1, 1);

    fixtureDef.friction = 100f;
    fixtureDef.restitution = 0.5f;
    fixtureDef.shape = shape;
    fixtureDef.density = 2;

    box.createFixture(fixtureDef);

    // PLATFORM
    bodyDef.type = BodyDef.BodyType.KinematicBody;
    bodyDef.position.set(-10, 6);

    platform = world.createBody(bodyDef);

    shape.setAsBox(3, .5f);

    fixtureDef.shape = shape;
    fixtureDef.density = 0;
    fixtureDef.friction = 7;
    fixtureDef.restitution = 0;

    platform.createFixture(fixtureDef);

    Gdx.input.setInputProcessor(new MyInputProcessor());

    platform.setLinearVelocity(PLATFORM_VELOCITY, 0);
  }