This site requires JavaScript, please enable it in your browser!
Greenfoot back
gquach
gquach wrote ...

2013/5/29

how to make ghost die properly until it reaches ghost healer?

gquach gquach

2013/5/29

#
when a scared ghost is eaten by the ladybug named Clara, it was dead- but for a short time where it doesn't intersect the ghost healer, to not be dead nor scared. How could you make the scared ghost be dead until it reaches the ghost healer, ignoring the fact of the ghost being scared or not? Note: isToMyRight(), isToMyLeft(), isAboveMe(), and isBelowMe() is relative to the direction of the screen, not the ghost itself
 final boolean IS_DEBUG_MODE_ON = true;
  boolean dead = true;
  public boolean scared = true;
  boolean animation = true;
    /**
     * Act method, runs on every frame
     */
    public void act()
    {
        int k = 2;
        Random randomWay = new Random();
        randomWay.nextBoolean();
        randomWay.nextInt();
        int seed = 4;
          randomWay.setSeed ( 4 );
          
      //This is the start of ghost exitting ghostwall    
      if ( isToMyRight( getGhostHealer() ) )
         {
                  setDirection( "right" );
          if ( intersects( getGhostHealer() ) && !treeAbove() )
            setDirection( "up" );
                 treeUpWest();  
             if ( treeFront() )
               treeDownWest();
       }
               else 
        if ( isToMyLeft( getGhostHealer() ) )
         {
              setDirection( "left" );
             if ( intersects( getGhostHealer() ) && !treeAbove() )
               setDirection( "up" );                           
                    treeUpEast();
                    if ( treeFront() )
                     treeDownEast();    
                   }    
            
       if ( treeBelow() && treeToRight() )
        {
        setDirection( "up" );
        getClara();
             }
        else
        setDirection( "left" );
            
      if ( treeAbove() && treeBelow() )
        setDirection( "left" );
        else
        setDirection( "up" );
       
     nwDown();
     int Way = Greenfoot.getRandomNumber(1);
    boolean way = ( Greenfoot.getRandomNumber(2) == 1) ? true : false;
                    
    if ( !isBelowMe( getGhostHealer() ) && isToMyRight( getGhostHealer() ) || isToMyLeft( getGhostHealer() ) && isBelowMe( getClara() ) )
    {
        if ( treeToRight() && treeToLeft() )
          setDirection( "down" );
          }
     if ( !isScared() && !intersects( getClara() ) )
     animate();
      if ( intersects( getClara() ) && !isScared() )
      {
       makeClaraDead(); // this is for ghost to make Clara dead when they intersect Clara nor scared, nor dead
       isClaraDead();
                     }
        if ( isScared() && !intersects( getClara() ) ){
          animateScared();
          int Go = Greenfoot.getRandomNumber(7);  
             if ( isToMyRight( getGhostHealer() ) || isBelowMe( getGhostHealer() ) )
              {
           if ( treeToLeft() && treeToRight() )
             setDirection("down" );
           if ( treeBelow() && treeToLeft() ) 
                setDirection( "right" );         
          }
          if ( isToMyLeft( getGhostHealer() ) || isBelowMe( getGhostHealer() ) )
           {
           if ( treeToLeft() && treeToRight() )
             setDirection("down" );
                 
           if ( treeBelow() && treeToRight() ) 
              setDirection( "left" );
                 }
          bugBelow();
           bugAbove();  
           if ( isToMyRight( getClara() ) && treeBelow() && treeToLeft() )
           setDirection( "up" );
           else 
            if ( isToMyRight( getClara() ) && treeAbove() && treeToLeft() )
            setDirection( "down" );
           else
          if ( isToMyRight( getClara() ) && treeToLeft() && !treeAbove() && !treeBelow() )
           setDirection( "down" );
           else 
           if ( isToMyRight( getClara() ) && !treeToLeft() && treeAbove() && treeBelow() )
           setDirection( "left" );
           downRight();  
        }
        
        if ( intersects( getClara() ) && isScared() )
           {
         playGhostEatenSound(); //when ghost is scared and intersects Clara it dies
          animateDead(); 
   if ( dead && isScared() || isBelowMe( getClara() ) || isAboveMe( getClara() ) || isToMyRight( getClara() ) || isToMyLeft( getClara() ) || intersects( getClara() ) )
   {
           animateDead();
           getGhostHealer();
            if ( isToMyRight( getGhostHealer() ) || isBelowMe( getGhostHealer() ) )
              {
           if ( treeToLeft() && treeToRight() )
             setDirection("down" );
           if ( treeBelow() && treeToLeft() ) 
                setDirection( "right" );         
          }
          if ( isToMyLeft( getGhostHealer() ) || isBelowMe( getGhostHealer() ) )
           {
           if ( treeToLeft() && treeToRight() )
             setDirection("down" );
                 
           if ( treeBelow() && treeToRight() ) 
              setDirection( "left" );
                 }
          bugBelow();
           bugAbove();  
           if ( isToMyRight( getClara() ) && treeBelow() && treeToLeft() )
           setDirection( "up" );
           else 
            if ( isToMyRight( getClara() ) && treeAbove() && treeToLeft() )
            setDirection( "down" );
           else
          if ( isToMyRight( getClara() ) && treeToLeft() && !treeAbove() && !treeBelow() )
           setDirection( "down" );
           else 
           if ( isToMyRight( getClara() ) && !treeToLeft() && treeAbove() && treeBelow() )
           setDirection( "left" );
           downRight();
       }
                   else
   if ( dead && !isScared() && isBelowMe( getClara() ) || isAboveMe( getClara() ) || isToMyLeft( getClara() ) || isToMyRight( getClara() ) || intersects( getClara() ))
          {
        animateDead(); //when ghost is dead during time it's not scared, where ghost death don't affect Clara to die
           if ( isToMyRight( getGhostHealer() ) || isBelowMe( getGhostHealer() ) )
       {
           if ( treeToLeft() && treeToRight() )
             setDirection("down" );
               if ( treeBelow() && treeToLeft() ) 
                setDirection( "right" );         
       }
       if ( isToMyLeft( getGhostHealer() ) || isBelowMe( getGhostHealer() ) )
       {
           if ( treeToLeft() && treeToRight() )
             setDirection("down" );
                 
           if ( treeBelow() && treeToRight() ) 
              setDirection( "left" );
                 }
              
        bugBelow();
        bugAbove();
           
        if ( isToMyRight( getClara() ) && treeBelow() && treeToLeft() )
         setDirection( "up" );
        else 
         if ( isToMyRight( getClara() ) && treeAbove() && treeToLeft() )
         setDirection( "down" );
        else
       if ( isToMyRight( getClara() ) && treeToLeft() && !treeAbove() && !treeBelow() )
        setDirection( "down" );
        else 
        if ( isToMyRight( getClara() ) && !treeToLeft() && treeAbove() && treeBelow() )
        setDirection( "left" );
        
                     }  

    }
       
         
if ( intersects( getGhostHealer() ) )
{ 
  if ( !isScared() || !dead )
      setDirection( "up" );
 }
 wrapAroundWorld();
     if ( !isPacmanIntroStillPlaying() )   
        move( k );  
                   
          //Make the Ghost do things here    
    //Give the Ghost functions here   
}

