Esempio n. 1
0
  public void
      checkTPress() // this method whether T key is being pressed o not and move the object
                    // according do following.
      {
    if (alive) // check if the ship alive
    {
      DeepSpace myDeepSpace = (DeepSpace) getWorld(); // get referance to the DeepSpace class
      FuelTank myFuelTank =
          myDeepSpace
              .myFuelTank(); // use myFuelTank method that return reference of FuelTank class. So
                             // you can call method of Fueltank class.

      if (Greenfoot.isKeyDown("t")
          && !myFuelTank
              .empty()) // if "t" key is being pressed by user and if i have enough fuel, do
                        // following.
      {

        move(3); // move forward direction of object
        setImage("rocket.png"); // set the image rocket that seems like burning fuel.
        myFuelTank
            .burn(); // call the Fueltank class method in order to decrese level of fuel on screen
      } else
        setImage("rocket_noThrust.png"); // if no key is being press than set the regular picture.
    }
  }
Esempio n. 2
0
  public void checkBetWeenTwoMarkers() {
    if (alive) // check if the object alive
    {
      DeepSpace myDeepSpace = (DeepSpace) getWorld(); // get referance to the DeepSpace Class

      if (getX() == 799
          && getY() > myDeepSpace.getExitMarkerTop()
          && myDeepSpace.getExitMarkerBottom()
              > getY()) // check that if we are right side of the world and between two markers than
                        // do following
      {
        setImage("balloon2.png"); // set the baloon image
        baloonCount--; // start counting. we do these because it simulates the baloon picture for
                       // little time for the user.

        if (baloonCount
            < 1) // if little time passed over than remove the object from the world and call the
                 // greenfooot stop method.
        {
          getWorld().removeObject(this);
          return;
          // Greenfoot.stop();
        }
      }

      if ((getX() == 799 && 0 < getY() && getY() < myDeepSpace.getExitMarkerTop())
          || (getX() == 799 && 600 > getY() && getY() > myDeepSpace.getExitMarkerBottom()))
      // if the ship between top of the right corner and top marker than do fallowing  OR if the
      // ship between bottom of the right corner and bottom marker than do fallowing
      {
        setImage(
            "explosion.gif"); // set the image as Explosion in order to simulate explosion for the
                              // user.
        baloonCount--; // increase the baloonCount variable in order to slowly remove the object
                       // from the world

        if (baloonCount < 1) // if little time has passed than remove the obejct.
        {

          getWorld().removeObject(this);
          return; // leave the function.
          // Greenfoot.stop();
        }
      }
    }
  }