/**
   * Set <CODE>Vector</CODE> of <CODE>String</CODE>s describing the cursor location from the cursor
   * location; this is invoked when the cursor location changes or the cursor display status changes
   */
  public void setCursorStringVector() {
    synchronized (cursorStringVector) {
      cursorStringVector.removeAllElements();
      float[][] cursor = new float[3][1];
      double[] cur = getCursor();
      cursor[0][0] = (float) cur[0];
      cursor[1][0] = (float) cur[1];
      cursor[2][0] = (float) cur[2];
      Enumeration maps = display.getMapVector().elements();
      while (maps.hasMoreElements()) {
        try {
          ScalarMap map = (ScalarMap) maps.nextElement();
          DisplayRealType dreal = map.getDisplayScalar();
          DisplayTupleType tuple = dreal.getTuple();
          int index = dreal.getTupleIndex();
          if (tuple != null
              && (tuple.equals(Display.DisplaySpatialCartesianTuple)
                  || (tuple.getCoordinateSystem() != null
                      && tuple
                          .getCoordinateSystem()
                          .getReference()
                          .equals(Display.DisplaySpatialCartesianTuple)))) {
            float[] fval = new float[1];
            if (tuple.equals(Display.DisplaySpatialCartesianTuple)) {
              fval[0] = cursor[index][0];
            } else {
              float[][] new_cursor = tuple.getCoordinateSystem().fromReference(cursor);
              fval[0] = new_cursor[index][0];
            }
            float[] dval = map.inverseScaleValues(fval);
            RealType real = (RealType) map.getScalar();

            // WLH 31 Aug 2000
            Real r = new Real(real, dval[0]);
            Unit overrideUnit = map.getOverrideUnit();
            Unit rtunit = real.getDefaultUnit();
            // units not part of Time string
            // DRM 2003-08-19: don't check for equality since toString
            // may be different
            if (overrideUnit != null
                && // !overrideUnit.equals(rtunit) &&
                (!Unit.canConvert(rtunit, CommonUnit.secondsSinceTheEpoch)
                    || rtunit.getAbsoluteUnit().equals(rtunit))) {
              dval[0] = (float) overrideUnit.toThis((double) dval[0], rtunit);
              r = new Real(real, dval[0], overrideUnit);
            }
            String valueString = r.toValueString();

            // WLH 27 Oct 2000
            String s = map.getScalarName() + " = " + valueString;
            // String s = real.getName() + " = " + valueString;

            cursorStringVector.addElement(s);
          } // end if (tuple != null && ...)
        } catch (VisADException e) {
        }
      } // end while(maps.hasMoreElements())
    } // end synchronized (cursorStringVector)
    render_trigger();
  }
Beispiel #2
0
  public void attack(Unit enemy) {

    if (heatCounter >= heat) {

      fireX = enemy.getX();
      fireY = enemy.getY();
      enemy.freeze(level * 2.0);
      effects.add(new CircleTowerEffect(fireX, fireY, Global.MAX_SIZE, 100));
    }
  }
Beispiel #3
0
  public void finishedSelectingUnits(TilePanel tilePanel, List<Unit> chosenUnits) {
    UnitActionDetector unitActionDetector =
        new UnitActionDetector(selectedPanel, selectedUnit, tilePanel, chosenUnits);

    if (unitActionDetector.isSelectingUnit()) {
      selectedPanel = tilePanel;
      selectedPanel.addTileStateFromKey(selectedStateKey);
      repaintPanels(selectedPanel);
      selectedUnit = getUnit(chosenUnits);
      selectValidMovements(selectedPanel.getTile(), selectedUnit);
    } else if (unitActionDetector.isDeselectingUnit()) {
      selectedPanel.removeTileStateFromKey(selectedStateKey);
      deselectValidMovements(selectedPanel.getTile(), selectedUnit);
      repaintPanels(selectedPanel);
      selectedPanel = null;
      selectedUnit = null;
    } else if (unitActionDetector.isMovingUnit()) {
      Position from = selectedPanel.getTile().getPosition();
      Position to = tilePanel.getTile().getPosition();
      if (movementStrategy.isValidMove(selectedUnit, from, to, unitMap)) {
        deselectValidMovements(selectedPanel.getTile(), selectedUnit);
        selectedPanel.removeTileStateFromKey(selectedStateKey);

        List<Unit> units = unitMap.get(to);
        if (units != null && !units.isEmpty()) {
          Unit defending = units.get(0);
          BattleStrategy strategy =
              battleStrategyConfiguration.getBattleStrategy(
                  selectedUnit, defending, selectedPanel.getTile(), tilePanel.getTile());
          Unit winner = strategy.getWinner(selectedUnit, defending);
          if (winner.equals(selectedUnit)) {
            units.remove(defending);
          }
        }
        board.move(selectedUnit, from, to);
        repaintPanels(selectedPanel);
        selectedPanel = null;
        selectedUnit = null;
      }
    }
    frame.setEnabled(true);
    resetPositions();
  }
