Exemplo n.º 1
0
 public void checkStarCollision() {
   for (Star s : starList) {
     if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides
       if (s.checkCollision(
           s.getPics().get(s.getCounter()),
           player1)) { // if the player collides with the star we remove it then change the
         // velosity to the distance that the star provides
         sRemove.add(s); // remove star once you collide with it
         player1.setVelo(s.getDist()); // changes the velocity
         player1.setInvi(true); // sets the player invisble for a few seconds
         score += s.getPoints(); // points increase by the star type
         if (musicOn) {
           starSound.play(); // playthe star sound
         }
       }
     } else {
       sRemove.add(s); // remove the star if its not on the screen
     }
   }
   for (Star s : sRemove) {
     poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect
     starList.remove(s);
   }
   sRemove = new ArrayList<Star>();
 }
Exemplo n.º 2
0
  public void keyReleased(KeyEvent key) {

    if (key.getKeyCode() == 37) {

      leftcheck = false;
      if (rightcheck) {
        player.ta = changet;
      } else {
        player.ta = 0;
      }
    }

    if (key.getKeyCode() == 39) {

      rightcheck = false;
      if (leftcheck) {
        player.ta = -changet;
      } else {
        player.ta = 0;
      }
    }

    if (key.getKeyCode() == 32) {

      grav = false;
    }
  }
Exemplo n.º 3
0
 public void checkEnemyCollision() {
   for (Enemy e : enemyList) {
     if (e.getOnScreen()) { // can be removed later on
       // goes through all the enemies and checks if they collide
       if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) {
         if (player1.getInvi() == false) {
           // If the player is not invisble then you get spiked.
           if (player1.getVelocity() > 0) { // if the player hits it from the bottom
             player1.setSpikeVelo();
             loseCoins();
           } else {
             player1.setVelo(
                 50); // if the player is on top instead the player bounces off the enemy
             if (musicOn) {
               bounce.play();
             }
           }
         }
         eRemove.add(e); // once we hit, we remove the enemy
       }
     } else {
       eRemove.add(e); // if the enemy goes of the screen, we remove
     }
   }
   for (Enemy e : eRemove) {
     poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies
     enemyList.remove(e);
   }
   eRemove = new ArrayList<Enemy>();
 }
Exemplo n.º 4
0
 @Override
 public void update(Observable o, Object arg) {
   if (arg instanceof Player) {
     Player player = (Player) arg;
     int points = player.getPoints();
     System.out.println("Spieler" + player.getNum() + "an der Reihe");
     if (player.getNum() == 1) {
       System.out.println("Spieler1 punkte++");
       points1Num.setText("" + points);
     } else if (player.getNum() == 2) {
       System.out.println("Spieler2 punkte++");
       points2Num.setText("" + points);
     }
   } else {
     GameController controller = (GameController) arg;
     if (controller.getPlayer().getNum() == 1) {
       ImageIcon image = new ImageIcon("../gfx/spieler1_play.png");
       l1.setIcon(image);
       ImageIcon imageOld = new ImageIcon("../gfx/spieler2.png");
       l2.setIcon(imageOld);
       System.out.println("spieler gewechselt");
     } else {
       ImageIcon imageI = new ImageIcon("../gfx/spieler2_play.png");
       l2.setIcon(imageI);
       ImageIcon imageOldI = new ImageIcon("../gfx/spieler1.png");
       l1.setIcon(imageOldI);
     }
   }
 }
Exemplo n.º 5
0
 public void scrollCoins() {
   for (Coin i : coinList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
     i.setYPos(i.getYPos() + (int) (player1.getVelocity() * 0.3));
     i.setYMax(i.getYMax() + (int) (player1.getVelocity() * 0.3));
   }
 }
Exemplo n.º 6
0
 public void scrollEnemies() {
   for (Enemy i : enemyList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
     i.setYPos(i.getYPos() + (int) (player1.getVelocity() * 0.3));
     i.setYMax(i.getYMax() + (int) (player1.getVelocity() * 0.3));
   }
 }
Exemplo n.º 7
0
 public void keyReleased(KeyEvent evt) {
   keys[evt.getKeyCode()] = false;
   // reset the counters for for the sprite s
   player1.resetCounter();
   if (!player1.getPower().equals("Balloon")) {
     player1.resetPicCounter();
   }
 }
Exemplo n.º 8
0
 public void loseCoins() {
   int x = player1.getX();
   int y = player1.getY();
   double losePercentage = 0.1;
   for (int i = 0;
       i < (int) coins * losePercentage;
       i++) { // makes the user lose 10 percent of the coin and draws them in a circle
     // System.out.println(i);
     int xPos = x + (int) (100 * Math.cos(Math.toRadians((360 / (coins * losePercentage)) * i)));
     int yPos = y - (int) (100 * Math.sin(Math.toRadians((360 / (coins * losePercentage)) * i)));
     coinList.add(new Coin(xPos, yPos, 3));
   }
   coins -= (int) (coins * losePercentage);
 }
