Exemplo n.º 1
0
  public Tile(Map map, int x, int y, Element tile) {
    this.map = map;
    this.x = x;
    this.y = y;
    height = (int) Float.parseFloat(tile.getAttribute("height"));
    if (!tile.getAttribute("caveHeight").equals("")) {
      caveHeight = (int) Float.parseFloat(tile.getAttribute("caveHeight"));
    }
    if (!tile.getAttribute("caveSize").equals("")) {
      caveSize = (int) Float.parseFloat(tile.getAttribute("caveSize"));
    }
    ground = new Ground((Element) tile.getElementsByTagName("ground").item(0));
    if (tile.getElementsByTagName("cave").getLength() != 0) {
      cave = CaveData.get((Element) tile.getElementsByTagName("cave").item(0));
    }

    NodeList labels = tile.getElementsByTagName("label");
    if (labels.getLength() != 0) {
      label = new Label((Element) labels.item(0));
    }
    NodeList caveLabels = tile.getElementsByTagName("caveLabel");
    if (caveLabels.getLength() != 0) {
      caveLabel = new Label((Element) caveLabels.item(0));
    }

    entities = new HashMap<>();

    NodeList list = tile.getElementsByTagName("level");
    for (int i = 0; i < list.getLength(); i++) {
      Element level = (Element) list.item(i);
      int floor = Integer.parseInt(level.getAttribute("value"));
      NodeList childNodes = level.getElementsByTagName("*");
      for (int i2 = 0; i2 < childNodes.getLength(); i2++) {
        Element entity = (Element) childNodes.item(i2);
        switch (entity.getNodeName().toLowerCase()) {
          case "floor":
            entities.put(new EntityData(floor, EntityType.FLOORROOF), new Floor(entity));
            break;
          case "hwall":
            Wall hwall = new Wall(entity);
            if (hwall.data.houseWall) {
              entities.put(new EntityData(floor, EntityType.HWALL), hwall);
            } else {
              entities.put(new EntityData(floor, EntityType.HFENCE), hwall);
            }
            break;
          case "vwall":
            Wall vwall = new Wall(entity);
            if (vwall.data.houseWall) {
              entities.put(new EntityData(floor, EntityType.VWALL), vwall);
            } else {
              entities.put(new EntityData(floor, EntityType.VFENCE), vwall);
            }
            break;
          case "hborder":
            entities.put(new EntityData(0, EntityType.HBORDER), BorderData.get(entity));
            break;
          case "vborder":
            entities.put(new EntityData(0, EntityType.VBORDER), BorderData.get(entity));
            break;
          case "roof":
            entities.put(new EntityData(floor, EntityType.FLOORROOF), new Roof(entity));
            break;
          case "object":
            ObjectLocation loc = ObjectLocation.parse(entity.getAttribute("position"));
            entities.put(new ObjectEntityData(floor, loc), new GameObject(entity));
            break;
          case "cave":
            cave = CaveData.get(entity);
            break;
        }
      }
    }
  }
Exemplo n.º 2
0
  private void renderEntities(GL2 g) {
    for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
      EntityData key = e.getKey();
      final int floor = key.getFloor();
      float colorMod = 1;
      if (Globals.upCamera) {
        switch (Globals.floor - floor) {
          case 0:
            colorMod = 1;
            break;
          case 1:
            colorMod = 0.6f;
            break;
          case 2:
            colorMod = 0.25f;
            break;
          default:
            continue;
        }
      }
      TileEntity entity = e.getValue();
      g.glPushMatrix();
      switch (key.getType()) {
        case FLOORROOF:
          g.glTranslatef(4, 0, 3 * floor + getFloorHeight() / Constants.HEIGHT_MOD);
          g.glColor3f(colorMod, colorMod, colorMod);
          entity.render(g, this);
          break;
        case VWALL:
        case VFENCE:
          g.glTranslatef(0, 0, 3 * floor + getVerticalWallHeight() / Constants.HEIGHT_MOD);
          g.glRotatef(90, 0, 0, 1);
          float vdiff = getVerticalWallHeightDiff() / 47f;
          if (vdiff < 0) {
            g.glTranslatef(0, 0, -vdiff * 4f);
          }
          deform(g, vdiff);

          Wall vwall = (Wall) entity;
          if (Globals.upCamera) {
            vwall.data.color.use(g, colorMod);
          } else {
            g.glColor3f(1, 1, 1);
          }
          vwall.render(g, this);
          g.glColor3f(1, 1, 1);
          break;
        case HWALL:
        case HFENCE:
          g.glTranslatef(0, 0, 3 * floor + getHorizontalWallHeight() / Constants.HEIGHT_MOD);
          float hdiff = getHorizontalWallHeightDiff() / 47f;
          if (hdiff < 0) {
            g.glTranslatef(0, 0, -hdiff * 4f);
          }
          deform(g, hdiff);
          Wall hwall = (Wall) entity;
          if (Globals.upCamera) {
            hwall.data.color.use(g, colorMod);
          } else {
            g.glColor3f(1, 1, 1);
          }
          hwall.render(g, this);
          g.glColor3f(1, 1, 1);
          break;
        case OBJECT:
          ObjectEntityData objData = (ObjectEntityData) key;
          ObjectLocation loc = objData.getLocation();
          GameObject obj = (GameObject) entity;
          g.glColor3f(colorMod, colorMod, colorMod);
          g.glTranslatef(
              loc.getHorizontalAlign(),
              loc.getVerticalAlign(),
              3 * floor
                  + getHeight(loc.getHorizontalAlign() / 4f, loc.getVerticalAlign() / 4f)
                      / Constants.HEIGHT_MOD);
          obj.render(g, this);
          break;
      }
      g.glPopMatrix();
      g.glColor3f(1, 1, 1);
    }
  }