Major Assignment: Pacman Game

Similar documents
The University of Melbourne Department of Computer Science and Software Engineering Graphics and Computation

Fruit Snake SECTION 1

CPSC 217 Assignment 3

Lab 9: Pointers and arrays

Improving the Crab more sophisticated programming

Improving the crab: more sophisticated programming

CMSC 201 Spring 2018 Project 3 Minesweeper

Creating Breakout - Part 2

Introduction to Unreal Engine Blueprints for Beginners. By Chaven R Yenketswamy

More About WHILE Loops

Intro. Scheme Basics. scm> 5 5. scm>

The first program: Little Crab

Assignment 3: Optimizing solutions

Agents That Move. NetLogo Guide 2. Turtles - Breeds. John Hayward Church Growth Modelling

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING

The WideRuled Story Generator Tutorial Alex Mitchell Communications and New Media Programme National University of Singapore

Appendix 9 Insteon. What is Insteon?

Shorthand for values: variables

Get comfortable using computers

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via by Friday, Mar. 18, 2016

SPRITES Moving Two At the Same Using Game State

Dalarna University Telephone:

Pacman. you want to see how the maze was created, open the file named unity_pacman_create_maze.

Getting to know Greenfoot

Web API Lab. The next two deliverables you shall write yourself.

These are notes for the third lecture; if statements and loops.

Imagery International website manual

Lesson 2. Introducing Apps. In this lesson, you ll unlock the true power of your computer by learning to use apps!

Understanding and Exploring Memory Hierarchies

CMSC 201 Spring 2018 Project 2 Battleship

CSC D84 Assignment 2 Game Trees and Mini-Max

NAME EET 2259 Lab 3 The Boolean Data Type

Making use of other Applications

CS211 Spring 2007 Assignment 5 Pacman Due Thursday, 3 May 2007, 11:59:59pm. 1 General Instructions. 2 Overview. 2.1 Background. 2.

In this lesson you will learn: How to capture the input from the user. How to write programs using variables and lists. Athletics Swimming Gymnastics

Boardmaker 5.0 (Macintosh) Creating a Story Response Board. Introduction. Case Study. Learning Objectives

Tangents. In this tutorial we are going to take a look at how tangents can affect an animation.

CSC 258 lab notes, Fall 2003

Use lists. Use loops. Use conditionals. Define and use functions. Create and use code modules

Part 1: Understanding Windows XP Basics

Introduction. What is Max?

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Dice in Google SketchUp

Pong in Unity a basic Intro

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

Procedures: Algorithms and Abstraction

Hello App Inventor! Android programming for kids and the rest of us. Chapter 2. by Paula Beer and Carl Simmons. Copyright 2015 Manning Publications

Midterm Exam, October 24th, 2000 Tuesday, October 24th, Human-Computer Interaction IT 113, 2 credits First trimester, both modules 2000/2001

printf( Please enter another number: ); scanf( %d, &num2);

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Add in a new balloon sprite, and a suitable stage backdrop.

Text Input and Conditionals

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

Linux Tutorial #1. Introduction. Login to a remote Linux machine. Using vim to create and edit C++ programs

Project 5 - The Meta-Circular Evaluator

Lab 12: Lijnenspel revisited

Lecture Transcript While and Do While Statements in C++

The State Universtiy of New York, Korea Computer Science

Introducing Activstudio

textures not patterns

FILE ORGANIZATION. GETTING STARTED PAGE 02 Prerequisites What You Will Learn

: Principles of Imperative Computation. Fall Assignment 5: Interfaces, Backtracking Search, Hash Tables

Using Tab Stops in Microsoft Word

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Quick Start Guide to using Light Converse along with Pangolin LD2000 and BEYOND

1. Introduction EE108A. Lab 1: Combinational Logic: Extension of the Tic Tac Toe Game

Practical 2: Ray Tracing

Game Design Unity Workshop

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

Student Success Guide

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

Damaging, Attacking and Interaction

Your First Windows Form

IAT 445 Lab 10. Special Topics in Unity. Lanz Singbeil

Assignment 4: Due Friday Mar 11 at 6pm

Laboratory 1: Eclipse and Karel the Robot

Lab 7: Creating a Virtual Pet

Assignment #6 Adventure

Creating an Xtra-Normal Movie. 1. Go online and type in the URL 2. Click on Create a Movie. 3. Click on Create An Account

Java/RealJ Troubleshooting Guide

CPSC 217 Assignment 4

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

1 Getting started with Processing

Chapter 3. Using the System CHANGING CHANNELS USING THE MENUS OPENING THE MENUS CLOSING THE MENUS MENU OPTIONS

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2010

CS 210 Fundamentals of Programming I Spring 2015 Programming Assignment 4

CMSC162 Intro to Algorithmic Design II Blaheta. Lab March 2019

