Ask Other Engineering Expert

Lab: Pacman Game

Objective: Review homogeneous coordinates. Using these coordinates, and anonymous functions design a Pacman gameand create an animation as Pacman maneuvers the maze to gobble down the blue jewel.

Questions 1-2: Create an image of the Pacman character. Start by entering the coordinates for the Pacman image shown below. You will not draw the points. These are just to help you create the vectors for the Pacman figure.

i. To enter the points for your Pacman figure, start with the green point, and proceed counterclockwise through the yellow points and stop at the red point.

First, create a vector for the x-coordinates of each point.

ii. Now enter the y-coordinates for each point in the exact same order.

Note the y-value for the mouth is a half-integer.

iii. Later, we will need to use homogeneous coordinates to help translate the Pacman figure about a maze. Add the z-coordinates, all of which are 1. The number of 1's must be the same as the number of x's and y 's. Finish the assignment statement below.

iv. Be sure to define: pacman = [xcoords; ycoords; zcoords];

You will need this variable to move the Pacman around the maze later.

Now paste in an image of your Pacman character. Use the fill()command to create your plot. You will not need the z-coordinates at this stage. Draw your Pacman using yellow(instead of red). Do not draw the points! Label both axes and add a title to the plot.

Question 3:Set the 'LineWidth' to 4, and add a black eye centered at (2, 3.25) using the plot command.

We won't use this later in the lab, but it's a suggestion for future improvement.

Questions 4-5: Anonymous Functions for translate() and rotate()

Last week, you used standard function files, to define functions translate(dx,dy), rotate(angle_in_deg) and scale(k). This week, you will create the same functions, but using simple inline code to create each of these as an anonymous function in the same Matlab file you are working in.

Read more about anonymous functions here:

http://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html

Example:Create an anonymousfunctionto computetranslate(dx,dy).

This function should return the matrix:

Just enter then following line in your Matlab script for this lab. Do not use a new file.

translate = @(dx,dy)([1 0 dx;0 1 dy; 0 0 1]);

Question 5:Create an anonymousfunctionforrotate(d). This function should return the matrix R shown below. The angle d is in degrees. You must use cosd and sind, not cos and sin!

Question 6: The Pacman Maze

Create a figure showing this Pacman Maze.

As before, the 12 dots are just to help you see the

coordinates for each point. Do not draw the 12 dots!

i. To enter the 12 points for your Pacman Maze, start with the green point, and proceed counterclockwise(initially) through the yellow points and stop at the red point.

First, create a vector for the x-coordinates of each point.

ii. Now enter the y-coordinates for each point in the exact same order.

iii. Plot your maze using fill(). Set the color to cyan, and use a 'LineWidth' of 4. Add a title.

Questions 7-8: Place the Pacman at thestartof the maze, and a blue jewelat the end for it to gobble down.

Show the four "turning points" using a black asterisk for each.

i.Place the Pacman at the starting position. Recall you should have earlier defined:
pacman = [xcoords; ycoords; zcoords];

IMPORTANT: Use exactly the following command.

pacman_handle = fill(pacman(1,:),pacman(2,:),'y', 'LineWidth', 2);

Why do we need a handle to the Pacman image? Well, later on, we want to animate the Pacman as it moves around the maze. Each time it moves to a new position, we need to delete the image of its previous position. This handle will enable us to do that simply by using the code:
delete(pacman_handle)

ii.Place a blue jewelat the end of the maze. A good location is (14, 12.5).

Use the plot command with a diamond or 'd' for the marker. Set the 'MarkerFaceColor' to blue.

You should also use a handle for your jewel, so it can disappear when the Pacman eats it. Here's how:

jewel_handle = plot( Add arguments here.);

iii. As the Pacman moves from the start to the end of the maze, it encounters four turning points. Show each "turning point" using a black asterisk for each. Here are the x and y values for the four turning points.

tp1 = (22.5, 2.5), tp2 = (22.5, 22.5), tp3 = ( 2.5, 22.5), tp4 = ( 2.5, 12.5)

Questions 7-8: Replace this plot, with your new plot. Remember yours must have no dots! butshould show the turning points, the blue jewel and the yellow Pacman.

Questions9-10:You can see four asterisks added to the above maze. These are points where the Pacman is required to turn (rotate). Its mouth should always point in the direction it is moving.O-o!! We need to rotate the Pacman about these points, and not the origin. Our rotate command only works about the origin. To rotate counterclockwise by d degrees about a point (a,b) first translate by (-a,-b) to get to the origin, then rotate and finally translateback by (+a,b+), to get back to where you started.