void stayDead()
{
if ( dead )
animateDead();
}

void bugBelow()
{
   if ( isBelowMe( getClara() ) && !treeAbove() )
        setDirection( "up" );
       else 
       if ( isBelowMe( getClara() ) && treeAbove() && treeToRight() )
       setDirection( "left" );
       else 
       if ( isBelowMe( getClara() ) && treeAbove() && treeToLeft() )
       setDirection( "right" );
       else
       if ( isBelowMe( getClara() ) && treeAbove() && !treeToLeft() && !treeToRight() )
       setDirection( "right" );
}

void bugAbove()
{
   if ( isAboveMe( getClara() ) && !treeBelow() )
        setDirection( "down" );
       else 
       if ( isAboveMe( getClara() ) && treeBelow() && treeToRight() )
       setDirection( "left" );
       else 
       if ( isAboveMe( getClara() ) && treeBelow() && treeToLeft() )
       setDirection( "right" );
       else
       if ( isAboveMe( getClara() ) && treeBelow() && !treeToLeft() && !treeToRight() )
       setDirection( "right" );
}

void bugLeft() 
{
 if ( isToMyLeft( getClara() ) && !treeToRight() )
         setDirection( "right" );
         else 
        if ( isToMyLeft( getClara() ) && treeBelow() && treeToRight() )
         setDirection( "up" );
         else 
         if ( isToMyLeft( getClara() ) && treeAbove() && treeToRight() )
         setDirection( "down" );
        else
        if ( isToMyLeft( getClara() ) && treeToRight() && !treeAbove() && !treeBelow() )
          setDirection( "down" );
}
 /*
  * pre-condition: tree at front and tree at right of ghost
  * post-condition: ghost moves down.
  */
  void neDown()
  {
    if ( treeAbove() && treeToRight() )
     {
           setDirection( "down" );
           getClara();
         if ( treeToLeft() && treeToRight() )
           setDirection( "down" );
         }  
    }
 /*
  * pre-condition: tree at front and tree at right of ghost
  * post-condition: ghost moves left.
  */
    void neLeft()
      {
    if ( treeAbove() && treeToRight() )
     {
           setDirection( "left" );
           getClara();
      if ( treeAbove() && treeBelow() )
          setDirection( "left" );
        }  
    }
    /*
     * pre-condition: tree at front and tree at left of ghost
     * post-condition: ghost moves down.
     */
    void nwDown()
    {
     if ( treeAbove() && treeToLeft() && !treeBelow() && !treeToRight() )
         {
            setDirection( "down" );
             getClara();
      if ( treeToLeft() && treeToRight() && !treeAbove() && !treeFront() )
           setDirection( "down" );
          }    
    }
    
    /*
     * pre-condition: tree at front and tree at left of ghost
     * post-condition: ghost moves right.
     */
    void nwRight()
    {
     if ( treeAbove() && treeToLeft() && !treeBelow() && !treeToRight() )
         {
             setDirection( "right" );
             getClara();
      if ( treeAbove() && treeBelow() )
         setDirection( "right" );
                }    
    }
    
    /*
     * pre-condition: tree below and tree at right of ghost
     * post-condition: ghost moves up.
     */
    void seUp()
    {
     if ( treeBelow() && treeToRight() )
         {
             setDirection( "up" );
             getClara();
      if ( treeToLeft() && treeToRight() )
        setDirection( "up" );
                 }       
    }
    
    /*
     * pre-condition: tree below and tree at right of ghost
     * post-condition: ghost moves left.
     */
     void seLeft()
    {
     if ( treeBelow() && treeToRight() )
         {
             setDirection( "left" );
             getClara();
      if ( treeBelow() && treeAbove() )
        setDirection( "left" );
      }     
    }
    
    /*
     * pre-condition: tree below and tree at left of ghost
     * post-condition: ghost moves up.
     */
    void swUp()
    {
     if ( treeBelow() && treeToLeft() )
         {
             setDirection( "up" );
             getClara();
      if ( treeToLeft() && treeToRight() )
            setDirection( "up" );
                  }          
    }
    
    /*
     * pre-condition: tree below and tree at left of ghost
     * post-condition: ghost moves right.
     */
     void swRight()
    {
     if ( treeBelow() && treeToLeft() )
         {
             setDirection( "right" );
             getClara();
      if ( treeAbove() && treeBelow() )
        setDirection( "right" );
            }          
    }
    
  /*
   * pre-condition: tree below and tree above of ghost,or tree below and tree at left of ghost
   * post-condition: ghost moves left if tree below and tree above of ghost. Also, ghost moves up if tree below and tree at left of ghost
   */  