Exemplo n.º 9
0
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 public String getPowerUp() {
   if (!player1.getPower().equals("")) {
     return ("P1");
   } else {
     return "none";
   }
 }
Exemplo n.º 10
0
  public void keyPressed(KeyEvent key) {

    if (key.getKeyCode() == 37) {

      leftcheck = true;
      player.ta = -changet;
    }

    if (key.getKeyCode() == 39) {

      rightcheck = true;
      player.ta = changet;
    }

    if (key.getKeyCode() == 32) {

      grav = true;
    }
  }
Exemplo n.º 11
0
 public void checkJumperCollision() {
   // same as all the other collsions
   for (Jumper j : jumperList) {
     if (j.getOnScreen()) { //
       if (j.checkCollision(j.getImage(), player1)) {
         player1.setVelo(50);
         player1.setDown(false);
         if (musicOn) {
           bounce.play();
         }
       }
     } else {
       jRemove.add(j);
     }
   }
   for (Jumper j : jRemove) {
     jumperList.remove(j);
   }
   jRemove = new ArrayList<Jumper>();
 }
Exemplo n.º 12
0
 public void checkSpikeCollision() { // checks the spike collision
   for (Spikes s : spikeList) {
     if (s.getOnScreen()) { // if the spike is on the screen
       if (s.checkCollision(s.getImage(), player1)) { // if the user collides with the spike
         if (player1.getInvi() == false) { // if player is not invisiblity
           player1.setSpikeVelo(); // set the spike velocity
           loseCoins();
           player1.setDown(true);
         }
         spRemove.add(s);
       }
     } else {
       spRemove.add(s); // remove the spike
     }
   }
   for (Spikes s : spRemove) {
     spikeList.remove(s);
   }
   spRemove = new ArrayList<Spikes>();
 }
Exemplo n.º 13
0
  public BlackHole() {

    Container window = getContentPane();
    window.setLayout(new BorderLayout());

    panel = new JPanel(null);

    label = new JLabel("Planet Health: " + healthStr, JLabel.CENTER);
    label.setBounds(0, 500, 1000, 50);

    panel.add(label);
    window.add(panel, BorderLayout.CENTER);

    addKeyListener(this);
    addMouseListener(this);
    setSize(1000, 600);
    setFocusable(true);
    setTitle("Black Hole");
    setVisible(true);

    player = new Player();
    player.xc = centerx;
    player.yc = centery;
    player.t = -Math.PI / 2;
    player.r = 950;
    player.convert();

    ball = new Ball[10];

    ballCount++;
    ball[1] = new Ball();
    ball[1].r = centery;
    ball[1].t = -Math.PI / 2;
    ball[1].xc = centerx;
    ball[1].yc = centery;

    timer = new Timer(20, this);
    timer.start();

    repaint();
  }
Exemplo n.º 14
0
  public void checkPupCollision() {
    // pretty much the same thing as before, however it alsoe does the powerup effects
    for (Powerup p : pupList) {
      if (p.getOnScreen()) { // can be removed later on
        if (p.checkCollision(player1)) {
          pupRemove.add(p);
          player1.setPower(p.getType());
          player1.setVelo(50);
        }
      } else {
        pupRemove.add(p);
      }
    }
    if (player1.getPower().equals("Lucky")) { // changes everything to stars
      for (Coin c : coinList) {
        starList.add(new Star(c.getX(), c.getY(), 2));
        cRemove.add(c);
      }
      for (Box b : boxList) {
        starList.add(new Star(b.getX(), b.getY(), 2));
        bRemove.add(b);
      }
      for (Enemy e : enemyList) {
        starList.add(new Star(e.getX(), e.getY(), 2));
        eRemove.add(e);
      }
    } else if (player1.getPower().equals("Magnet")) { // moves the coins towards the player
      for (Coin c : coinList) {
        c.moveTowards(player1);
      }
    } else { // else do nothing

    }
    for (Powerup p : pupRemove) {
      poofList.add(new Poof(p.getX(), p.getY(), 2));
      pupList.remove(p);
    }
    pupRemove = new ArrayList<Powerup>();
  }
Exemplo n.º 15
0
 public void DrawEveryThing(Graphics g) {
   moveLayerOne(g); // moves the background makes it parallax scrolling
   moveLayerTwo(g); // the decorations
   drawPowerUpEffect(g); // draws the powerup effect
   moveLayerThree(g); // moves all the other stuff
   newPattern(); // makes a new PAttern
   newDecos(); // makes new decorations
   atLevel();
   levelUp(); // changes the level
   checkAllCollisions();
   removePoof(); // remove the poofs
   moveEverything(); // moves everything
   player1.changeVelocity();
 }
