The major assignment involves producing a pacman style game


The major assignment involves producing a Pacman style game with Clara using the Greenfoot files that are given to you.

Important Requirements

For your convenience, all important requirements specified in this brief are re-listed here:

- Clara and the Ghosts must be able to move from one side of the game to the other with the "wrapAroundWorld()" method
- Clara must be capable of being controlled with at least the arrow keys on the keyboard
- Clara must not move in the game until after an arrow key pressed
- Clara must stop before hitting trees or the ghost wall
- Clara must be able to eat leaves, and play the appropriate sound when doing so
- When all the leaves are eaten, the game must progress to the next level
- When each level starts the intro sound must be played once for each level and Clara and the Ghosts must not be able to move until after the intro sound has completed playing
- Ghosts must move slower than Clara when moving normally and when scared
- Ghosts must stop before hitting trees
- Ghosts must randomly decide on a direction to go in when they find themselves in an intersection
- When Clara and a Ghost collide, and the Ghost is neither dead nor scared, she must die, and play the appropriate sound
- When Clara is dead the player must not be able to continue controlling her
- Clara must be able to eat mushrooms, and this must make the Ghosts scared
- When the Ghosts are scared, they must run the appropriate animation
- When Clara and a Ghost collide, and the Ghost is scared, the Ghost must die, play the appropriate sound and play the appropriate animation
- When Ghosts are dead they must attempt to return to the Ghost Healer
- When Ghosts collide with the Ghost Healer they must no longer be dead
- You must make, at a minimum, one extra level
- All files must compile and the game must run.

Part 1 - Moving Clara and Keyboard Input

One of your first tasks - is to learn how to process keyboard input of the player by using Greenfoot.isKeyDown(String) method. Try passing the movement constants defined inside MyClara.java as input for Greenfoot.isKeyDown(String) and see what happens when you press the arrow keys. Try starting with using System.out.println() to print which of the keys was pressed to make yourself familiar with keyboard input.

Next thing for you to do - is to make sure that Clara can be controlled with the arrow keys. You may add extra functionality, such as controls for left handed players, but that is not compulsory. You will need to use Clara's "setDirection(String)" method, which can be sent one of the following commands; "up", "down", left" or "right" (a good idea is to use the same movement constants defined inside MyClara rather than using those String literals inside your code). Passing the aforementioned String values to setDirection(String) method will set Clara's direction to the command you specify.

Note that the "setDirection(String)" method will not change Clara to a specified direction if there is a tree in that direction. Once you're able to process keyboard input and make Clara respond to it by turning in the right direction - now it's time to make Clara move. In order to make Clara move, you will need to use the "move(int)" method. Note that it can be passed any integer, and that a bigger integer will make Clara move faster. The integer that it is passed will determine how fast Clara moves. It will be up to you to determine a suitable speed for Clara.

Please note that it is not a good programming practice to arbitrarily pass numbers to methods, and that it is always a good idea to instead, make a constant that will hold the value that you wish to pass.

Then you will need to somehow stop Clara from automatically moving at the start of the game, and only start continuously moving after a single key is pressed. Note that as per the original Pacman game, it is only necessary to stop Clara from moving before the initial key press, and that after that, it is perfectly acceptable to have Clara continuously move in the direction that was last selected.

Once you have determined, and tested, a suitable speed, you might notice Clara disappearing off the edge of the world. It is important that Clara, and the Ghosts, at some point call the method "wrapAroundWorld()" to deal with this issue. This will enable them to reappear on the opposite side of the world that they disappear off.

Part 2 - Animating Clara's Movement

In order to animate Clara, you will need to call the "animate()" method. You may notice, that if you just call the "animate()" method, that it cycles through Clara's animation very quickly. This is because every time the method is called, it advances Clara's animation to the next frame.

You will need to figure out a way of not calling it every time the act method is run, but every so many times that the act method is run.

HINT: If you are having trouble, try only calling "animate()" every second time the act method is called. Then try editing that attempt to work only every third time the act method is called. It will ultimately be up to you to determine what looks best.

Part 3 - Clara Collisions with Trees and Ghost Walls

Obviously, Clara really shouldn't be floating through the world; she should stop before hitting trees. She will also need to stop before hitting the Ghost Wall, as only the Ghosts are allowed to pass through it.

