/** Update or add a sprite to the client side game. */
  public void addPacket(HacktendoPacket Packet) {
    while (!getInitialized()) { // Make sure things have loaded before we start mucking with stuff.
      try {
        Thread.sleep(5);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    do {
      Sprite S = (Sprite) Sprites.get(new Integer(Packet.getID()));
      boolean setRenderType = false;
      if (S == null) {
        S = new Sprite(this);
        setRenderType = true;
        S.setParameter("destroy", new TypeBoolean(false));
        S.setParameter("globalID", new TypeInteger(Packet.getID()));
        S.setParameter("id", new TypeInteger(Packet.getID()));
        Sprites.put(new Integer(Packet.getID()), S);
        S.setOffscreenProcessing(false);
      }
      S.setScriptID(Packet.getScriptID());
      S.setImageID(Packet.getImage());

      if (S.getSpriteID() != playerID || setRenderType) { // Allow the sprite to move client side.
        S.setX(Packet.getX());
        S.setY(Packet.getY());
        S.setZ(Packet.getZ());
        S.setParameter("xTarget", new TypeInteger(Packet.getTargetX()));
        S.setParameter("yTarget", new TypeInteger(Packet.getTargetY()));
        S.setParameter("newTarget", new TypeBoolean(true));
      }

      if (Packet.getExplodeSprite()) S.explode();
      if (Packet.getDestroySprite()) S.setParameter("destroy", new TypeBoolean(true));
      S.setFrame(Packet.getFrame());
      S.setXRotation(Packet.getXRotation());
      S.setYRotation(Packet.getYRotation());
      S.setZRotation(Packet.getZRotation());

      S.setWidth(Packet.getWidth());
      S.setHeight(Packet.getHeight());
      S.setDepth(Packet.getDepth());
      S.setZOffset(Packet.getZOffset() * -1);

      if (setRenderType) S.setRenderType(Packet.getRenderType());

    } while (Packet.next() > 0);

    // Takes the form Object[]{ID,IP,Name,NPC,BODY_ID}
    if (Packet.getReferenceArray() != null) {
      for (int i = 0; i < Packet.getReferenceArray().size(); i++) {
        Object O[] = (Object[]) Packet.getReferenceArray().get(i);
        Sprite S = (Sprite) Sprites.get((Integer) O[0]);

        System.out.println("ID: " + O[0]);
        if (S != null) {
          String ip = (String) O[1];
          String name = (String) O[2];
          boolean npc = (Boolean) O[3];

          S.setParameter("ip", new TypeString(ip));
          S.setParameter("name", new TypeString(name));
          S.setParameter("npc", new TypeBoolean(npc));

          if (S.getScriptID() == SPRITE_SCRIPT) {
            S.setOffscreenProcessing(true);
            S.setAutoCollide(true);
            Sprite S2 = (Sprite) Sprites.get((Integer) O[4]);
            S.setParameter("body", new TypeInteger(S2.getSpriteID()));
          }

          if (ip.equals(MyHacker.getIP())) {
            if (S.getScriptID() == SPRITE_SCRIPT) {
              playerSprite = S;
            }
            playerID = S.getSpriteID();
            System.out.println(
                "We are setting the player to equal : "
                    + S.getSpriteID()
                    + " This Is Sprite ID: "
                    + O[0]);
            HacktendoLinker.addGlobal("player", new TypeInteger(S.getSpriteID()));
          }
        }
      }
    }
  }
Example #2
0
  public void display(GLAutoDrawable gLDrawable) {
    key = Input.keysPressed();

    double dt = (System.currentTimeMillis() - dt_timer) / 1000.0;
    dt_timer = System.currentTimeMillis();

    // Start 3d Rendering
    GL gl = gLDrawable.getGL();

    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    gl.glLoadIdentity();

    GLU glu = new GLU();

    // Code to adjust camera
    if (input.getKey(KeyEvent.VK_UP)) z -= .5 * dt;
    if (input.getKey(KeyEvent.VK_DOWN)) z += .5 * dt;

    if (input.getKey(KeyEvent.VK_LEFT)) y -= .5 * dt;
    if (input.getKey(KeyEvent.VK_RIGHT)) y += .5 * dt;
    if (input.getKey(KeyEvent.VK_SPACE)) System.out.println(y + " " + z);

    glu.gluLookAt(0, y, z, 0, 0, -3, 0, 1, 0);

    // orangeNote.drawBar(gLDrawable, zTest);
    // redNote.draw(gLDrawable, -3f, -4f, zTest);
    // yellowNote.draw(gLDrawable, -1.5f, -4f, zTest);
    // blueNote.draw(gLDrawable, 0f, -4f, zTest);
    // greenNote.draw(gLDrawable, 1.5f, -4f, zTest);
    zTest += 0.005f;
    if (zTest > -2f) zTest = -10f;

    gl.glPushMatrix();
    gl.glEnable(GL.GL_BLEND);
    // gl.glRotatef(70,1,-2,1);

    gl.glBegin(GL.GL_QUADS);
    // Draw the Board
    // x goes basically from -1 to 1(camera changed tho)
    // y stays same
    // board length is -z
    gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f); // R,G,B,A
    gl.glVertex3f(-3f, -4f, 0f); // x,y,z

    gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f);
    gl.glVertex3f(3f, -4f, 0f);

    gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f);
    gl.glVertex3f(3f, -4f, -10f);

    gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f);
    gl.glVertex3f(-3f, -4f, -10f);

    // All y values on top of the Board must have at least
    // 0.0001f added for some reason
    // Bottom bar - Orange
    gl.glColor4f(255 / 256f, 165 / 256f, 0 / 256f, 1f);
    gl.glVertex3f(-3f, -4f + .0001f, -2.15f); // close left
    gl.glVertex3f(3f, -4f + .0001f, -2.15f); // close right
    gl.glVertex3f(3f, -4f + .0001f, -2.85f); // far right
    gl.glVertex3f(-3f, -4f + .0001f, -2.85f); // far left
    // RedNote
    gl.glColor4f(1f, 0f, 0f, 1f);
    gl.glVertex3f(-3f, -4f + .001f, -2.25f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.75f);
    gl.glVertex3f(-3f, -4f + .001f, -2.75f);
    // YellowNote
    gl.glColor4f(1f, 1f, 0f, 1f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(0f, -4f + .001f, -2.25f);
    gl.glVertex3f(0f, -4f + .001f, -2.75f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.75f);
    // BlueNote
    gl.glColor4f(0f, 0f, 1f, 1f);
    gl.glVertex3f(0f, -4f + .001f, -2.25f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.75f);
    gl.glVertex3f(0f, -4f + .001f, -2.75f);
    // GreenNote
    gl.glColor4f(0f, 1f, 0f, 1f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(3f, -4f + .001f, -2.25f);
    gl.glVertex3f(3f, -4f + .001f, -2.75f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.75f);
    // End Bottom Bar

    this.renderNotes(gLDrawable, dt);

    /////////////////////////////////////
    gl.glEnd();

    gl.glDisable(GL.GL_BLEND);
    gl.glPopMatrix();

    try {
      Thread.sleep(1);
    } catch (Exception e) {
    }
  }