Exemplo n.º 16
0
 public void checkBoxCollision() { // pretty much the same thing as all the other collisions
   for (Box b : boxList) {
     if (b.getOnScreen()) { // checks if its on the screen
       if (b.checkCollision(b.getImage(), player1)) {
         player1.setVelo(50);
         player1.setDown(false);
         b.setPcount(
             b.getPcount() - 1); // sets the type to one less so then you can  bounce on it twice
         if (b.getPcount() == 0) {
           bRemove.add(b); // removes the box
         }
         if (musicOn) {
           bounce.play();
         }
       }
     } else {
       bRemove.add(b);
     }
   }
   for (Box b : bRemove) {
     boxList.remove(b);
   }
   bRemove = new ArrayList<Box>();
 }
Exemplo n.º 17
0
 public void checkCoinCollision() {
   for (Coin c : coinList) {
     if (c.getOnScreen()) { // check if the coin is on the screen
       if (c.checkCollision(
           c.getPics().get(c.getCounter()), player1)) { // if the player collides with the coin
         cRemove.add(c); // remove the coin
         player1.setVelo(50); // set the velocity so the player moves up
         player1.setDown(false); // set the down false (players moving up)
         coins += c.getValue(); // check the coins collected
         score += c.getPoints(); // get the score
         if (musicOn) {
           coinSound.play(); // play the sound
         }
       }
     } else {
       cRemove.add(c); // remove the coin
     }
   }
   for (Coin c : cRemove) {
     poofList.add(new Poof(c.getX(), c.getY(), 0));
     coinList.remove(c);
   }
   cRemove = new ArrayList<Coin>();
 }
Exemplo n.º 18
0
  public void actionPerformed(ActionEvent evt) {

    if (evt.getSource() == timer) {

      player.physics();

      k = 1;
      while (k <= ballCount) {

        ball[k].physics(player.x, player.y, player.size);
        if (ball[k].r < centery - 500 + ball[k].size / 2) {
          health = health - (int) ball[k].size;
          ball[k].r = centery;
          ball[k].t = -Math.PI / 2;
        }
        k++;

        if (grav) {

          k = 1;
          while (k <= ballCount) {
            ball[k].grav();
            k++;
          }

        } else {

          k = 1;
          while (k <= ballCount) {
            ball[k].antiGrav();
            k++;
          }
        }

        k = 1;
        while (k <= ballCount) {

          ball[k].physicsXY();
          k++;
        }

        healthStr = Integer.toString(health) + "%";
        label.setText("Planet Health: " + healthStr);

        repaint();
      }
    }
  }
Exemplo n.º 19
0
 public void drawPowerUpIcon(Graphics g) {
   // draws the powerup the player has on the top
   if (player1.getPower().equals("Umbrella")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/UmbrellaSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Ball")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/BallSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Boost")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/BoostSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Balloon")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/BalloonSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Sheild")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/SheildSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Magnet")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/MagnetSymbol.png").getImage(), 200, 10, this);
   } else {
     g.drawImage(new ImageIcon("gamelayerstuff/powerupbox.png").getImage(), 200, 10, this);
   }
 }
Exemplo n.º 20
0
 public void scrollJumpers() {
   for (Jumper i : jumperList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
   }
 }
Exemplo n.º 21
0
 public void moveLayerThree(Graphics g) {
   backy += (int) (player1.getVelocity() * 0.1);
   midy += (int) (player1.getVelocity() * 0.5);
   drawEnemy(g);
   drawCoin(g);
   drawBox(g);
   drawPoof(g);
   drawStar(g);
   drawJumper(g);
   drawSpike(g);
   drawPup(g);
   if (backy <= dieHeight) {
     // System.out.println(die);
     g.drawImage(player1.move(2), player1.getX(), player1.getY(), this);
     if (player1.animationComplete()) {
       die = true;
     }
   } else {
     if (backy <= dieHeight) {
       player1.resetCounter();
     }
     if (keys[KeyEvent.VK_RIGHT]) {
       g.drawImage(player1.move(1), player1.getX(), player1.getY(), this);
     } else if (keys[KeyEvent.VK_LEFT]) {
       g.drawImage(player1.move(-1), player1.getX(), player1.getY(), this);
     } else {
       g.drawImage(player1.move(0), player1.getX(), player1.getY(), this);
     }
   }
 }
Exemplo n.º 22
0
 public void scrollRects() {
   for (Rectangle i : rectList) {
     i.setLocation((int) (i.getX()), (int) (i.getY() + (int) (player1.getVelocity() * 0.3)));
   }
 }
Exemplo n.º 23
0
 public void scrollPoofs() {
   for (Poof i : poofList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
   }
 }
Exemplo n.º 24
0
 public void scrollPowerUps() {
   for (Powerup i : pupList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
   }
 }
