Esempio n. 1
0
 private void addDish() {
   foodTimerDiff = (System.nanoTime() - foodTimer) / 1000000;
   if (foodTimerDiff > foodDelay) { // there will be a 88% chance the next dish will be food
     double chance = Math.random();
     int rail = (int) Math.round(Math.random() * 2);
     if (chance < foodprobability) {
       String food = foodList.get((int) (Math.random() * foodList.size()) % foodList.size());
       Food f = new Food(food, rail, foodValues.get(food));
       f.setPositionInRail(player.getx() + GamePanel.WIDTH + f.getWidth() / 2, rail);
       f.setCamera(camera);
       dishes.add(f);
     } else {
       String power = powerList.get((int) (Math.random() * powerList.size()) % powerList.size());
       Power p = new Power(power, rail);
       p.setPositionInRail(player.getx() + GamePanel.WIDTH + p.getWidth() / 2, rail);
       p.setCamera(camera);
       dishes.add(p);
     }
     foodTimer = System.nanoTime();
     if (difficulty == OptionsState.EASY)
       foodDelay = (long) (Math.random() * fooddelays[0]) + fooddelays[1];
     if (difficulty == OptionsState.NORMAL)
       foodDelay = (long) (Math.random() * fooddelays[2]) + fooddelays[3];
     if (difficulty == OptionsState.HARD)
       foodDelay = (long) (Math.random() * fooddelays[4]) + fooddelays[5];
   }
 }
Esempio n. 2
0
 private void collisionDetection() {
   for (int i = 0; i < dishes.size(); i++) {
     Dish d = dishes.get(i);
     if (player.eats(d)) {
       if (d instanceof Food) {
         Food f = (Food) d;
         player.changeCholesterol(f.getValue());
       }
       if (d instanceof Power) {
         Power p = (Power) d;
         player.setPower(p);
       }
       dishes.remove(i);
       i--;
     }
   }
 }