Exemple #1
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);
  }
Exemple #2
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();
  }
Exemple #3
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == easy) {
      invSpeed = 50000;
      bombN = 1;
      timeDifficulty1 = 1000;
      distanceLimit = 400;
      monsterMultiplier = 1;
      multiplier = 1;
      setup();
    } else if (e.getSource() == hard) {
      invSpeed = 30000;
      bombN = 4;
      timeDifficulty1 = 500;
      distanceLimit = 200;
      monsterMultiplier = 2;
      multiplier = 2;
      setup();
    } else if (e.getSource() == back) {
      r = null;
      menu.setVisible(true);
      back.setVisible(false);
      this.revalidate();
      repaint();
    } else if (e.getSource() == howTo) {
      menu.removeAll();

      menu.add(howToBack);
      menu.add(howToIMGL);

      menu.revalidate();
      menu.repaint();
    } else if (e.getSource() == howToBack) {
      menu.remove(howToIMGL);
      menu.remove(howToBack);

      menu.add(keyboardSpeedL1);
      menu.add(keyboardSpeedL2);
      menu.add(easy);
      menu.add(hard);
      menu.add(howTo);
      menu.add(onePlayerRB);
      menu.add(twoPlayerRB);
      menu.add(mouseRB);
      menu.add(keyboardRB);
      menu.add(keyboardSpeedS1);
      menu.add(keyboardSpeedS2);
      menu.add(musicCB);
      menu.add(highscoreL);
      menu.add(menuIMGL);

      menu.revalidate();
      menu.repaint();
    }
  }
Exemple #4
0
  private void makeMenuScreen() {
    menu = new JPanel();
    menu.setBackground(Color.BLACK);
    menu.setLayout(null);
    menu.setBounds(0, 0, width, height);

    try {
      BufferedImage menuIMG =
          ImageIO.read(this.getClass().getResource("/Resources/MenuBackground.png"));
      // BufferedImage menuIMG = ImageIO.read(new
      // File("M:/ComputerProgrammingJava/InsaneMouse_03/src/Resources/MenuBackground.png"));
      menuIMGL =
          new JLabel(
              new ImageIcon(
                  menuIMG.getScaledInstance(
                      (int) (width * 0.8), (int) (height * 0.8), Image.SCALE_SMOOTH)));
      menuIMGL.setBounds(0, 0, width, height);
    } catch (Exception e) {
    }

    highscoreL = new JLabel(String.valueOf(highscore));
    highscoreL.setBackground(Color.darkGray);
    highscoreL.setBounds((width / 2) + 100, (height / 2) + 70, 500, 100);
    highscoreL.setForeground(Color.white);

    easy = new JButton("Easy");
    hard = new JButton("Hard");

    easy.addActionListener(this);
    hard.addActionListener(this);

    easy.setBounds((width / 2) - 60, (height / 2) - 50, 120, 20);
    hard.setBounds((width / 2) - 60, height / 2 - 10, 120, 20);

    onePlayerRB = new JRadioButton("One Player");
    twoPlayerRB = new JRadioButton("Two Player");
    mouseRB = new JRadioButton("Mouse (Player 1)");
    keyboardRB = new JRadioButton("Keyboard (Player 1)");
    keyboardSpeedS1 = new JSlider(JSlider.HORIZONTAL, 10, 300, 50);
    keyboardSpeedS2 = new JSlider(JSlider.HORIZONTAL, 10, 300, 50);
    musicCB = new JCheckBox("Music");

    onePlayerRB.setBackground(null);
    twoPlayerRB.setBackground(null);
    mouseRB.setBackground(null);
    keyboardRB.setBackground(null);
    keyboardSpeedS1.setBackground(null);
    keyboardSpeedS2.setBackground(null);
    musicCB.setBackground(null);

    onePlayerRB.setForeground(Color.WHITE);
    twoPlayerRB.setForeground(Color.WHITE);
    mouseRB.setForeground(Color.WHITE);
    keyboardRB.setForeground(Color.WHITE);
    keyboardSpeedS1.setForeground(Color.WHITE);
    keyboardSpeedS2.setForeground(Color.WHITE);
    musicCB.setForeground(Color.WHITE);

    ButtonGroup playerChoice = new ButtonGroup();
    playerChoice.add(onePlayerRB);
    playerChoice.add(twoPlayerRB);
    onePlayerRB.setSelected(true);

    ButtonGroup peripheralChoice = new ButtonGroup();
    peripheralChoice.add(mouseRB);
    peripheralChoice.add(keyboardRB);
    mouseRB.setSelected(true);

    musicCB.setSelected(true);

    onePlayerRB.setBounds((width / 2) + 100, (height / 2) - 50, 100, 20);
    twoPlayerRB.setBounds((width / 2) + 100, (height / 2) - 30, 100, 20);
    mouseRB.setBounds((width / 2) + 100, (height / 2), 200, 20);
    keyboardRB.setBounds((width / 2) + 100, (height / 2) + 20, 200, 20);
    keyboardSpeedS1.setBounds(width / 2 - 120, height / 2 + 100, 200, 50);
    keyboardSpeedS2.setBounds(width / 2 - 120, height / 2 + 183, 200, 50);
    musicCB.setBounds((width / 2) + 100, (height / 2) + 50, 100, 20);

    keyboardSpeedL1 = new JLabel("Keyboard Speed (Player One)");
    keyboardSpeedL1.setForeground(Color.WHITE);
    keyboardSpeedL1.setBounds(width / 2 - 113, height / 2 + 67, 200, 50);

    keyboardSpeedL2 = new JLabel("Keyboard Speed (Player Two)");
    keyboardSpeedL2.setForeground(Color.WHITE);
    keyboardSpeedL2.setBounds(width / 2 - 113, height / 2 + 150, 200, 50);

    howTo = new JButton("How To Play");
    howTo.addActionListener(this);
    howTo.setBounds((width / 2) - 60, height / 2 + 30, 120, 20);

    try {
      BufferedImage howToIMG = ImageIO.read(this.getClass().getResource("/Resources/HowTo.png"));
      // BufferedImage howToIMG = ImageIO.read(new
      // File("M:/ComputerProgrammingJava/InsaneMouse_03/src/Resources/HowTo.png"));
      howToIMGL = new JLabel(new ImageIcon(howToIMG));
      howToIMGL.setBounds(
          width / 2 - howToIMG.getWidth() / 2,
          height / 2 - howToIMG.getHeight() / 2,
          howToIMG.getWidth(),
          howToIMG.getHeight());
    } catch (Exception e) {
    }

    howToBack = new JButton("X");
    howToBack.setBounds(
        (int) (width / 2 + width * 0.25) - 50, (int) (height / 2 - height * 0.25), 50, 50);
    howToBack.setBackground(Color.BLACK);
    howToBack.setForeground(Color.WHITE);
    howToBack.addActionListener(this);

    menu.add(easy);
    menu.add(hard);
    menu.add(howTo);
    menu.add(highscoreL);
    menu.add(onePlayerRB);
    menu.add(twoPlayerRB);
    menu.add(mouseRB);
    menu.add(keyboardRB);
    menu.add(keyboardSpeedL1);
    menu.add(keyboardSpeedL2);
    menu.add(keyboardSpeedS1);
    menu.add(keyboardSpeedS2);
    menu.add(musicCB);
    menu.add(menuIMGL);

    back = new JButton("Back");
    back.setBounds(width / 2 - 40, height / 2, 100, 20);
    back.addActionListener(this);
    back.setVisible(false);
    this.add(back);
  }