示例#1
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);
   }
 }
示例#2
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}));
    }
示例#3
0
/** \if English Result of collision detection \else 碰撞检测的结果 \endif */
public class CDResult {
  /** \if English collision point count \else 碰撞点个数 \endif */
  public int pointCount = 0;

  /**
   * \if English collision points, max is two and they are in world coordinates \else 碰撞点数组,
   * 最多两个且用的是全局坐标 \endif
   */
  public WYPoint[] points = new WYPoint[] {WYPoint.makeZero(), WYPoint.makeZero()};

  /**
   * \if English normal of collision, in world coordinate. It points from first node to second node.
   * \else 碰撞方向, 以全局坐标表示. 总是从第一个节点指向第二个节点. \endif
   */
  public WYPoint normal = WYPoint.makeZero();

  /** \if English reset result object to all zero \else 重置所有数据为0 \endif */
  public void clear() {
    pointCount = 0;
    points[0].x = points[0].y = points[1].x = points[1].y = 0;
    normal.x = normal.y = 0;
  }

  /**
   * \if English Get float array of collision points
   *
   * @return float array of collision points \else 得到碰撞点的浮点数组表示形式
   * @return 碰撞点的浮点数组 \endif
   */
  public float[] getPoints() {
    if (pointCount == 1) return new float[] {points[0].x, points[0].y};
    else if (pointCount == 2)
      return new float[] {points[0].x, points[0].y, points[1].x, points[1].y};
    else return new float[0];
  }
}
示例#4
0
 /**
  * \if English Map a clip to external atlas texture
  *
  * @param fromClipIndex source clip index
  * @param tex external texture \else 映射一个分片到外部的图片集上
  * @param fromClipIndex 被映射的分片索引
  * @param tex 图片集的贴图对象 \endif
  */
 public void mapClip(int fromClipIndex, Texture2D tex) {
   mapClip(fromClipIndex, tex, WYPoint.makeZero());
 }
示例#5
0
 /** Get the global gravity vector. */
 public WYPoint getGravity() {
   WYPoint p = WYPoint.makeZero();
   nativeGetGravity(p);
   return p;
 }
示例#6
0
 /**
  * \if English get pin point
  *
  * @return global coordinate of pin point \else 得到pin point
  * @return pin point的全局坐标 \endif
  */
 public WYPoint getPinPoint() {
   WYPoint p = WYPoint.makeZero();
   nativeGetPinPoint(p);
   return p;
 }
示例#7
0
 /** \if English reset result object to all zero \else 重置所有数据为0 \endif */
 public void clear() {
   pointCount = 0;
   points[0].x = points[0].y = points[1].x = points[1].y = 0;
   normal.x = normal.y = 0;
 }
  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();
    }
  }