The code block on the next page requires you have already done the following.

Check each condition carefully!

1. You have already defined the pacman coordinates using:

pacman = [xcoords; ycoords; zcoords];

2a. You defined pacman_handleusing exactly the following code:

pacman_handle = fill(pacman(1,:),pacman(2,:),'y', 'LineWidth', 2);

2b. Similarly, you have defined jewel_handle when you plotted the blue jewel.

3. You have defined and entered anonymous functions for rotate(d) and translate(dx,dy).

By testing if the Pacman has arrived at a turning point, we can automate the Pacman to navigate through the entire maze. Using a for loop, we move the pacman "forward" 0.5 units on each iteration with the help of your translate() command. You will also need the rotate() command, but just at each of the four turning points.

In the code on the next page, the first two turning points are given. Also the end of the game, with the blue jewel gobbled down has been provided. Your task is to add two if blocks to handle the third and fourth turning points.

Start by pasting the code on the next pageat the end of your script for today's lab, and test that it runs. If not, that means one of the above conditions has not been met exactly. Go back and check all the conditions.

Note the starter codebreaks after reaching the second turning point. This is so it will stop before reaching the incomplete code. Change that break to a continue right after you run the code a few times.

The code on this page is in a very small font to preserve its formatting. You might want to try reading it after pasting it into the end of your Matlab file for this week's lab.

That's it! Hope you enjoyed the game!

When your lab is complete, be sure to submit it as a PDF by the due date - this Thursday before 11:59PM. You have one more day, to submit the lab (but with a small penalty), and then the window closes for good and your grade will be zero. Only one submission is allowed per student.

Attachment:- Attachments.rar

Other Engineering, Engineering

  • Category:- Other Engineering
  • Reference No.:- M91914226
  • Price:- $100

Priced at Now at $100, Verified Solution

Have any Question?


Related Questions in Other Engineering

Register design a cpu register is simply a row of

Register design A CPU register is simply a row of flip-flops (i.e. SR, JK, T, etc) put side by side in an array to make the size of register required. For example, an 8 bit register has 8 flip-flops side by side for stor ...

A detailed review of spatial modulation and simulation

A Detailed Review of Spatial Modulation and Simulation Learning Outcomes a. Learn how to model mobile communication channels d. Discern knowledge development and directions on the recent advances in 4G to the research pr ...

Mine safety amp environmental engineering assignment -part

Mine Safety & Environmental Engineering Assignment - Part 1 - Questions 1. Occupational health and safety is the primary factor that needs to be considered in the mining industry. Discuss this statement. 2. Define the fo ...

Projectflow processing of liquor in a mineral refining

Project Flow Processing of Liquor in a Mineral Refining Plant The aim of this project is to design a flow processing system of liquor (slurry) in a mineral (aluminum) refining plant. Aluminum is manufactured in two phase ...

Learning outcomes evaluate multiuser communication and

Learning Outcomes Evaluate multiuser communication and resource sharing techniques; Apply the techniques of, and report on, digital communication applications using Matlab and hardware devices. Assignment Description The ...

Operations engineering assignment -please select only one

Operations Engineering Assignment - Please select only one of the following case studies for your assignment: CASE A. Tesla Motors Tesla is an innovative manufacturer that designs, assemble and sells fully electric vehic ...

Select a risk problem from the list below and prepare a

Select a risk problem from the list below and prepare a risk management plan in accordance with AS/NZS ISO 31000:2009. Please ensure that: - Establish the context clearly, in accordance with the Standard; - Define your s ...

Engineering materials term paper assignment -conduct a

ENGINEERING MATERIALS TERM PAPER ASSIGNMENT - Conduct a thorough literature search and write a 15-20 page technical review paper on the evolution of the engineering materials used in the manufacturing of any one of the f ...

Task 1using the lab kit design a circuit for the processor

Task 1: Using the lab kit, design a circuit for the processor to control the output of a connected 7-segment LED display device. You will be provided with a standard common anode 7-segment display of the type FND-507 (or ...

Control theory - lab reportsfor experiments 1 to 4 you must

Control Theory - Lab Reports For experiments 1 to 4 you must undertake the following: a) At the start of each section (including the pre-lab activities) there are a number learning outcomes. That is, what students should ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As