Example #1
0
    public MyLayer() {
      WYSize s = Director.getInstance().getWindowSize();
      Chipmunk chipmunk = Chipmunk.make();
      chipmunk.setDebugDraw(true);
      chipmunk.setPosition(s.width / 2, s.height / 2);
      addChild(chipmunk);

      mRandom = new Random();

      Shape.resetShapeIdCounter();

      mSpace = chipmunk.getSpace();
      mSpace.setIterations(5);
      mSpace.setGravity(0, -100);
      mSpace.resizeActiveHash(40f, 999);
      mSpace.resizeStaticHash(30f, 2999);

      Body staticBody = Body.make(Float.MAX_VALUE, Float.MAX_VALUE);

      // Create vertexes for a pentagon shape.
      WYPoint[] verts = new WYPoint[5];
      for (int i = 0; i < NUM_VERTS; i++) {
        float angle = -2 * (float) Math.PI * i / (NUM_VERTS);
        verts[i] = WYPoint.make(10 * (float) cos(angle), 10 * (float) sin(angle));
      }

      // Vertexes for a triangle shape.
      WYPoint tris[] = {WYPoint.make(-15, -15), WYPoint.make(0, 10), WYPoint.make(15, -15)};

      // Create the static triangles.
      for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 6; j++) {
          float stagger = (j % 2) * 40;
          WYPoint offset = WYPoint.make(i * 80 - s.width / 2 + stagger, j * 70 - s.width / 2);
          Poly shape = Poly.make(staticBody, tris, offset);
          shape.setRestitution(1f);
          shape.setFriction(1f);
          shape.setLayerMask(Chipmunk.NOT_GRABABLE_MASK);
          mSpace.addStaticShape(shape);
        }
      }

      // Add lots of pentagons
      float moment = Chipmunk.calculateMomentForPoly(1f, verts, WYPoint.makeZero());
      for (int i = 0; i < 50; i++) {
        Body body = Body.make(1f, moment);
        float x = frand() * s.width - s.width / 2;
        body.setPosition(x, s.height / 2 * 5 / 7);
        mSpace.addBody(body);

        Poly shape = Poly.make(body, verts, WYPoint.makeZero());
        shape.setFriction(0.4f);
        mSpace.addShape(shape);
      }

      schedule(new TargetSelector(this, "update(float)", new Object[] {0f}));
    }
