Exemplo n.º 1
0
 public void setTablaPrincipal(java.util.List val) {
   DefaultTableModel modelo = ((DefaultTableModel) this.tablaPrincipal.getModel());
   for (int i = 0; i < val.size(); i++) {
     modelo.addRow(((java.util.ArrayList) val.get(i)).toArray());
   }
   this.calculaSumas();
 }
Exemplo n.º 2
0
  private void spawnRandomers() {
    for (int i = 0; i < randomN; i++) {
      float x = (float) Math.random() * width;
      float y = (float) Math.random() * height;
      float r =
          (float)
              Math.sqrt(
                  Math.pow(((Player) players.get(0)).getX() - x, 2)
                      + Math.pow(((Player) players.get(0)).getY() - x, 2));

      while (r < distanceLimit) {
        x = (float) Math.random() * width;
        y = (float) Math.random() * height;
        r =
            (float)
                Math.sqrt(
                    Math.pow(((Player) players.get(0)).getX() - x, 2)
                        + Math.pow(((Player) players.get(0)).getY() - y, 2));
      }

      enemies.add(new EnemyTypes.Random(x, y, 0.5f, borders));
    }

    spawnRandomersB = false;
  }
Exemplo n.º 3
0
 public static void drawImage(int[][][] pixels, int startX, int startY) {
   // Key idea: draw a bunch (lots of rectangles) with the appropriate color
   DrawObject R = new DrawObject();
   R.pixels = pixels;
   R.startX = startX;
   R.startY = startY;
   R.sequenceNum = currentSequenceNum;
   images.add(R);
   // Rescale if needed.
   int leftX = startX;
   int rightX = startX + pixels.length;
   int lowY = startY;
   int highY = startY + pixels[0].length;
   if (minX > leftX) {
     minX = leftX;
   }
   if (maxX < rightX) {
     maxX = rightX;
   }
   if (minY > lowY) {
     minY = lowY;
   }
   if (maxY < highY) {
     maxY = highY;
   }
   drawArea.repaint();
 }
Exemplo n.º 4
0
 static void handleMouseDragged(MouseEvent e) {
   DrawObject L = new DrawObject();
   L.scribbleX = e.getX();
   L.scribbleY = e.getY();
   L.scribbleNum = currentScribbleNum;
   scribbles.add(L);
   drawArea.repaint();
 }
Exemplo n.º 5
0
 protected void paintToImage(Component c, Image image, Graphics g, int w, int h, Object[] args) {
   Graphics2D g2 = (Graphics2D) g;
   java.util.List gradient = (java.util.List) args[0];
   boolean isVertical = ((Boolean) args[1]).booleanValue();
   // Render to the VolatileImage
   if (isVertical) {
     drawVerticalGradient(
         g2,
         ((Number) gradient.get(0)).floatValue(),
         ((Number) gradient.get(1)).floatValue(),
         (Color) gradient.get(2),
         (Color) gradient.get(3),
         (Color) gradient.get(4),
         w,
         h);
   } else {
     drawHorizontalGradient(
         g2,
         ((Number) gradient.get(0)).floatValue(),
         ((Number) gradient.get(1)).floatValue(),
         (Color) gradient.get(2),
         (Color) gradient.get(3),
         (Color) gradient.get(4),
         w,
         h);
   }
 }
Exemplo n.º 6
0
 public static void drawLabel(double x, double y, String str) {
   DrawObject L = new DrawObject();
   L.color = labelColor;
   L.x = x;
   L.y = y;
   L.str = str;
   L.sequenceNum = currentSequenceNum;
   if (animationMode) {
     synchronized (animLabels) {
       animLabels.add(L);
     }
   } else {
     synchronized (labels) {
       labels.add(L);
     }
   }
   drawArea.repaint();
 }
Exemplo n.º 7
0
 public void updateIconImages() {
   java.util.List<Image> imageList = ((Window) target).getIconImages();
   if (imageList == null || imageList.size() == 0) {
     setIconImagesData(null, 0, 0, null, 0, 0);
   } else {
     int w = getSysIconWidth();
     int h = getSysIconHeight();
     int smw = getSysSmIconWidth();
     int smh = getSysSmIconHeight();
     DataBufferInt iconData = SunToolkit.getScaledIconData(imageList, w, h);
     DataBufferInt iconSmData = SunToolkit.getScaledIconData(imageList, smw, smh);
     if (iconData != null && iconSmData != null) {
       setIconImagesData(iconData.getData(), w, h, iconSmData.getData(), smw, smh);
     } else {
       setIconImagesData(null, 0, 0, null, 0, 0);
     }
   }
 }
