Exemplo n.º 1
1
 /** Checks the timers and start actions according to it */
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == buttonTimer) {
     // From the Btns class
     if (Btns.startB) {
       unPause();
       this.requestFocus();
     }
     if (Btns.pauseB) {
       pause();
       this.requestFocus();
     }
   }
   if (e.getSource() == fallTime) {
     shapes.get(0).fall(map, character);
     repaint();
     if (shapes.get(0).hitGround()) {
       map.addShape(shapes.get(0));
       map.clearLines();
       shapes.remove(0);
       addShape();
     }
   }
   if (e.getSource() == aiMove) {
     if (aiCommand.size() > 0) {
       shapes.get(0).aiCommand(map, aiCommand.get(0), shapeTrack);
       if (aiCommand.get(0) != 0) {
         shapeTrack.add(aiCommand.get(0));
       }
       aiCommand.remove(0);
       repaint();
     }
   }
   if (e.getSource() == moveTime) {
     character.checkUnderWater(water.getY());
     character.checkDeath(shapes.get(0).getShape());
     character.move(map, shapes.get(0));
     if (character.checkExit() == true) {
       MyFrame.screen = "gameover";
       pause();
       character.setDeath(false);
     }
     if (character.getDeath() == true) {
       pause();
       MyFrame.screen = "gameover";
       character.setDeath(false);
     }
   }
   if (e.getSource() == bulletMoveTime) {
     for (int i = 0; i < weaponList.size(); i++) {
       weaponList.get(i).move((int) character.getX(), (int) character.getY());
       if (!weaponList.get(i).getWeapon().equalsIgnoreCase("laser")) {
         int[] col = weaponList.get(i).collide(shapes.get(0), map);
         if (col[2] == 0) {
           map.change(
               weaponList
                   .get(i)
                   .damage(
                       map.getMap(),
                       col[1] / Square.SIZE,
                       col[0] / Square.SIZE,
                       THA.HEIGHT / Square.SIZE,
                       THA.WIDTH / Square.SIZE));
         } else if (col[2] == 1) {
           shapes
               .get(0)
               .change(
                   weaponList
                       .get(i)
                       .damage(
                           shapes.get(0).getShape(),
                           shapes.get(0).getIndex(col[0], col[1])[0],
                           shapes.get(0).getIndex(col[0], col[1])[1],
                           4,
                           4));
         }
         i = removeBullet(i);
         if (shapes.get(0).shapeGone()) {
           shapes.remove(0);
           addShape();
         }
       } else {
         map.change(
             weaponList
                 .get(i)
                 .damage(
                     map.getMap(),
                     (int) (character.getX() / Square.SIZE),
                     (int) (character.getY() / Square.SIZE),
                     THA.HEIGHT / Square.SIZE,
                     THA.WIDTH / Square.SIZE));
       }
       if (weaponList.get(i).getRemove() == true) {
         weaponList.remove(i);
       }
     }
   }
   if (System.currentTimeMillis() - startWater > 100 * 500 && startWater != 0) {
     if (e.getSource() == waterTime) {
       water.move();
     }
   }
   // delays for weapons
   if (e.getSource() == bulletTime) {
     bshoot = true;
   }
   if (e.getSource() == grenadeTime) {
     gshoot = true;
   }
   if (e.getSource() == laserTime) {
     lshoot = true;
   }
   if (e.getSource() == shotgunTime) {
     sgshoot = true;
   }
   repaint();
 }