Example #2
0
 public void jDraw() {
   if (mHasViewport) {
     WYSize s = Director.getInstance().getWindowSize();
     GL10 gl = Director.getInstance().gl;
     gl.glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
     gl.glLineWidth(1);
     WYPoint[] vertices = {
       WYPoint.make(50, 50),
       WYPoint.make(s.width - 50, 50),
       WYPoint.make(s.width - 50, s.width - 50),
       WYPoint.make(50, s.width - 50)
     };
     Primitives.drawPoly(vertices, true);
   }
 }
  private void populateGlasses() {
    loadZwoptex();
    /** glass01 */
    this.glass01 = ZwoptexManager.makeSprite("glass01.png");
    this.glass01.setPosition(WYPoint.make(150.0f, 655.0f));
    addChild(this.glass01);
    this.glass01.setScale(0.3f);
    this.glass01.autoRelease();
    if (SharedData.getInstance().glassList.get(0).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass01.getWidth() - 25.0f, 40.0f);
      glass01.addChild(sprite);
      sprite.autoRelease();
    }

    /** glass02 */
    this.glass02 = ZwoptexManager.makeSprite("glass02.png");
    this.glass02.setPosition(WYPoint.make(this.wySize.width - 150.0f, 655.0f));
    addChild(this.glass02);
    this.glass02.setScale(0.3f);
    this.glass02.autoRelease();
    if (SharedData.getInstance().glassList.get(1).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass02.getWidth() - 25.0f, 40.0f);
      glass02.addChild(sprite);
      sprite.autoRelease();
    }
    /** glass03 */
    this.glass03 = ZwoptexManager.makeSprite("glass03.png");
    this.glass03.setPosition(WYPoint.make(150.0f, 530));
    addChild(this.glass03);
    this.glass03.setScale(0.3f);
    this.glass03.autoRelease();
    if (SharedData.getInstance().glassList.get(2).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass03.getWidth() - 25.0f, 40.0f);
      glass03.addChild(sprite);
      sprite.autoRelease();
    }

    /** glass04 */
    this.glass04 = ZwoptexManager.makeSprite("glass04.png");
    this.glass04.setPosition(WYPoint.make(this.wySize.width - 150.0f, 530.0f));
    addChild(this.glass04);
    this.glass04.setScale(0.3f);
    this.glass04.autoRelease();
    if (SharedData.getInstance().glassList.get(3).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass04.getWidth() - 25.0f, 40.0f);
      glass04.addChild(sprite);
      sprite.autoRelease();
    }

    /** glass05 */
    this.glass05 = ZwoptexManager.makeSprite("glass05.png");
    this.glass05.setPosition(WYPoint.make(150.0f, 400));
    addChild(this.glass05);
    this.glass05.setScale(0.3f);
    this.glass05.autoRelease();
    if (SharedData.getInstance().glassList.get(4).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass05.getWidth() - 25.0f, 40.0f);
      glass05.addChild(sprite);
      sprite.autoRelease();
    }

    /** glass06 */
    this.glass06 = ZwoptexManager.makeSprite("glass06.png");
    this.glass06.setPosition(WYPoint.make(this.wySize.width - 150.0f, 400.0f));
    addChild(this.glass06);
    this.glass06.setScale(0.3f);
    this.glass06.autoRelease();
    if (SharedData.getInstance().glassList.get(5).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass06.getWidth() - 25.0f, 40.0f);
      glass06.addChild(sprite);
      sprite.autoRelease();
    }

    /** glass07 */
    this.glass07 = ZwoptexManager.makeSprite("glass07.png");
    this.glass07.setPosition(WYPoint.make(150.0f, 275));
    addChild(this.glass07);
    this.glass07.setScale(0.3f);
    this.glass07.autoRelease();
    if (SharedData.getInstance().glassList.get(6).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass07.getWidth() - 25.0f, 40.0f);
      glass07.addChild(sprite);
      sprite.autoRelease();
    }

    /** glass08 */
    this.glass08 = ZwoptexManager.makeSprite("glass08.png");
    this.glass08.setPosition(WYPoint.make(this.wySize.width - 150.0f, 275.0f));
    addChild(this.glass08);
    this.glass08.setScale(0.3f);
    this.glass08.autoRelease();
    if (SharedData.getInstance().glassList.get(7).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass08.getWidth() - 25.0f, 40.0f);
      glass08.addChild(sprite);
      sprite.autoRelease();
    }

    /** glass09 */
    this.glass09 = ZwoptexManager.makeSprite("glass09.png");
    this.glass09.setPosition(WYPoint.make(150.0f, 133.0f));
    addChild(this.glass09);
    this.glass09.setScale(0.3f);
    this.glass09.autoRelease();
    if (SharedData.getInstance().glassList.get(8).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass09.getWidth() - 25.0f, 40.0f);
      glass09.addChild(sprite);
      sprite.autoRelease();
    }

    /** glass10 */
    this.glass10 = ZwoptexManager.makeSprite("glass10.png");
    this.glass10.setPosition(WYPoint.make(this.wySize.width - 150.0f, 133.0f));
    addChild(this.glass10);
    this.glass10.setScale(0.3f);
    this.glass10.autoRelease();
    if (SharedData.getInstance().glassList.get(9).isLocked()) {
      Sprite sprite = Sprite.make(Texture2D.makePNG(R.drawable.lock_1));
      sprite.setScale(2.0f);
      sprite.setPosition(glass10.getWidth() - 25.0f, 40.0f);
      glass10.addChild(sprite);
      sprite.autoRelease();
    }
  }