コード例 #1
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>();
 }
コード例 #2
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>();
 }