void leftUp()
{
if ( treeAbove() && treeBelow() )
setDirection( "left" );
if ( treeToLeft() && treeBelow() )
setDirection( "up" );
}

  /*
   * pre-condition: tree at right and left of ghost,or tree above and tree at right of ghost
   * post-condition: ghost moves up if tree at right and left of ghost. Also, ghost moves left if tree above and tree at right of ghost
   */  
void upLeft()
{
if ( treeToLeft() && treeToRight() )
setDirection( "up" );
if ( treeToRight() && treeAbove() )
setDirection( "left" );
}

  /*
   * pre-condition: tree above and below of ghost,or tree below and tree at right of ghost
   * post-condition: ghost moves right if tree above and below of ghost. Also, ghost moves up if tree below and tree at right of ghost
   */  
void rightUp()
{
if ( treeAbove() && treeBelow() )
setDirection( "right" );
if ( treeToRight() && treeBelow() )
setDirection( "up" );
}


void rightDown()
{
if ( treeAbove() && treeBelow() )
{
setDirection( "right" );
getDirection();
 }
if ( treeToRight() && treeAbove() )
{
setDirection( "down" );
 getDirection();
 }
}

void downRight() 
{
if ( treeToLeft() && treeToRight() )
{
setDirection( "down" );
getDirection();
 }
if ( treeBelow() && treeToLeft() )
{
setDirection( "right" );
 getDirection();
  }
}

 void treeUpEast()
 {
    if ( treeAbove() && !treeBelow() && !treeToLeft() && !treeToRight() && treeFront() )
    {
    int Way = Greenfoot.getRandomNumber(1);
      setDirection( "right" );
    }
     else 
    setDirection( "up" );
}

 void treeUpWest()
 {
    if ( treeAbove() && !treeBelow() && !treeToLeft() && !treeToRight() && treeFront() )
    {
    int Way = Greenfoot.getRandomNumber(3);
     setDirection( "left" );
    }
       else 
    setDirection( "up" );
}
void treeDownEast()
{
 if ( treeBelow() && !treeAbove() && !treeToLeft() && !treeToRight() && treeFront() )
    setDirection( "right" );
      else 
    setDirection( "down" );
}

 void treeDownWest()
 {
    if ( treeBelow() && !treeAbove() && !treeToLeft() && !treeToRight() && treeFront() )
     setDirection( "left" );
     else 
    setDirection( "down" );
}

}
Kartoffelbrot Kartoffelbrot

2013/5/29

#
if(getOneIntersectingObject(GhostHealer.class)!=null)
{
dead=true;
}
You need to login to post a reply.