Tips from the experts: How to waste a lot of time on this assignment

Using Flash Animation Basics

6.001 Notes: Section 8.1

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Test-Driven Development (TDD)

CS50 Supersection (for those less comfortable)

CS 134 Programming Exercise 9:

ENCM 501 Winter 2016 Assignment 1 for the Week of January 25

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

The Fundamentals. Document Basics

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

CSE 142, Autumn 2018 Programming Assignment #9: Critters (20 points) Due Tuesday, December 4th, 9:00 PM

Transcription:

Major Assignment: Pacman Game 300580 Programming Fundamentals Week 10 Assignment The major assignment involves producing a Pacman style game with Clara using the Greenfoot files that are given to you. The essence of the game is to make Clara eat all available leaves, while avoiding collisions with ghosts chasing her. Clara is to be controlled by a player through keyboard. Apart from leaves, there are also mushrooms available in Clara s world, but unlike the practicals, Clara is unable to push them around, but instead she can eat those mushrooms and gain superpowers (for a short period of time she will be able to eat ghosts). Ghosts always start at their home base (also known as Ghost Healer) that is always marked by a think red dot. Somewhere close to a Ghost Healer there is always a ghost wall (represented by a square surrounded by dotted red line). The ghost wall can be penetrated by ghosts, but not by Clara, making the ghost base protected from invasion. When Clara eats a mushroom, ghosts change their colour and would start running away from Clara. This mode when Clara is able to eat ghosts is called scared mode. In the scared mode ghosts run away from Clara rather than chasing her and if a collision between a ghost and Clara occurs while in this mode the ghost would change into an almost invisible creature that moves from the collision location to the base and then resurrects once the base is reached. If a collision happens between Clara and a ghost in any other mode then Clara looses and the game is over. In solving the major assignment you will not be entirely on your own, as the steps involved are broken up in this assignment brief. During practical classes your tutors will explain you the basics in completing these steps. Before we start, there will be an explanation of all commands available in both Clara and the Ghosts vocabularies. Major Assignment: Pacman Game 1

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. Important note 1 While in the past you only had to work with MyClara.java, this time you will also have to edit Ghost.java for all the logic related to the Ghosts as well as MyClara.java for all the Clara functionality. Important note 2 Do not let the following list of commands scare you, as they are further explained in the assignment brief and your tutors will help you to select those commands that you need for each task. Major Assignment: Pacman Game 2

Important note 3 For this assignment you should no longer have a main loop (for or while) inside act(). Instead you should rely on Greenfoot executing act() repetitively (similar to how you did in Practical 2). The stop(); command MUST NOT be used in this assignment. Clara s vocabulary For this assignment, the following commands are available for Clara right from the start: treefront() Checks if there is a tree in front of Clara. true if there is a tree in front of Clara. false if there is not a tree in front of Clara. ghostwallfront() Checks if there is a ghost wall in front of Clara. true if there is a ghost wall in front of Clara. getdirection() Gets which direction Clara is facing. false if there is not a ghost wall in front of Clara. A string which represents the direction Clara is facing. up if Clara is facing up toward the top of the screen. down if Clara is facing toward the bottom of the screen. right if Clara is facing to the right side of the screen. setdirection(string) Makes Clara face a specific direction. It will not change her direction if there is a tree in the way. A String, which specifies which direction you want Clara to face. up - face toward the top of the screen. left if Clara is facing to the left side of the screen. down - face toward the bottom of the screen. right - face toward the right side of the screen. left - face toward the left side of the screen. Major Assignment: Pacman Game 3

Clara s vocabulary - continued move(int) Moves Clara at the specified speed. An integer, which specifies how fast you want Clara to move. makescared() Clara lets the Ghosts know that she is ready to eat, and makes them scared. isscared() animate() For more information, see the isscared() function in the Ghost s vocabulary. Also see the section Part 10 Eating Mushrooms and Making Ghosts Eatable Clara checks whether the Ghosts are still scared of her. Clara continues her animation by one frame. true if the Ghosts are still scared of her. false if the Ghosts are no longer scared of her. animatedead() For more information, see the section Part 2 - Animating Clara s Movement. Clara visually shows that she is dead. onleaf() For more information, see the section Part 9 - Ghosts Colliding With Clara and Losing Checks if Clara is on top of a leaf. true if Clara is on top of a leaf. removeleaf() Clara removes a leaf that she is standing on. false if Clara is not on top of a leaf. Will show an error if she tries to remove a leaf that isn t there. Major Assignment: Pacman Game 4

