Project 10: Pinball with Rotation
The focus on this project is to give you more experience writing child classes, working with equations and code, and integrating user input.
The first task is to create a RotatingBlock class. You could create
this in your physics_objects.py file or you could create a new file.
The choice is yours. The class should be called RotatingBlock, and it
should inherit from the Thing class, just like Ball, Wall, Floor and
Block. The RotatingBlock.__init__ method should have the following
win A reference to a GraphWin object x0 The anchor point x value. The anchor is in the middle of the left side. y0 The anchor point y value. The anchor is in the middle of the left side. width The horizontal distance of the floor. height The vertical distance of the floor. Ax The anchor point X value, with the default value of None. Ay The anchor point Y value, with the default value of None.
As with the Ball class, the first action in the __init__ method is to call the parent Thing.__init__ method. Specify the type as the string "rotating block", and pass in [x0, y0] as the position. Next, assign the parameters width and height to two fields width and height.
Next, create the list of vertex points (self.points), which should be a list of four 2-element lists. The coordinates of the block should be (-width/2, -height/2), (width/2, -height/2), (width/2, height/2), and (-width/2, height/2).
The remaining unique fields should be identical to the ones you created in the RotatingLine class: angle, rvel, anchor, and drawn. Note that scale and vis are already created in the Thing parent class.
Make the methods draw, getAngle, setAngle, getAnchor, setAnchor,
getRotVelocity, setRotVelocity, and rotate. These should be very
similar, if not identical to the RotatingLine class from lab.
Make the render method. Again, this will be identical to the RotatingLine version except that the last step will be to create a graphics Polygon instead of a Line, using the list of rotated points. At this point, you can run the first test function. You may need to modify the test code, depending on where you wrote your RotatingBlock class. The block should spin around once.
Next, you need to create an update method in the RotatingBlock class, since the Thing.update method does not include rotational velocity. The update method needs to take self and dt (time step) as arguments. The update method should first calculate how much the angle changes during the time step (self.rvel * dt) and assign that to a local variable (e.g. da). If the da value is not equal to zero, then call the rotate method, passing in da as the argument. Then, call the update method in the Thing class, passing in self and dt.
Once you have the update method done, try out the second second test function. Since the anchor point is different, the block should appear to rotate around the center of the screen.
- Download the new collision.py file. Copy your collision_router code from last week and update it to include a key for ('ball, 'rotating block'). Then run the third test function.
Create a very simple obstacle course with one or two rotating objects.
Launch one or more balls into the scene.
Create a video of your simple obstacle course in action and include a link to it on your wiki.
Create a scene that includes at least one rotating object and
incorporates some form of user interaction. For example, add paddles
to your pinball-style scene from last week that activate when the user
hits the space bar. Make something very simple that responds to user
input before doing anything more complex.
Create a video of your reactive scene in action and include a link to it on your wiki.
Each assignment will have a set of suggested extensions. The required tasks constitute about 85% of the assignment, and if you do only the required tasks and do them well you will earn a B+. To earn a higher grade, you need to undertake one or more extensions. The difficulty and quality of the extension or extensions will determine your final grade for the assignment. One complex extension, done well, or 2-3 simple extensions are typical.
The following are a few suggestions on things you can do as extensions to this assignment. You are free to choose other extensions.
- Create more elaborate spaces and developing interesting additional simulation videos.
- Create more shape classes and show that they collide and simulate appropriately.
- This simulation does not take into account masses. A challenging extension would be to modify the collision code so that when two things collide the velocity changes take into account the masses. (Conservation of momentum, energy, and geometry.)
- Create a separate scene like putt-putt golf and let the user shoot the golf ball.
Write-up and Hand-in
Turn in your code by putting it into your private hand-in directory on the Courses server. All files should be organized in a folder titled "Project 10" and you should include only those files necessary to run the program. We will grade all files turned in, so please do not turn in old, non-working, versions of files.
Make a new wiki page for your assignment. Put the label cs151sf15project10 in the label field on the bottom of the page. But give the page a meaningful title (e.g. Milo's Project 10).
In general, your intended audience for your write-up is your peers not in the class. Your goal should be to be able to use it to explain to friends what you accomplished in this project and to give them a sense of how you did it. Follow the outline below.
- A brief summary of the task, in your own words. This should be no more than a few sentences. Give the reader context and identify the key purpose of the assignment.
- A description of your solution to the tasks, including any text output or images you created. This should be a description of the form and functionality of your final code. Note any unique computational solutions you developed or any insights you gained from your code's output. You may want to incorporate code snippets in your description to point out relevant features. Code snippets should be small segments of code--usually less than a whole function--that demonstrate a particular concept. If you find yourself including more than 5-10 lines of code, it's probably not a snippet.
- A description of any extensions you undertook, including text output or images demonstrating those extensions. If you added any modules, functions, or other design components, note their structure and the algorithms you used.
- A brief description (1-3 sentences) of what you learned. Think about the answer to this question in terms of the stated purpose of the project. What are some specific things you had to learn or discover in order to complete the project?
- A list of people you worked with, including TAs and professors. Include in that list anyone whose code you may have seen, such as those of friends who have taken the course in a previous semester.
- Double-check the label. When you created the page, you should have added a the label cs151f15sproject10. Make sure it is there.