Beispiel #4
0
 public void setCameraFocus(Unit unit) {
   cameraX = (unit.getTile().getX() * 64) - (getWidth() / 2) + 32;
   cameraY = (unit.getTile().getY() * 64) - (getHeight() / 2) + 32;
 }
Beispiel #5
0
 @Override
 protected void paintComponent(Graphics graphics) {
   BufferedImage backImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D backGraphics = backImage.createGraphics();
   BufferedImage frontImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D frontGraphics = frontImage.createGraphics();
   BufferedImage particleImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D particleGraphics = particleImage.createGraphics();
   Graphics2D graphics2D = (Graphics2D) graphics;
   graphics.setColor(Color.BLACK);
   graphics.fillRect(0, 0, getWidth(), getHeight());
   graphics2D.translate(-cameraX, -cameraY);
   backGraphics.translate(-cameraX, -cameraY);
   frontGraphics.translate(-cameraX, -cameraY);
   particleGraphics.translate(-cameraX, -cameraY);
   for (int y = cameraY / 64; y < (cameraY / 64) + (getHeight() / 64) + 2; y++) {
     for (int x = cameraX / 64; x < (cameraX / 64) + (getWidth() / 64) + 2; x++) {
       Tile tile = world.getTileAt(x, y);
       if (tile != null) {
         backGraphics.drawImage(
             client.getTextureManager().getTexture("grass"), x * 64, y * 64, null);
         Unit unit = tile.getUnit();
         if (unit != null) {
           if (unit instanceof Dragon) {
             BufferedImage texture;
             if (unit.getDX() > 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_right_1")
                       : client.getTextureManager().getTexture("dragon_right_2");
             } else if (unit.getDX() < 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_left_1")
                       : client.getTextureManager().getTexture("dragon_left_2");
             } else if (unit.getDY() > 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_down_1")
                       : client.getTextureManager().getTexture("dragon_down_2");
             } else if (unit.getDY() < 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_up_1")
                       : client.getTextureManager().getTexture("dragon_up_2");
             } else {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_down_1")
                       : client.getTextureManager().getTexture("dragon_down_2");
             }
             frontGraphics.drawImage(
                 texture, (x * 64) + unit.getXOffset(), (y * 64) + unit.getYOffset(), null);
             particleGraphics.setColor(Color.BLACK);
             if (unit.getAttackTarget() != null
                 && ((abs(unit.getAttackTarget().getTile().getX() - unit.getTile().getX()) == 1
                         && unit.getAttackTarget().getTile().getY() == unit.getTile().getY())
                     || (abs(unit.getAttackTarget().getTile().getY() - unit.getTile().getY()) == 1
                         && unit.getAttackTarget().getTile().getX() == unit.getTile().getX()))) {
               int xStart = min(unit.getTile().getX(), unit.getAttackTarget().getTile().getX());
               int xEnd = max(unit.getTile().getX(), unit.getAttackTarget().getTile().getX());
               int yStart = min(unit.getTile().getY(), unit.getAttackTarget().getTile().getY());
               int yEnd = max(unit.getTile().getY(), unit.getAttackTarget().getTile().getY());
               Random random = new Random();
               for (int pX = (xStart * 64) + 28; pX < (xEnd * 64) + 34; pX++) {
                 for (int pY = (yStart * 64) + 28; pY < (yEnd * 64) + 34; pY++) {
                   switch (random.nextInt(3)) {
                     case 0:
                       particleGraphics.setColor(Color.RED);
                       break;
                     case 1:
                       particleGraphics.setColor(Color.ORANGE);
                       break;
                     case 2:
                       particleGraphics.setColor(Color.YELLOW);
                       break;
                   }
                   particleGraphics.fillOval(
                       pX - 3 + random.nextInt(3), pY - 3 + random.nextInt(3), 4, 4);
                 }
               }
             }
           } else if (unit instanceof Wall) {
             TextureManager textureManager = client.getTextureManager();
             BufferedImage texture = textureManager.getTexture("tower");
             int offset = 128;
             Tile upTile = unit.getTile().getAdjacent(0, -1);
             boolean up =
                 upTile != null
                     && upTile.getUnit() != null
                     && upTile.getUnit() instanceof Wall
                     && upTile.getUnit().isComplete();
             Tile downTile = unit.getTile().getAdjacent(0, 1);
             boolean down =
                 downTile != null
                     && downTile.getUnit() != null
                     && downTile.getUnit() instanceof Wall
                     && downTile.getUnit().isComplete();
             Tile leftTile = unit.getTile().getAdjacent(-1, 0);
             boolean left =
                 leftTile != null
                     && leftTile.getUnit() != null
                     && leftTile.getUnit() instanceof Wall
                     && leftTile.getUnit().isComplete();
             Tile rightTile = unit.getTile().getAdjacent(1, 0);
             boolean right =
                 rightTile != null
                     && rightTile.getUnit() != null
                     && rightTile.getUnit() instanceof Wall
                     && rightTile.getUnit().isComplete();
             if (unit.isComplete()) {
               if (up) {
                 if (down) {
                   if (left) {
                     if (right) {
                       texture = textureManager.getTexture("tower_wall_up_down_left_right");
                     } else {
                       texture = textureManager.getTexture("tower_wall_up_down_left");
                     }
                   } else if (right) {
                     texture = textureManager.getTexture("tower_wall_up_down_right");
                   } else {
                     texture = textureManager.getTexture("wall_ver");
                     offset = 64;
                   }
                 } else if (left) {
                   if (right) {
                     texture = textureManager.getTexture("tower_wall_up_left_right");
                   } else {
                     texture = textureManager.getTexture("tower_wall_up_left");
                   }
                 } else if (right) {
                   texture = textureManager.getTexture("tower_wall_up_right");
                 } else {
                   texture = textureManager.getTexture("tower_wall_up");
                 }
               } else if (down) {
                 if (left) {
                   if (right) {
                     texture = textureManager.getTexture("tower_wall_down_left_right");
                   } else {
                     texture = textureManager.getTexture("tower_wall_down_left");
                   }
                 } else if (right) {
                   texture = textureManager.getTexture("tower_wall_down_right");
                 } else {
                   texture = textureManager.getTexture("tower_wall_down");
                 }
               } else if (left) {
                 if (right) {
                   texture = textureManager.getTexture("wall_hor");
                   offset = 64;
                 } else {
                   texture = textureManager.getTexture("tower_wall_left");
                 }
               } else if (right) {
                 texture = textureManager.getTexture("tower_wall_right");
               }
             } else {
               texture = textureManager.getTexture("wall_in_progress");
               offset = 64;
             }
             frontGraphics.drawImage(
                 texture,
                 (x * 64) + unit.getXOffset(),
                 (y * 64) + unit.getYOffset() - offset,
                 null);
           } else if (unit instanceof Flag) {
             BufferedImage texture = null;
             if (currentFlagFrame == 0) texture = client.getTextureManager().getTexture("flag_1");
             else if (currentFlagFrame == 1)
               texture = client.getTextureManager().getTexture("flag_2");
             else if (currentFlagFrame == 2)
               texture = client.getTextureManager().getTexture("flag_3");
             else if (currentFlagFrame == 3)
               texture = client.getTextureManager().getTexture("flag_4");
             if (texture != null) frontGraphics.drawImage(texture, (x * 64), (y * 64) - 64, null);
           }
         }
       }
     }
   }
   int mouseTileX =
       ((cameraX
               - (int) getLocationOnScreen().getX()
               + (int) MouseInfo.getPointerInfo().getLocation().getX())
           / 64);
   int mouseTileY =
       ((cameraY
               - (int) getLocationOnScreen().getY()
               + (int) MouseInfo.getPointerInfo().getLocation().getY())
           / 64);
   Tile mouseTile = getWorld().getTileAt(mouseTileX, mouseTileY);
   if (mouseTile != null) {
     if (mouseTile.getUnit() == null) {
       if (client.getShopPanel().getSelectedItem() == null) {
         backGraphics.setColor(new Color(0F, 1F, 0F, 0.5F));
       } else {
         backGraphics.setColor(new Color(0F, 0F, 1F, 0.5F));
       }
     } else {
       backGraphics.setColor(new Color(1F, 0F, 0F, 0.5F));
     }
     backGraphics.fillRect(mouseTileX * 64, mouseTileY * 64, 64, 64);
     if (mouseTile.getUnit() == null) {
       if (client.getShopPanel().getSelectedItem() == null) {
         backGraphics.setColor(Color.GREEN);
       } else {
         backGraphics.setColor(Color.BLUE);
       }
     } else {
       backGraphics.setColor(Color.RED);
     }
     backGraphics.drawRect(
         ((cameraX
                     - (int) getLocationOnScreen().getX()
                     + (int) MouseInfo.getPointerInfo().getLocation().getX())
                 / 64)
             * 64,
         ((cameraY
                     - (int) getLocationOnScreen().getY()
                     + (int) MouseInfo.getPointerInfo().getLocation().getY())
                 / 64)
             * 64,
         64,
         64);
   }
   graphics2D.translate(cameraX, cameraY);
   backGraphics.translate(cameraX, cameraY);
   frontGraphics.translate(cameraX, cameraY);
   particleGraphics.translate(cameraX, cameraY);
   graphics.drawImage(backImage, 0, 0, null);
   graphics.drawImage(frontImage, 0, 0, null);
   graphics.drawImage(particleImage, 0, 0, null);
   backGraphics.dispose();
   frontGraphics.dispose();
   particleGraphics.dispose();
   backImage.flush();
   frontImage.flush();
   particleImage.flush();
 }