Exemplo n.º 8
0
 public static void drawPoint(double x, double y) {
   DrawObject p = new DrawObject();
   p.color = pointColor;
   p.x = x;
   p.y = y;
   p.diameter = pointDiameter;
   p.sequenceNum = currentSequenceNum;
   if (animationMode) {
     synchronized (animPoints) {
       animPoints.add(p);
     }
   } else {
     synchronized (points) {
       points.add(p);
     }
   }
   drawArea.repaint();
 }
  public void tabRemoveHighlight(int tabIndex) {
    Iterator<Integer> highlightedIter = highlightedTabs.iterator();

    while (highlightedIter.hasNext()) {
      if (highlightedIter.next().intValue() == tabIndex) {
        highlightedIter.remove();
        break;
      }
    }
  }
Exemplo n.º 10
0
 public static void drawRectangle(double x1, double y1, double width, double height) {
   DrawObject R = new DrawObject();
   R.color = rectangleColor;
   R.x = x1;
   R.y = y1;
   R.width = width;
   R.height = height;
   R.sequenceNum = currentSequenceNum;
   R.drawStroke = drawStroke;
   if (animationMode) {
     synchronized (animRectangles) {
       animRectangles.add(R);
     }
   } else {
     synchronized (rectangles) {
       rectangles.add(R);
     }
   }
   drawArea.repaint();
 }
Exemplo n.º 11
0
 public static void animationPause(int pauseTime) {
   if ((pauseTime < 1) || (pauseTime > 1000)) {
     pauseTime = 100;
   }
   try {
     Thread.sleep(pauseTime);
     synchronized (animPoints) {
       animPoints.clear();
     }
     synchronized (animLines) {
       animLines.clear();
     }
     synchronized (animOvals) {
       animOvals.clear();
     }
     synchronized (animRectangles) {
       animRectangles.clear();
     }
   } catch (InterruptedException e) {
   }
 }
Exemplo n.º 12
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    height = this.getHeight();
    width = this.getWidth();

    drawPlayers(g);
    g.setColor(Color.WHITE);
    g.drawString("Score", width - 60, 25);
    g.drawString(String.valueOf(score), width - 60, 40);

    if (countdownF) {
      g.drawString(String.valueOf(counterN), width / 2 - 10, height / 2);
    } else {
      if ((spawnCircleB) && (spawnIncrease)) {
        spawnCircles();
      }
      if (spawnMonsterB) {
        spawnMonsters();
      }
      if (spawnRandomersB) {
        spawnRandomers();
      }
      if (spawnRainB) {
        spawnRain();
      }
      if (spawnBombB()) {
        spawnBomb();
      }

      try {
        Iterator i = enemies.iterator();
        while (i.hasNext()) {
          Enemy e = (Enemy) i.next();
          Iterator j = players.iterator();
          while (j.hasNext()) {
            Player p = (Player) j.next();
            e.move(players, programSpeedAdjust /*/players.size()*/);
            if ((e.collidesWith(p.getX(), p.getY())) && (!p.getImmunity())) {
              p.decLives(p.getX(), p.getY());
              p.setImmunity(true);
            }
          }
          e.paint(g);
        }
      } catch (Exception e) {
      }
    }
    drawLayout(g);
  }
Exemplo n.º 13
0
 private void movePlayers() {
   onePlayerAlive = false;
   Iterator i = players.iterator();
   while (i.hasNext()) {
     Player p = (Player) i.next();
     if (p.getLives() == 0) {
       p.setActive(false);
     }
     if (p.isActive()) {
       onePlayerAlive = true;
       p.move();
     }
   }
 }
Exemplo n.º 14
0
 public static void drawLineFromEquation(double a, double b, double c) {
   // Draw the equation ax+by+c=0 in the available range.
   DrawObject L = new DrawObject();
   L.color = lineEqnColor;
   L.a = a;
   L.b = b;
   L.c = c;
   L.sequenceNum = currentSequenceNum;
   L.drawStroke = drawStroke;
   synchronized (eqnLines) {
     eqnLines.add(L);
   }
   drawArea.repaint();
 }
Exemplo n.º 15
0
 public static void drawLine(double x1, double y1, double x2, double y2, boolean isArrow) {
   DrawObject L = new DrawObject();
   L.color = lineColor;
   L.x = x1;
   L.y = y1;
   L.x2 = x2;
   L.y2 = y2;
   if (isArrow) {
     L.color = arrowColor;
     L.isArrow = true;
   }
   L.sequenceNum = currentSequenceNum;
   L.drawStroke = drawStroke;
   if (animationMode) {
     synchronized (animLines) {
       animLines.add(L);
     }
   } else {
     synchronized (lines) {
       lines.add(L);
     }
   }
   drawArea.repaint();
 }
