Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HW.07b Turtle Friend In Need Your friend, turtle, wants to run off and marry his princess girlfriend but an all-powerful otaku opposes his plan. He

HW.07b Turtle Friend In Need

Your friend, turtle, wants to run off and marry his princess girlfriend but an all-powerful otaku opposes his plan. He hires two brothers, a pair of plumbers, to thwart turtle's plan and kidnap the princess.

Your turtle friend asks you to create a program, turtle_friend.py, to devise a means to evade the plumbers and escape with his princess to live happily ever after.

Task

Create a function that uses Turtle Graphics to simulate your turtle friends escape. The function should define a parameter, num_enemies, to represent the number of enemies your friend could face. Enemies will be displayed as red or green bouncing balls.

Create num_enemies red or green bouncing balls, each located at a random location but no closer than a ball's width from any window borders. For each ball, select a random direction (dx and dy) for each ball to move in the combined range of (-5, 5), excluding 0.

Note: Do NOT have all balls use the same dx and dy values; rather, each ball should have its own dx and dy. You will need to use parallel lists (where a ball's dx and dy are located at the same index in both lists) or a list of sublists to manage the ball's dx and dy movements.

Create a turtle (your turtle friend) in the lower right-hand corner of the window. The turtle should be the same size as the balls. Use the arrow keys to control your turtle friends movement. When running your function, the user will use the arrow keys to try to move your turtle friend from the starting corner of the window to the OPPOSITE corner without letting the turtle be hit by a ball.

You will need to detect collisions between each ball and the window boundaries in order to know whether to reverse the ball's heading. You do NOT need to detect collisions with the boundaries of the window for your turtle friend. Also, the balls do NOT need to collide with each other; that is, they may pass through each other and/or overlap.

If your friend collides with a bouncing ball, he is captured (ie. game over). If your friend eludes the bouncing balls, then he escapes (ie. your friend wins). For each ending condition, print a message of your choosing (eg "Your friend made it!" or "Your friend is now turtle soup!") to indicate the result.

Notes:

Set the window to 500 pixels x 500 pixels.

Both your turtle friend and the enemies are defined as turtle objects; use a turtle shape for your friend and circle shape for the enemies.

Set the size of your friend and the enemies to turtlesize 3; this value can vary slightly but your friend and the enemies should be the SAME size.

To test for a collision between your turtle friend and an enemy, you'll want to determine when the distance between them is small enough to know they are right beside each other. You can use a turtle object's .distance() method to determine distance between to turtle objects. The following statement returns the distance between turtle1 and turtle2:

turtle1.distance(turtle2)

Additional Assignment Criteria

Place all functions in the same Python file, turtle_friend.py.

Include a header with the filename, brief descriptions of each function, your name and a date.

Add line comments before each function and at other appropriate sections of your code.

Keep your functions are reasonable size by breaking their contents into additional functions that are called from your function (keeps your code modular).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions

Question

outline some of the current issues facing HR managers

Answered: 1 week ago