Exemple #1
0
 @Override
 public void componentResized(ComponentEvent e) {
   int lim = Math.min(getWidth(), getHeight());
   if (game.getMapSize() != 0) {
     int size = lim / game.getMapSize();
     game.setPixelSize(size);
   }
 }
Exemple #2
0
 @Override
 public void mousePressed(MouseEvent e) {
   // if (spawnMenuItem.isEnabled()) {
   int newX = (int) Math.round(e.getX() / (double) game.getPixelSize());
   int newY = (int) Math.round(e.getY() / (double) game.getPixelSize());
   if (game.isInBounds(newY, newX)) {
     erase = game.getEntity(newX, newY) != null;
   }
   repaint();
   // }
 }
Exemple #3
0
 @Override
 public void mouseClicked(MouseEvent e) {
   // if (spawnMenuItem.isEnabled()) {
   int newX = (int) Math.round(e.getX() / (double) game.getPixelSize());
   int newY = (int) Math.round(e.getY() / (double) game.getPixelSize());
   if (game.isInBounds(newX, newY)) {
     if (erase) {
       game.removeEntity(newX, newY);
     } else {
       game.placeEntity(newX, newY, spawnID);
     }
   }
   repaint();
   // }
 }
Exemple #4
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Pixel[][] pixels = game.getDisplay();
    for (Pixel[] row : pixels) {
      for (Pixel pixel : row) {
        game.getPixelType(pixel.id).draw(pixel, game, g);
      }
    }
    List<Animation> animations = game.getAnimations();

    for (Animation a : animations) {
      a.draw(g);
    }
    frames++;
  }
Exemple #5
0
  @Override
  public void mouseDragged(MouseEvent e) {
    // if (spawnMenuItem.isEnabled()) {
    int newX = (int) Math.round(e.getX() / (double) game.getPixelSize());
    int newY = (int) Math.round(e.getY() / (double) game.getPixelSize());

    if (!game.isInBounds(newX, newY)
        || (newX == placeX && newY == placeY)
        || (game.getEntity(newX, newY) == null == erase)) {

      return;
    }

    placeX = newX;
    placeY = newY;

    if (erase) {
      game.removeEntity(newX, newY);
    } else {
      game.placeEntity(newX, newY, spawnID);
    }
    repaint();
    // }
  }