/**
  * Uses an item on a game object.
  *
  * @param item the item to use
  * @param target the game object to be used on by the item
  * @return <tt>true</tt> if the "Use" action had been used on both the inventory item and the game
  *     object; otherwise <tt>false</tt>
  */
 public static boolean useItem(Item item, GameObject target) {
   if (item != null && target != null) {
     for (int i = 0, r = Random.nextInt(5, 8); i < r; i++) {
       if (!isItemSelected()) {
         if (item.interact("Use")) {
           for (int j = 0; j < 10 && !isItemSelected(); j++) {
             Task.sleep(100, 200);
           }
         } else {
           return false;
         }
       }
       // just make sure in case something bad happened
       if (isItemSelected()) {
         final String itemName = item.getName();
         final ObjectDefinition targetDef = target.getDef();
         final Model targetModel = target.getModel();
         if (targetDef != null && itemName != null && targetModel != null) {
           final String targetName = targetDef.getName();
           Mouse.move(targetModel.getNextPoint());
           final String action =
               "Use "
                   + itemName.replace("<col=ff9040>", "")
                   + " -> "
                   + targetName.replace("<col=ff9040>", "");
           for (int j = 0, s = Random.nextInt(5, 8); j < s; j++) {
             if (Menu.contains(action) && Menu.click(action)) {
               return true;
             } else {
               Mouse.move(targetModel.getNextPoint());
             }
           }
         }
         // kay, since that failed, let's try just use
         if (target.interact("Use")) {
           return true;
         }
       }
     }
   }
   return false;
 }
  /** Update the game logic related to aliens */
  public void doLogic() {
    // swap over horizontal movement and move down the
    // screen a bit
    //		dx = -dx;
    //		y += 10;
    //
    //		// if we've reached the bottom of the screen then the player
    //		// dies
    //		if (y > 570) {
    //			game.bothPlayers_notifyDeath();
    //		}

    currentAngle += moveSpeed;
    super.setRotatedAngle(currentAngle);
  }
  /**
   * Request that this alien moved based on time elapsed
   *
   * @param delta The time that has elapsed since last move
   */
  public void move(long delta) {
    // if we have reached the left hand side of the screen and
    // are moving left then request a logic update
    //		if ((dx < 0) && (x < 10)) {
    //			game.updateLogic();
    //		}
    //		// and vice vesa, if we have reached the right hand side of
    //		// the screen and are moving right, request a logic update
    //		if ((dx > 0) && (x > 750)) {
    //			game.updateLogic();
    //		}
    game.updateLogic();

    // proceed with normal move
    super.move(delta);
  }
Beispiel #4
0
 /**
  * Vil bli kalt hvis en kollisjon blir detektert.
  *
  * @param otherObject Det andre objektet i kollisjonen.
  */
 public void collide(GameObject otherObject) {
   otherObject.hit(_damage);
 }
Beispiel #5
0
 public void draw(Graphics2D g2) {
   if (!isDead) super.draw(g2);
   else g2.drawImage(imgExplosion.getImage(), getX(), getY(), null);
 }