Exemple #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();
 }
Exemple #2
0
 /** Fires weapons when left mouse is pressed */
 public void mousePressed(MouseEvent evt) {
   int mx = evt.getX(); // x-coordinate where user clicked.
   int my = evt.getY(); // y-coordinate where user clicked.
   if (!pause) {
     if (!evt.isMetaDown()) {
       if (weapons[guntrack].equals("gun") && bshoot) {
         weaponList.add(
             new Bullet(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 7));
         bshoot = false;
         ammo.useBullet();
         bulletTime.restart();
       }
       if (weapons[guntrack].equals("grenade") && gshoot) {
         weaponList.add(
             new Grenade(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 12));
         gshoot = false;
         ammo.useGrenade();
         grenadeTime.restart();
       }
       if (weapons[guntrack].equals("laser") && lshoot) {
         weaponList.add(
             new Laser(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 20));
         lshoot = false;
         ammo.useLaser();
         laserTime.restart();
       }
       if (weapons[guntrack].equals("shotgun") && sgshoot) {
         weaponList.add(
             new ShotGun(
                 mx,
                 my,
                 character.getX(),
                 character.getY(),
                 0,
                 THA.WIDTH,
                 0,
                 THA.HEIGHT,
                 7,
                 character.getX(),
                 character.getY(),
                 25,
                 90,
                 weaponList));
         sgshoot = false;
         ammo.useShotgun();
         shotgunTime.restart();
       }
     }
   }
 }