Exemplo n.º 16
0
 void drawScribbles(Graphics g) {
   if ((scribbles == null) || (scribbles.size() == 0)) {
     return;
   }
   DrawObject L = (DrawObject) scribbles.get(0);
   int scribbleCounter = L.scribbleNum;
   g.setColor(scribbleColor);
   ((Graphics2D) g).setStroke(new BasicStroke(2f));
   int prevX = L.scribbleX;
   int prevY = L.scribbleY;
   for (int i = 1; i < scribbles.size(); i++) {
     L = (DrawObject) scribbles.get(i);
     if (L.scribbleNum == scribbleCounter) {
       // Keep drawing.
       g.drawLine(prevX, prevY, L.scribbleX, L.scribbleY);
       prevX = L.scribbleX;
       prevY = L.scribbleY;
     } else {
       scribbleCounter = L.scribbleNum;
       prevX = L.scribbleX;
       prevY = L.scribbleY;
     }
   }
 }
Exemplo n.º 17
0
  private void setup() {
    playerSetup();

    deathLocation = new int[4];
    Arrays.fill(deathLocation, -1);

    menu.setVisible(false);
    this.revalidate();

    audioSetup();

    Iterator i = players.iterator();
    Player p;
    while (i.hasNext()) {
      p = (Player) i.next();
      p.resetLives(3);
      p.setActive(true);
    }

    BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Cursor blank =
        Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "BLANK");
    this.setCursor(blank);

    reset();

    ballN = 1;
    level = 1;
    timeLast = 0;
    score = 0;
    counterN = 10;
    timeCircle = 0;
    timeCircleSwitch = 0;
    programLoopCounter = 1;
    programSpeedAdjust = 1;

    onePlayerAlive = true;
    countdownF = true;
    circular = true;
    spawnIncrease = true;
    spawnCircleB = false;
    spawnMonsterB = false;
    spawnRandomersB = false;

    levelSetup();
    countdown();
    animate();
  }
Exemplo n.º 18
0
  // ErtanO 12.03.2004
  public static java.util.List getAvailablePLAF() {
    java.util.List l = new java.util.ArrayList();
    l.add("System");
    l.add("TinyLAF");
    l.add("JGoodiesLAF-PlasticXP");
    l.add("JGoodiesLAF-Plastic");
    l.add("JGoodiesLAF-Plastic3D");
    l.add("JGoodiesLAF-ExtWindows");

    javax.swing.UIManager.LookAndFeelInfo[] lfinfo =
        javax.swing.UIManager.getInstalledLookAndFeels();

    for (int i = 0; i < lfinfo.length; ++i) {
      l.add(lfinfo[i].getName());
    }

    return l;
  }
Exemplo n.º 19
0
  private void drawPlayers(Graphics g) {
    Iterator i = players.iterator();
    Player p;
    while (i.hasNext()) {
      p = (Player) i.next();

      if (p.isActive()) {
        if (p.getImmunity()) {
          g.setColor(Color.red.brighter());
          g.drawOval(p.getX() - 30, p.getY() - 30, 60, 60);
        }
        g.setColor(Color.WHITE);
        g.fillOval(p.getX() - 5, p.getY() - 5, 10, 10);
      }

      p.paint(g);
    }
  }