Clara s vocabulary - continued onmushroom() Checks if Clara is on top of a mushroom. true if Clara is on top of a mushroom. removemushroom() allleaveseaten() Clara removes a mushroom that she is standing on. Checks if Clara has eaten all of the leaves in the level. false if Clara is not on top of a mushroom. Will show an error if she tries to remove a mushroom that isn t there. true if there are no more leaves for Clara to eat. isclaradead() playclaradiesound() Checks if Clara should be dead. For more information, see the function makeclaradead() in the Ghost s vocabulary and the section Part 9 Ghosts Colliding with Clara and Losing Plays Clara s death sound. Nothing false if there are still leaves for Clara to eat. true if Clara should be dead. false if Clara should not be dead. Nothing isclaradiesoundstillplaying() For more information see the section Part 9 Ghosts Colliding with Clara and Losing Checks if Clara s death sound is still playing. playleafeatensound() playpacmanintro() For more information see the section Part 9 Ghosts Colliding with Clara and Losing Plays the sound of Clara eating a single leaf. Plays the pacman intro sound. Major Assignment: Pacman Game 5

Clara s vocabulary - continued ispacmanintrostillplaying() Checks if the pacman intro sound is still playing. wraparoundworld() getcurrentlevelnumber() For more information see the section Part 4 Eating Leaves and Winning Enables Clara to automatically move off one side of the game, and end up on the other. Gets the number of the current level. An integer representing the current level number. advancetolevel(char[][]) Changes the current game level to the one specified. If it is sent null, then it will automatically load the first level. A level as per Part 12 Making and Adding Levels, or null. E.g. If the current level is 1, then it will return 1. To see more information on how to use it, see Part 4 Eating Leaves and Winning For more information on making levels to send the method, see Part 12 Making and Adding Levels Major Assignment: Pacman Game 6

Ghost s vocabulary For this assignment, you will also be required to code new characters - Ghosts. The Ghosts pose a threat to Clara as she tries to eat all of her leaves and try to prevent her from accomplishing her mission. The behaviour of each Ghost is controlled by the act() method inside Ghost.java. Each of the Ghosts in the game is essentially an instance of the Ghost class (we will learn about classes soon enough in the lectures). In order to assist you in programming Ghosts, just like for Clara, there are Ghost commands already made for you. Some of these commands are exactly the same as Clara s, some are slightly different, and some completely unique to the Ghosts. Be sure to read the following list of commands carefully: treefront() Checks if there is a tree in front of the Ghost. true if there is a tree in front of the Ghost. treeabove() Checks if there is a tree above the Ghost. false if there is not a tree in front of the Ghost. true if there is a tree above the Ghost. treebelow() Note that this method is relative to the screen, not the Ghost. That is, regardless of the direction of the Ghost, a tree that is above it, will always be above it. Checks if there is a tree below the Ghost. false if there is not a tree above the Ghost. true if there is a tree below the Ghost. treetoleft() Note that this method is relative to the screen, not the Ghost. That is, regardless of the direction of the Ghost, a tree that is below it, will always be below it. Checks if there is a tree to the left of the Ghost. false if there is not a tree below the Ghost. true if there is a tree to the left of the Ghost. Note that this method is relative to the screen, not the Ghost. That is, regardless of the direction of the Ghost, a tree that is to the left of it, will always be to the left it. false if there is not a tree to the left of the Ghost. Major Assignment: Pacman Game 7

Ghost s vocabulary - continued treetoright() Checks if there is a tree to the right of the Ghost. true if there is a tree to the right of the Ghost. getdirection() Note that this method is relative to the screen, not the Ghost. That is, regardless of the direction of the Ghost, a tree that is to the right of it, will always be to the right it. Gets which direction the Ghost is facing. false if there is not a tree to the right of the Ghost. A string which represents the direction the Ghost is facing. up if the Ghost is facing up toward the top of the screen. down if the Ghost is facing toward the bottom of the screen. right if the Ghost is facing to the right side of the screen. setdirection(string) Makes the Ghost face a specific direction. The Ghost will not change to a direction that has a tree in the way. A string, which specifies which direction you want the Ghost to face. up if you want it to face toward the top of the screen. left if the Ghost is facing to the left side of the screen. down if you want it to face toward the bottom of the screen. right if you want it to face toward the right side of the screen. left if you want it to face toward the left side of the screen. Major Assignment: Pacman Game 8

Ghost s vocabulary - continued move(int) isscared() animate() Moves the Ghost at the specified speed. The ghost will move in the direction it is currently facing until it hits an obstacle or until the direction is changed The Ghost checks whether it should be scared of Clara. The Ghost continues its animation by one frame. An integer, which specifies how fast you want the Ghost to move. true if the Ghosts should still be afraid of Clara. false if the Ghosts should no longer be scared of Clara. animatedead() For more information, see the section Part 6 - Animating Ghost s Movement. The Ghosts continues its death animation by one frame. animatescared() For more information, see the section Part 10 Eating Mushrooms and Making Ghosts Eatable The Ghosts continues its scared animation by one frame. getclara() For more information, see the section Part 10 Eating Mushrooms and Making Ghosts Eatable Gets Clara. Clara. Is to be used with the isaboveme, isbelowme, istomyleft and istomyright commands, explained below. Major Assignment: Pacman Game 9

