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

2013/5/9

how to move ghosts randomly, where you're not allowed to control them?

gquach gquach

2013/5/9

#
i was given commands, treeToRight(), treeToLeft(), treeBelow(), and treeAbove() i wanted the ghost to move separately later on, after hitting a tree above but can't, how can you do it? here's my code:
  
   public void act()
    {
  int k = 2;
       
      if ( isToMyRight( getGhostHealer() ) )
         {
          setDirection( "right" );
          animate();  
        if ( intersects( getGhostHealer() ) && !treeAbove() )
         {
          setDirection( "up" );
            left();
           getDirection();
          treeDownWest();
             }       
            }
                else 
        if ( isToMyLeft( getGhostHealer() ) )
         {
              setDirection( "left" );
              animate(); 
             if ( intersects( getGhostHealer() ) && !treeAbove() )
              {
              setDirection( "up" );     
               right();
                  treeDownEast();
                }
                   }    
       
                        
     if ( treeAbove() && treeToRight() )
     {
           setDirection( "down" );
           getClara();
      if ( treeToLeft() && treeToRight() )
       setDirection( "down" );
        }
        
     if ( treeAbove() && treeToLeft() )
         {
             setDirection( "down" );
             getClara();
      if ( treeToLeft() && treeToRight() )
       setDirection( "down" );
             }
                
        if ( treeBelow() && treeToRight() )
        {
        setDirection( "up" );
        getClara();
       }
        else
        setDirection( "left" );
       
       if ( treeAbove() && treeBelow() )
       setDirection( "left" );
       else
       setDirection( "up" );
}

void treeDownEast()
{
 if ( treeBelow() )
    setDirection( "right" );
      else 
    setDirection( "down" );
}

 void treeDownWest()
 {
    if ( treeBelow() )
     setDirection( "left" );
     else 
    setDirection( "down" );
}
You need to login to post a reply.