It will be up to you to figure out how to stop Clara from passing through either. HINT: You will need to use the "ghostWallFront()" method.

Part 4 - Eating Leaves and Winning

Clara will need to eat all of the leaves in order to win. First, she will need to be capable of eating leaves. If you are unsure of how
to do this, please revise practicals 1 and 2.

Once you've got Clara eating leaves, you'll need to play the right sound. To do so, you'll need to call the method "playLeafEatenSound()" at an appropriate point in your code.

When you have Clara happily eating leaves, you'll need to check that all leaves have been eaten and progress to the next level. You will need to use the "allLeavesEaten()", "advanceToLevel(char[][])" and "getCurrentLevelNumber()" methods. You will need to somehow check what the current level is, and either advance to the next available level, or, if there are no more available levels, advance back to the first level again.

Note that if you wish to return back to the first level, all you need to do is send LEVEL_1 or null to the "advanceToLevel(char[][])" method.

Please note that actually adding levels to the "advanceToNextLevel()" method is covered in "Part 12 - Making and Adding Levels".

Once you can advance to new levels, or return to the first level after player completes it, it's time to play the famous Pacman intro music at the start of each level. Note that it is a requirement to not allow Clara or the Ghosts to move until after the intro music has finished playing and the intro music must only play once for each level.

You will need to use the methods "playPacmanIntro()" and "isPacmanIntroStillPlaying()". For now, just focus on stopping Clara from moving while it is playing.

Note that after doing the above, you may wish to comment out the code that plays the intro music and prevents movement while testing the game, but remember to uncomment it and add it back in when you're ready to submit.

Part 5 - Moving Ghosts

Making the Ghosts move is very similar to making Clara move, but all your corresponding code must now be placed inside Ghost.java. You will need to call the "move(int)" method and determine a suitable speed for Ghosts. Note that they should move slower than Clara at this point. It is also a good idea to add the code to stop them from moving when the intro is playing. You will need to use the method
"isPacmanIntroStillPlaying()".

Don't forget to call the "wrapAroundWorld()" method, so that Ghosts correctly move after reaching the edge of the world. Before starting to code collisions and AI, there is something important you need to note: unlike Clara the Ghosts do not face the direction that they are pointing. They will always look like they are facing up, and this will not change.

This is important to know for logic error checking.

Part 6 - Animating Ghosts' Movement

Making the Ghosts animated works in the similar way as animating Clara. The method you call is exactly the same. Just like Clara, you will need to figure out a way of calling the "animate()" method every so often that the act method is called, and that it is up to you to determine how often they should animate.

Part 7 - Ghosts and Tree Collisions

Making the Ghosts detect that a tree is in the way, and stop, is achieved in a similar way as making Clara do so, you will even need the same methods. Although, unlike Clara, there is no human player to tell the Ghosts where to go after they hit a tree. It is up to you to decide what they should generally do when they hit one.

Note that telling the Ghosts where to face will involve using the "setDirection(string)" method, just like with Clara. It may assist your general Ghost logic if you use the "getDirection()" method, which returns a string just like you would send the "setDirection(string)" method, and that the string will be either "up", "down", "left" or "right". It is not necessary to use the "getDirection()" method, but you may find it helpful while testing and debugging your code.

Note that, just like Clara, the "setDirection(string)" method will not change the Ghost to a specified direction if there is a tree in that direction.

Part 8 - AI and Intersections

An important part of making your Ghosts intelligent - is detecting an intersection and deciding which way to go. You should start with simply selecting a random direction at an intersection by using random numbers covered in the lectures.

You will need to use the methods "treeAbove()", "treeBelow()", "treeToLeft()" and "treeToRight()" to detect an intersection. It should be noted that, unlike most sensor commands that you've used before, like "treeFront()" and "treeLeft()", these commands are not relative to the direction that the Ghost is facing, they are relative to the screen itself. This means that a tree that is above the Ghost, will always be above the ghost, regardless of which direction it is facing. This basic logic is true for all four aforementioned commands.

Test them out in order to understand them. Drag one of the Ghosts around and see what is the result of calling those methods.

It should be noted that, for the most part, an intersection can be defined as a location where there are three or more directions to go to.