Ghost s vocabulary - continued getghosthealer() Gets the Ghost Healer. Ghost Healer. isaboveme(actor) Is to be used with the isaboveme, isbelowme, istomyleft and istomyright commands, explained below. Checks whether the specified Actor is above the Ghost. Clara or Ghost Healer. true if specified Actor is above the Ghost. isbelowme(actor) Checks whether the specified Actor is below the Ghost. Clara or Ghost Healer. false if the specified Actor is not above the Ghost. true if specified Actor is below the Ghost. istomyleft(actor) istomyright(actor) intersects(actor) Checks whether the specified Actor is to the left of the Ghost. Checks whether the specified Actor is to the right of the Ghost. Checks whether the specified Actor is currently intersecting the Ghost. Clara or Ghost Healer. Clara or Ghost Healer. Clara or Ghost Healer. false if the specified Actor is not below the Ghost. true if specified Actor is to the left of the Ghost. false if the specified Actor is not to the left of the Ghost. true if specified Actor is to the right of the Ghost. false if the specified Actor is not to the right of the Ghost. true if the specified Actor is currently intersecting the Ghost. makeclaradead() Makes Clara s isclaradead() method return true. false if the specified Actor is not currently intersecting the Ghost. playghosteatensound() For more information, see the section Part 9 Ghosts Colliding with Clara and Losing Plays the sound of a Ghost being eaten. Major Assignment: Pacman Game 10

Ghost s vocabulary - continued ispacmanintrostillplaying() Checks if the pacman intro sound is still playing. wraparoundworld() For more information see the section Part 5 Moving Ghosts Enables the Ghost to automatically move off one side of the game, and end up on the other side. Making the Game 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. Major Assignment: Pacman Game 11

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. Major Assignment: Pacman Game 12

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. Major Assignment: Pacman Game 13

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. onmushroom() and removemushroom(). In order to do so, you will need to use methods 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. Major Assignment: Pacman Game 14

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. When you first opened up MyClara, you may have noticed the first level at the top of the code. This is the format you will need to use in order to create your own levels. See the image below for what you should roughly see when first opening up MyClara. Figure 12.1 The first level is done for you Major Assignment: Pacman Game 15

You will need to rename the level from LEVEL_1 to LEVEL_2. You ll notice that a level is simply an array of characters that visually represent the level that they make. The characters used are as follows: # represents a tree, which is an obstacle to both Clara and the Ghosts.. represents a leaf, which Clara needs to eat in order to progress to the next level. represents nothing, which is essentially an empty tile. % represents a Ghost. At least one must be present in every level you make.? represents a Ghost Healer, which the Ghosts return to when eaten in order to come back to life. At least one must be present in every level you make. represents a Ghost Wall, which is an obstacle that only Ghosts may pass through, and not Clara. It is connected to the group of trees that make up the initial room that the Ghosts start in. At least one must be present in every level you make. $ represents a mushroom, which can be eaten by Clara in order to make the Ghosts scared and capable of being killed by Clara. @ represents Clara, it is where she will start at the beginning of the level. Only one must be present in every level you make. The characters that make up the array of a level in Clara s world are each surrounded by single quotes ( ) and the characters in a single row are separated by commas (,). A single row in a level is surrounded by curly braces({}), and the end of a row of a level, that is not the end of the whole level, is indicated by a comma after the closing curly brace (},). This is all indicated in the image below. Figure 12.2 How a level of Clara s world is constructed in an array Now you should have a rough understanding of how Clara s world is constructed. Major Assignment: Pacman Game 16

In order to build your own level, all you have to do is delete all of the streets of the level and write your own level in there, following the above rules in order to present it and write it properly. Just in case you re still unsure of what to delete before you write your own level, only delete the section as highlighted in the following image. Figure 12.3 The part to delete to write your own level Then write your own level, in between the curly braces that are left after you delete what was highlighted. After you re done, you ll need to go to where you call the advancetolevel(char[][]) method and figure out a way of sending it LEVEL_2 when the player has finished LEVEL_1. Now add a new level, and test it. To add another level, simply copy and paste LEVEL_2 inside MyClara and change it to LEVEL_3, and modify it just like you did for level 2. Add as many levels as you want, although technically you are only required to add one more level. 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! Demonstrate the game to your tutor in the last tutorial class (Week 14) Submit all files to your tutor by 11.59PM Friday 31 October. Late penalties apply for submissions after the due date above (see learning guide). Major Assignment: Pacman Game 17