Beispiel #1
0
  public static void createFire(Scene scene, World world, Entity fire, JSONObject components)
      throws JSONException {
    Game game = scene.getGame();
    fire.add(
        new Sprite(
            /*game.getRenderer().addTexture(new float[]{1, 1, 0, 1}, 10, 10)*/ game.textureManager
                .get("fire"),
            -1.6f));
    fire.get(Sprite.class).postDrawn = true;
    JSONObject transformation = components.getJSONObject("Transformation");
    fire.add(
        new Transformation(
            (float) transformation.getDouble("Translate-X"),
            (float) transformation.getDouble("Translate-Y"),
            (float) transformation.getDouble("Angle")));

    PolygonShape shape = new PolygonShape();
    shape.setAsBox(
        60 / 2 * PhysicsSystem.METERS_PER_PIXEL,
        20 / 2 * PhysicsSystem.METERS_PER_PIXEL,
        new Vector2(0, (20 / 2 + 2) * PhysicsSystem.METERS_PER_PIXEL),
        0);
    PhysicsBody b =
        new PhysicsBody(
            world, BodyDef.BodyType.StaticBody, fire, shape, new PhysicsBody.Properties(0, 0, 0));
    fire.add(b);

    /*PolygonShape fireShape = new PolygonShape();
    fireShape.setAsBox(24 * PhysicsSystem.METERS_PER_PIXEL, 24 * PhysicsSystem.METERS_PER_PIXEL);
    b.createSensor(fireShape);*/

    Entity emitter = new Entity();
    emitter.add(new Transformation(0, 0, -90));
    emitter.add(createFireEmitter(game.getRenderer(), 28, 70));
    scene.addEntity(emitter);

    Burner burner = new Burner(emitter);
    fire.add(burner);

    burner.source = true;
    burner.position = 0;
    burner.sourceWidth = 24 * PhysicsSystem.METERS_PER_PIXEL;
    burner.sourceHeight = 24 * PhysicsSystem.METERS_PER_PIXEL;

    // Sound sound = new Sound();
    // fire.add(sound);
    // TODO: Add sound source for fire
    // sound.addSource(scene.getGame().getActivity(), R.raw.firesound, Sound.FIRE|Sound.AMBIANCE);
  }
Beispiel #2
0
  public static void createStick(Scene scene, World world, Entity stick, JSONObject components)
      throws JSONException {
    Game game = scene.getGame();
    stick.add(
        new Sprite(
            /*game.getRenderer().addTexture(new float[]{1, 1, 0, 1}, 16, 3)*/ game.textureManager
                .get("stick"),
            -0.05f));
    stick.get(Sprite.class).postDrawn = true;
    JSONObject transformation = components.getJSONObject("Transformation");
    stick.add(
        new Transformation(
            (float) transformation.getDouble("Translate-X"),
            (float) transformation.getDouble("Translate-Y"),
            (float) transformation.getDouble("Angle")));

    PhysicsBody b =
        new PhysicsBody(
            world,
            BodyDef.BodyType.DynamicBody,
            stick,
            new PhysicsBody.Properties(0.2f, 0.2f, 0.1f));
    stick.add(b);

    /*Filter d = b.body.getFixtureList().get(0).getFilterData();
    d.groupIndex = ExplosionSystem.NON_EXPLOSIVE_GROUP;
    b.body.getFixtureList().get(0).setFilterData(d);*/

    PolygonShape fireShape = new PolygonShape();
    fireShape.setAsBox(
        4 * PhysicsSystem.METERS_PER_PIXEL,
        4 * PhysicsSystem.METERS_PER_PIXEL,
        new Vector2(10 * PhysicsSystem.METERS_PER_PIXEL, 0),
        0);
    b.createSensor(fireShape);

    Carriable c = new Carriable();
    c.position = new Vector2(156, 136);
    c.angle = -30;
    for (int i = 0; i < 8; ++i) {
      c.positions.add(new Vector2(1628 - 1500, 256));
      c.angles.add(0f);
    }
    c.positions.add(new Vector2(128, 5128 - 266));
    c.angles.add(10f);
    c.positions.add(new Vector2(128, 5128 - 266));
    c.angles.add(10f);
    c.positions.add(new Vector2(638 - 500, 488 - 266));
    c.angles.add(15f);
    c.positions.add(new Vector2(890 - 750, 474 - 266));
    c.angles.add(10f);
    c.positions.add(new Vector2(1126 - 1000, 456 - 266));
    c.angles.add(-7f);
    c.positions.add(new Vector2(1368 - 1250, 440 - 266));
    c.angles.add(-10f);
    c.positions.add(new Vector2(1368 - 1250, 440 - 266));
    c.angles.add(-20f);
    c.positions.add(new Vector2(1368 - 1250, 440 - 266));
    c.angles.add(-20f);

    c.position.x *= 24f / 143;
    c.position.y *= 48f / 274;
    c.position.x -= 12;
    c.position.y -= 24;

    float xFactor = 48f / 250;
    float yFactor = 48f / 266;

    for (int i = 0; i < 16; ++i) {
      c.positions.get(i).x *= xFactor;
      c.positions.get(i).y *= yFactor;
      c.positions.get(i).x -= 12;
      c.positions.get(i).y -= 24;
    }

    stick.add(c);

    Entity emitter = new Entity();
    emitter.add(new Transformation(0, 0, -90));
    emitter.add(createFireEmitter(game.getRenderer(), 16, 70));
    scene.addEntity(emitter);

    Burner burner = new Burner(emitter);
    stick.add(burner);

    burner.source = false;
    burner.fullLife = 6;
  }