HINT: You might want to check to make sure the Ghost has passed the intersection it is currently at before running the code to choose a direction at an intersection. (Otherwise, it might just hang around the same intersection and not go anywhere).

For more advanced students, use the "isAboveMe()", "isBelowMe()", "isToMyLeft()", "isToMyRight()" and "getClara()" methods to give them a 50% chance of moving in the Clara's direction at every intersection. Note that the "isAboveMe()", "isBelowMe()", "isToMyLeft()", "isToMyRight()" methods are further explained in the "Part 11 - Ghosts and Regeneration".

Part 9 - Ghosts Colliding with Clara and Losing

The Ghosts must pose a threat to Clara, and as such, they must kill her if they catch her. In order to do so, you will need to check if they have collided with Clara. To do so, you will need to use the methods "intersects(Actor)", "getClara()" and "makeClaraDead()" inside the Ghost class. Clara will need to use the method "isClaraDead()" to signal that the game is over.

It is important for the Ghosts to be continually checking whether they have caught Clara, and it is important for Clara to check whether she is dead to prevent further movement and animation.

Once you have Clara capable of checking whether she is dead, you will need to show the appropriate death image, with Clara's method "animateDead()" and play the appropriate sound with the method "playClaraDieSound()". It is important that the method "playClaraDieSound()" is only called once.

It is also important that you stop processing keyboard input from the player at the point of Clara's death.

Note that Clara's "animateDead()" method only contains one frame, and so it is acceptable to run it every time the act method is called after Clara is dead.

Part 10 - Eating Mushrooms and Making Ghosts Eatable

Clara will need to able to eat mushrooms and get her super power. In order to do so, you will need to use methods "onMushroom()" and "removeMushroom()".

Then you will need to appropriately place the method "makeScared()" when Clara has eaten a mushroom. The Ghosts will need to check whether or not they should be scared, and switch to the appropriate animation when they are. You will need to use the methods "isScared()" and "animateScared()". Note that the "animateScared()" method will need to be run every so many times that the act method is called, just like the "animate()" method.

It is acceptable, but not compulsory to increase the Ghosts' speed when they are scared, but they should be slower than Clara. You will then need to ensure that the Ghosts don't kill Clara when they collide with her if they are scared, and instead, die themselves. It will be up to you to create your own variable that checks if the Ghosts are dead. You will need the "animateDead()"and "playGhostEatenSound()" methods.

It is important to note that the Ghosts do not stop moving when they are dead, and that the Ghost's "animateDead()" method will need to be run every so many times that the act method is called, just like the "animate()" method.

It is also important that the Ghosts should not harm Clara when they are scared or when they are dead. Also note that the game will automatically decide how long the Ghosts should be scared for.

Part 11 - Ghosts and Regeneration

When a Ghost is dead, it will need to return to the Ghost Healer, which is the red object near where the Ghosts start. It will be up to you to decide how they should logically make their way back to the Ghost Healer object.

You will need to use the "isAboveMe(Actor)", "isBelowMe(Actor)", "isToMyLeft(Actor)", "isToMyRight(Actor)" and "getGhostHealer()" methods to make this happen.

Note that the "isAboveMe(Actor)", "isBelowMe(Actor)", "isToMyLeft(Actor)", "isToMyRight(Actor)" methods need to be sent an Actor, and that only two are available to you, through the "getGhostHealer()" and "getClara()" methods. You will need to send those ‘get' methods to the ‘is' methods in order to get an appropriate answer.

An example of how to use the above functions is below:
"isAboveMe( getGhostHealer() );"

If the above example returns true, then the Ghost Healer is above the Ghost.

When the Ghost returns to the Ghost Healer object, it will need to make itself no longer dead. You will need the "intersects(Actor)" and "getGhostHealer()" methods to make this work.

Hint: To avoid ghosts being stuck between 2 intersections - you may want to remember the direction the ghost came form (use getDirection() for this) before setting a new direction and don't send the ghost to this direction again.

Part 12 - Making and Adding Levels

It's time to understand how Clara's world is designed in this game, and how to design and add your own levels.

Part 13 - Life is Good

Now tidy up your code, add more levels if you want, but be sure to properly comment what you've coded. You're ready to hand in your assignment. Life is good!

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: The major assignment involves producing a pacman style game
Reference No:- TGS0986251

Expected delivery within 24 Hours