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

2024/2/3

Need Help With Pacman in clara world

IcyCake242 IcyCake242

2024/2/3

#
I'm totally lost here on what to do...If anyone has done this before please guide me
IcyCake242 IcyCake242

2024/2/3

#
This is what I have written so far
/**
 * MyClara
 * 
 * Available functions (see Assignment document for explanations on what each function does):
 * treeFront, ghostWallFront,
 * getDirection, setDirection,
 * move,
 * makeScared, isScared,
 * animate, animateDead, 
 * onLeaf, removeLeaf, 
 * onMushroom, removeMushroom,
 * allLeavesEaten, 
 * isClaraDead,
 * playClaraDieSound, isClaraDieSoundStillPlaying,
 * playLeafEatenSound,
 * playPacmanIntro, isPacmanIntroStillPlaying,
 * wrapAroundWorld,
 * getCurrentLevelNumber, advanceToLevel
 */
class MyClara extends Clara
{
    // Please leave this first level here,
    // until after you've completed \"Part 12 -
    // Making and Adding Levels\"
    public final char[][] LEVEL_1 = {
            {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
            {'#','$','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','$','#'},
            {'#','.','#','#','.','#','.','#','#','#','#','#','.','#','.','#','#','.','#'},
            {'#','.','.','.','.','#','.','.','.','.','.','.','.','#','.','.','.','.','#'},
            {'#','#','#','#','.','#',' ','#','#','|','#','#',' ','#','.','#','#','#','#'},
            {' ',' ',' ',' ','.',' ',' ','#','%','?','%','#',' ',' ','.',' ',' ',' ',' '},
            {'#','#','#','#','.','#',' ','#','#','#','#','#',' ','#','.','#','#','#','#'},
            {'#','.','.','.','.','.','.','.','.','#','.','.','.','.','.','.','.','.','#'},
            {'#','.','#','#','.','#','#','#','.','#','.','#','#','#','.','#','#','.','#'},
            {'#','$','.','#','.','.','.','.','.','@','.','.','.','.','.','.','.','$','#'},
            {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}
        };
        
    // Movement constants
    public final String  UP = "up";    
    public final String  DOWN = "down";    
    public final String  LEFT = "left";    
    public final String  RIGHT = "right";        
    
    // Add and initialise Clara's variables here
    
    /**
     * Act method
     * 
     * Runs of every frame
     */
    public void act()
    {

        //Make Clara do things here
                if (Keyboard.isKeyDown(LEFT)){
            setDirection(LEFT);
        }
        if (Keyboard.isKeyDown(RIGHT)){
            setDirection(RIGHT);
        }
        if (Keyboard.isKeyDown(UP)){
            setDirection(UP);
        }
        if (Keyboard.isKeyDown(DOWN)){
            setDirection(DOWN);
        }
        move(3);
    
    if (onLeaf()){
removeLeaf();
playLeafEatenSound();
    
    }
    wrapAroundWorld();
    }
    
    //Give Clara functions here
}
You need to login to post a reply.