Exemplo n.º 25
0
 public void scrollDecorations() {
   for (Decorations i : decoList) {
     i.setY(i.getYTop() + (int) (player1.getVelocity() * 0.45));
   }
 }
Exemplo n.º 26
0
 public void drawPowerUpEffect(Graphics g) {
   if (player1.getPower().equals("Magnet")) {
     Image magpic = magnetList.get((int) count % 6);
     g.drawImage(
         magpic,
         player1.getX() - ((magpic.getWidth(null) - player1.getWidth()) / 2),
         player1.getY() - ((magpic.getHeight(null) - player1.getHeight()) / 2),
         magpic.getWidth(null),
         magpic.getHeight(null),
         this);
     count += 0.1;
   } else if (player1.getPower().equals("Ball")) {
     g.drawImage(
         ballPower,
         player1.getX() - ballPower.getWidth(null) / 2 + 17,
         player1.getY() + player1.getHeight() - 20,
         ballPower.getWidth(null),
         ballPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("Sheild")) {
     g.drawImage(
         sheildPower,
         player1.getX() - ((sheildPower.getWidth(null) - player1.getWidth()) / 2),
         player1.getY() - ((sheildPower.getHeight(null) - player1.getHeight()) / 2),
         sheildPower.getWidth(null),
         sheildPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("Umbrella")) {
     g.drawImage(
         umbrellaPower,
         player1.getX() - (umbrellaPower.getWidth(null) / 2) + 20,
         player1.getY() - umbrellaPower.getHeight(null) + 40,
         umbrellaPower.getWidth(null),
         umbrellaPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("")) {
   }
 }
Exemplo n.º 27
0
 public void scrollStars() {
   for (Star i : starList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
   }
 }
Exemplo n.º 28
0
 public void scrollBoxes() {
   for (Box i : boxList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
   }
 }
Exemplo n.º 29
0
  public void createLayout() {
    top = new JPanel();
    wModel.panel.add(top, BorderLayout.NORTH);
    top.setLayout(new BorderLayout(0, 0));

    bottom = new JPanel();
    wModel.panel.add(bottom, BorderLayout.SOUTH);
    bottom.setLayout(new BorderLayout(0, 0));

    center = new JPanel();
    wModel.panel.add(center, BorderLayout.CENTER);
    center.setLayout(new BorderLayout(0, 0));

    // Spielfeld
    gameField = new JPanel();
    gameField.setPreferredSize(new Dimension(550, 800));
    wModel.panel.add(gameField, BorderLayout.WEST);
    gameField.setLayout(new GridLayout(4, 4, 5, 5));

    /**
     * *********************************************************** Sidebar
     * ************************************************************
     */
    dates = new JPanel();
    dates.setLayout(new BorderLayout());
    JLabel background = new JLabel(new ImageIcon("../gfx/datesBack.png"));
    dates.add(background);

    GridBagLayoutModel gblModel = new GridBagLayoutModel();
    GridBagLayout gbl = new GridBagLayout();
    background.setLayout(gbl);

    l1 = new JLabel(new ImageIcon("../gfx/spieler1.png"));
    points1 = new JLabel(new ImageIcon("../gfx/punkte.png"));
    points1Num = new JLabel("0");
    l2 = new JLabel(new ImageIcon("../gfx/spieler2.png"));
    points2 = new JLabel(new ImageIcon("../gfx/punkte.png"));
    points2Num = new JLabel("0");

    JLabel namePlayer1 = new JLabel(player1.getName());
    JLabel namePlayer2 = new JLabel(player2.getName());

    JButton end = new JButton("Beenden");

    gblModel.addComponent(background, gbl, l1, 0, 2, 1, 1, 1.0, 0.5);
    gblModel.addComponent(background, gbl, namePlayer1, 1, 2, 1, 1, 1.0, 0.5);
    gblModel.addComponent(background, gbl, points1, 0, 3, 1, 1, 1.0, 0.2);
    gblModel.addComponent(background, gbl, points1Num, 1, 3, 1, 1, 1.0, 0.2);
    gblModel.addComponent(background, gbl, l2, 0, 4, 1, 1, 1.0, 1.0);
    gblModel.addComponent(background, gbl, namePlayer2, 1, 4, 1, 1, 1.0, 1.0);
    gblModel.addComponent(background, gbl, points2, 0, 5, 1, 1, 1.0, 0.2);
    gblModel.addComponent(background, gbl, points2Num, 1, 5, 1, 1, 1.0, 0.2);
    gblModel.addComponent(background, gbl, end, 1, 6, 1, 1, 0.0, 0.2);

    wModel.panel.add(dates, BorderLayout.EAST);

    end.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
  }
Exemplo n.º 30
0
 public void scrollSpikes() {
   for (Spikes i : spikeList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
   }
 }