Exemplo n.º 1
0
  /**
   * 定義を設定します。
   *
   * @param descript 定義
   */
  public void setDescript(String descript) {
    this.descript = descript;
    try {
      BufferedReader r = new BufferedReader(new StringReader(descript));
      while (true) {
        String line = r.readLine();
        if (line == null) break;

        if (line.length() == 0) continue;

        String[] split = line.split(",");
        String id = split[0];
        if (id.startsWith("collision")) {
          int x = Integer.parseInt(split[1]);
          int y = Integer.parseInt(split[2]);
          int w = Integer.parseInt(split[3]);
          int h = Integer.parseInt(split[4]);
          String name = split[5];
          SerikoCollision collision = new SerikoCollision(x, y, w, h, name);
          collisions.put(id, collision);
          log.debug("collision id=" + id + ", " + collision);
        } else if (id.matches(".+interval")) {
          Matcher m = Pattern.compile("(.+)interval").matcher(id);
          m.matches();
          id = m.group(1);
          String type = split[1];
          SerikoAnimation animation = new SerikoAnimation(this, id, type);
          animations.put(id, animation);
          log.debug("interval id=" + id + ", " + animation);
        } else if (id.matches(".+pattern.+")) {
          Matcher m = Pattern.compile("(.+)pattern(.+)").matcher(id);
          m.matches();
          id = m.group(1);
          //					String index = m.group(2);
          String method;
          String surfaceId;
          int interval;
          if (split[3].matches("[0-9]+")) {
            method = split[1];
            surfaceId = split[2];
            interval = Integer.parseInt(split[3]);
          } else {
            surfaceId = split[1];
            interval = Integer.parseInt(split[2]);
            method = split[3];
          }
          int offsetX = Integer.parseInt(split[4]);
          int offsetY = Integer.parseInt(split[5]);
          SerikoAnimation animation = animations.get(id);
          animation.addPattern(method, surfaceId, interval, offsetX, offsetY);
          log.debug("pattern id=" + id + ", " + animation + ", method=" + method);
        } else {
          log.debug("unknown id=" + id);
        }
      }
    } catch (IOException x) {
      log.error("不正な定義です。", x);
    }
  }
Exemplo n.º 2
0
  /**
   * イメージを描画します。
   *
   * @param g グラフィックス
   */
  public void draw(Graphics2D g) {
    if (log.isTraceEnabled()) log.debug("id=" + id + ", size=" + getSize());
    //		g.clearRect(0, 0, getWidth(), getHeight());
    if (animations.isEmpty()) {
      drawImage(g, x, y);
      //			Toolkit tk = Toolkit.getDefaultToolkit();
      //			ChromakeyImageFilter chromakey = new ChromakeyImageFilter(getBackground().getRGB());
      //			Image img = tk.createImage(new FilteredImageSource(image.getSource(), chromakey));
      //			g.drawImage(img, x, y, null);
    } else {
      for (SerikoAnimation animation : animations.values()) {
        animation.draw(g);
      }
      //			new Thread(new Runnable()
      //			{
      //				@Override
      //				public void run()
      //				{
      //					try
      //					{
      //						log.debug("sleep");
      //						Thread.sleep(90);
      //						log.debug("wakeup");
      ////						repaint(90);
      ////						invalidate();
      ////						validate();
      //						repaint();
      //					}
      //					catch (InterruptedException x)
      //					{
      //						// 何もしない
      //					}
      //				}
      //			}).start();
    }

    if (log.isDebugEnabled()) {
      g.setPaint(Color.RED);
      g.drawRect(x, y, getWidth() - 1, getHeight() - 1);
      if (descript != null) {
        g.fillRect(0, 0, 8, 8);
      }
      for (SerikoCollision collision : collisions.values()) {
        Rectangle clip = collision.getClip();
        g.draw(clip);
        g.drawString(collision.getName(), clip.x + 1, clip.y + 12);
      }
    }
  }