Exemplo n.º 20
0
  private void spawnCircles() {
    if (circular) {
      for (int i = 0; i < ballN; i++) {
        double degree = Math.random() * 2 * Math.PI;
        float x = ((Player) players.get(0)).getX() + distance * (float) Math.sin(degree * i);
        float y = ((Player) players.get(0)).getY() + distance * (float) Math.cos(degree * i);
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    } else {
      for (int i = 1; i < (ballN / 2); i++) {
        float x = (i * 2 * width) / (ballN);
        float y = 0;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }

      for (int i = (ballN / 2) + 1; i < ballN; i++) {
        float x = ((i - ballN / 2) * 2 * width) / ballN;
        float y = height;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    }
    spawnIncrease = false;
  }
 public boolean isTabHighlighted(int tabIndex) {
   return highlightedTabs.contains(tabIndex);
 }
Exemplo n.º 22
0
  private void drawLayout(Graphics g) {
    g.setColor(Color.blue);
    g.drawRect(10, 10, width - 20, height - 20);

    g.setColor(Color.red.brighter());
    Iterator f = players.iterator();
    int lifeDisplayPosition = 0;
    while (f.hasNext()) {
      Player h = (Player) f.next();
      if (h.isActive()) {
        lifeDisplayPosition++;
        String lifeInformation = "Player " + lifeDisplayPosition + ": ";
        for (int i = 0; i < h.getLives(); i++) {
          lifeInformation += "\u2606";
        }
        g.drawString(lifeInformation, 20, lifeDisplayPosition * 40);
      }
    }

    borders[2] = width - 20;
    borders[3] = height - 20;

    Iterator i = players.iterator();
    Player p;
    while (i.hasNext()) {
      p = (Player) i.next();
      if (p.isActive()
          && !countdownF
          && (p.getX() < borders[0]
              || p.getY() < borders[1]
              || p.getX() > borders[2]
              || p.getY() > borders[3])
          && (!p.getImmunity())) {
        p.decLives(width / 2, height / 2);
        p.setImmunity(true);
      }
      if (p.getLives() <= 0) {
        if (p instanceof MouseControlledPlayer) {
          MouseControlledPlayer m = (MouseControlledPlayer) p;
          removeMouseListener(m);
          removeMouseMotionListener(m);
        } else if (p instanceof KeyboardControlledPlayer) {
          KeyboardFocusManager.getCurrentKeyboardFocusManager()
              .removeKeyEventDispatcher((KeyboardControlledPlayer) p);
        }
        i.remove();
        for (int h = 0; h < 4; h++) {
          if (deathLocation[h] == -1) {
            deathLocation[h] = p.getX();
            deathLocation[h + 1] = p.getY();
            break;
          }
        }
      }
    }

    if ((deathLocation[0] != -1) && (deathLocation[1] != -1)) {
      g.drawLine(
          deathLocation[0] - 15,
          deathLocation[1] - 15,
          deathLocation[0] + 15,
          deathLocation[1] + 15);
      g.drawLine(
          deathLocation[0] + 15,
          deathLocation[1] - 15,
          deathLocation[0] - 15,
          deathLocation[1] + 15);
    }
    if ((deathLocation[2] != -1) && (deathLocation[3] != -1)) {
      g.drawLine(
          deathLocation[2] - 15,
          deathLocation[3] - 15,
          deathLocation[2] + 15,
          deathLocation[3] + 15);
      g.drawLine(
          deathLocation[2] + 15,
          deathLocation[3] - 15,
          deathLocation[2] - 15,
          deathLocation[3] + 15);
    }

    if (!onePlayerAlive) {
      Font old = g.getFont();
      g.setFont(new Font("monospaced", Font.BOLD, 20));
      g.setColor(Color.red.darker());
      g.drawString("GAME OVER", width / 2 - 40, height / 2);
      g.setFont(old);
      g.setColor(Color.WHITE);
      g.drawString("Score", width - 60, 25);
      g.drawString(String.valueOf(score), width - 60, 40);
    }
  }
Exemplo n.º 23
0
  private void playerSetup() {

    players = new ArrayList(twoPlayerRB.isSelected() ? 2 : 1);
    if (mouseRB.isSelected()) {
      MouseControlledPlayer p1 =
          new MouseControlledPlayer(width / 2, height / 2, 3, true, this, 3, 1, width);
      addMouseMotionListener(p1);
      addMouseListener(p1);
      players.add(p1);
    } else {
      KeyboardControlledPlayer p1 =
          new KeyboardControlledPlayer(
              width / 2,
              height / 2,
              3,
              true,
              this,
              3,
              KeyEvent.VK_W,
              KeyEvent.VK_A,
              KeyEvent.VK_S,
              KeyEvent.VK_D,
              keyboardSpeedS1.getValue(),
              KeyEvent.VK_SPACE,
              KeyEvent.VK_F,
              1,
              width);
      KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(p1);
      players.add(p1);
    }

    if (twoPlayerRB.isSelected()) {
      if (mouseRB.isSelected()) {
        KeyboardControlledPlayer p2 =
            new KeyboardControlledPlayer(
                width / 2,
                height / 2,
                3,
                true,
                this,
                3,
                KeyEvent.VK_W,
                KeyEvent.VK_A,
                KeyEvent.VK_S,
                KeyEvent.VK_D,
                keyboardSpeedS2.getValue(),
                KeyEvent.VK_SPACE,
                KeyEvent.VK_F,
                2,
                width);
        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(p2);
        players.add(p2);
      } else {
        KeyboardControlledPlayer p2 =
            new KeyboardControlledPlayer(
                width / 2,
                height / 2,
                3,
                true,
                this,
                3,
                KeyEvent.VK_NUMPAD8,
                KeyEvent.VK_NUMPAD4,
                KeyEvent.VK_NUMPAD5,
                KeyEvent.VK_NUMPAD6,
                keyboardSpeedS2.getValue(),
                KeyEvent.VK_NUMPAD0,
                KeyEvent.VK_NUMPAD1,
                2,
                width);
        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(p2);
        players.add(p2);
      }
    }
  }