Create an image of the pacman character

Assignment Help Other Engineering
Reference no: EM131158780

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:

https://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

Reference no: EM131158780

Questions Cloud

Why is plutonium one of the most toxic substances known : Why is plutonium one of the most toxic substances known?
How they can contribute to mind-body-spirit health : In a 2-page paper, describe three mystical moments (premonitions, insightful dreams, clairvoyant thoughts, synchronistic moments, etc...) and how they can contribute to mind-body-spirit health. Explain how you might overcome skepticism by those be..
What are the chemical properties of a radioactive substance : Assume the amount of radioactivity is the same in each case. Explain your answer on the basis of the chemical properties of Sr and Xe. Why are the chemical properties of a radioactive substance important in assessing its potential health hazards?
Explain why each step is important and necessary : In a 2-page paper, use the steps for meditation as outlined inHealth of the Human Spirit to design a meditation plan for yourself. Be sure to include specific step-by-step instructions and explain why each step is important and necessary.
Create an image of the pacman character : 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.
How many neutrons and particles produced in fission reaction : How many neutrons and -particles are produced in this fission reaction? Explain in detail the process in which you arrived at you answer, and show your work.
Describe at least two renewable alternatives to oil : Based on the concern that we may be running out of oil, describe at least two renewable alternatives to oil that are currently available and discuss the barriers that keep these alternatives from replacing oil as our primary means of energy. Do no..
What conclusions about photosynthesis can be drawn : When algae growing in water containing only 16O were furnished carbon dioxide containing 18O, no 18O was found to be evolved from the oxygen gas produced. What conclusions about photosynthesis can be drawn from these experiments?
3 measures for assessing the effectiveness of sales force : describe three measures for assessing the effectiveness of a sales force as a whole. Explain why they are important, and how sales managers apply these criteria to sales force performance evaluations.

Reviews

Write a Review

Other Engineering Questions & Answers

  Write a vhdl module for a 4-bit up-down counter

Write a VHDL module for a 4-bit up-down counter. If En = o, the counter will hold its state.If En = 1, the counter will count up if U = 1 or down if U = o. The counter should also have an asynchronous active-low clear signal ClrN.

  What is the highest junction temperature you would expect

A power transistor operating at an ambient temperature of 50°C, and an average emitter current of 3 A, dissipates 20 W. If the thermal resistance of the transistor is known to be less than 3°C/W, what is the highest junction temperature you would ..

  What level of service will segment of highway operate under

If the peak-hour factor is estimated to be 0.85 and the driver population adjustment factor is expected to be 1.0, what level of service will this segment of highway operate under?

  Why is lead compensation important in a bridge circuit

Why is lead compensation important in a bridge circuit? What are the advantages to using a bridge with all elements active? Draw a temperature sensing circuit using the LM35 to convert 25° C into 2.5VDC.

  Convert the decimal number to binary

Convert hexadecimal value 17 to decimal - how many of those possibilities will result in a HIGH output and What logic function corresponds to the following circuit?

  What kind of traffic if predominantly observed

When monitoring one port on the network switch, what kind of traffic if predominantly observed? What other traffic can be seen when port mirroring is turned on?

  Discuss the ethical and safety issues

Read the case study: "Citycorp" and analyze the situation of substantial risk. Discuss the ethical and safety issues involved and steps taken to resolve those issues. (use the template: Evaluating the Case Study)

  Variability of laboratory measured properties of category

Compare variability of laboratory measured properties of category 2 soil material for   a range of overburden pressure scenarios.

  Consultant analysis report on enterprise system

Throughout this course, you will be preparing a Consultant's Analysis Report on Enterprise Systems for a project of your choosing that will culminate in the Final Key Assignment. You will not be developing any software or actually implementing a s..

  Partial vacuum in a reservoir

Figure is a sketch of an aspirator, a simple device that can be used to achieve a partial vacuum in a reservoir connected to the vertical tube at B. An aspirator attached to the end of a garden hose may be used to deliver soap or fertilizer from t..

  Corresponding magnitude of the resultant

A collar that can slide on a vertical rod is subjected to the three forces shown. Determine (a) The value of the angle a for which the resultant of the three forces is horizontal,

  Analysis of the design options and impact on condenser

The circulating water system components include three pumps in parallel to provide the design flow, and the associated piping and valves to supply the water to the condenser. The water is drawn from a captive lake and is returned to the lake.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd