Ejemplo n.º 1
0
  void turnOnFadeLog() throws IOException {
    Global.log("Connecting to fade log...");
    while (true) {
      if (isDisposed()) throw new IOException("Client game disposed");
      Global.log("Connecting to port " + Global.fadeLogPort() + "...");
      try {
        fadeLog = new ClientByteStream(ip, Global.fadeLogPort(), 12);
        break;
      } catch (IOException ex) {
      }
    }
    Global.log("Connected!");
    timers.add(
        new FixedTimer(
            new FixedTask() {
              public boolean fixedRate() {
                return false;
              }

              public float FPS() {
                return Global.ReceiveFPS;
              }

              public void run() {
                String s = null;
                byte[] data = null;
                try {
                  data = fadeLog.read();
                  if (data == null) return;
                  s = fadeLog.readLine();
                } catch (IOException ex) {
                  System.err.println("Error reading from fade log: " + ex);
                  Global.onException();
                  stop();
                  return;
                }
                if (s == null) return;
                ByteBuffer bb = ByteBuffer.wrap(data);
                float x = bb.getFloat();
                float y = bb.getFloat();
                Color color = Global.IntToColor(bb.getInt());

                // if fade color is same as ship color, play power-up sound

                if (color.equals(getPlayerShip().fill)) Sounds.powerUp.play();

                fadeLog(s, x, y, color);
              }
            }));
  }