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

  Characterization technology for nanomaterials

Calculate the reciprocal lattice of the body-centred cubic and Show that the reciprocal of the face-centred cubic (fcc) structure is itself a bcc structure.

  Calculate the gasoline savings

How much gasoline do vehicles with the following fuel efficiencies consume in one year? Calculate the gasoline savings, in gallons per year, created by the following two options. Show all your work, and draw boxes around your answers.

  Design and modelling of adsorption chromatography

Design and modelling of adsorption chromatography based on isotherm data

  Application of mechatronics engineering

Write an essay on Application of Mechatronics Engineering

  Growth chracteristics of the organism

To examine the relationship between fermenter design and operating conditions, oxygen transfer capability and microbial growth.

  Block diagram, system performance and responses

Questions based on Block Diagram, System Performance and Responses.

  Explain the difference in a technical performance measure

good understanding of Mil-Std-499 and Mil-Std-499A

  Electrode impedances

How did this procedure affect the signal observed from the electrode and the electrode impedances?

  Write a report on environmental companies

Write a report on environmental companies

  Scanning electron microscopy

Prepare a schematic diagram below of the major parts of the SEM

  Design a pumping and piping system

creating the pumping and piping system to supply cool water to the condenser

  A repulsive potential energy should be a positive one

Using the data provided on the webvista site in the file marked vdw.txt, try to develop a mathematical equation for the vdW potential we discussed in class, U(x), that best fits the data

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