示例#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();
 }
示例#2
0
  public void loadWater() {
    System.out.println("Load water");

    water = Loader.load(assetManager, map, "water", false, Water.class);
    if (water == null) {
      water = new Water();
    }
    water.init(this, terrain, null, reflectNode);
  }
示例#3
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   map.drawMap(g);
   gs.imitate(shapes.get(0), map);
   gs.draw(g);
   if (shapes.size() > 0) shapes.get(0).draw(g);
   character.putCharacter(g); // draws the character
   for (int i = 0; i < weaponList.size(); i++) {
     weaponList.get(i).draw(g); // draws each weapon object
   }
   water.draw(g); // draws the water image
   g.setColor(Color.black);
   g.drawString("score: ", 300, 350);
 }
示例#4
0
  public MouseStatus getMouseCollision() {
    if (gui.isMouseOver()) {
      return null;
    }

    Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
    Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f);
    direction.subtractLocal(origin).normalizeLocal();

    Ray ray = new Ray(origin, direction);
    CollisionResults results = new CollisionResults();
    clickableNode.collideWith(ray, results);

    Vector3f v3f = null;
    Model m = null;

    if (results.size() > 0) {

      CollisionResult closest = results.getClosestCollision();
      Geometry g = closest.getGeometry();

      v3f = closest.getContactPoint();
      m = Model.Geometry2Model(g);

      // return new
      // MouseStatus(m,closest.getContactPoint().getX(),closest.getContactPoint().getZ());
    }

    if (water != null) {
      Vector3f waterv = water.collision(ray);
      if (waterv != null && (v3f == null || waterv.distance(origin) < v3f.distance(origin))) {
        v3f = waterv;
      }
    }

    if (v3f != null) return new MouseStatus(m, v3f.getX(), v3f.getZ());

    return null;
  }