Objectives

The focus on this project is to give you more experience writing child classes, working with equations and code, and integrating user input.

Tasks

RotatingBlock Class

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 arguments.

winA reference to a GraphWin object
x0The anchor point x value. The anchor is in the middle of the left side.
y0The anchor point y value. The anchor is in the middle of the left side.
widthThe horizontal distance of the floor.
heightThe vertical distance of the floor.
AxThe anchor point X value, with the default value of None.
AyThe 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.

Methods

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.

collision.py

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.

Obstacle Course

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.

User Interaction

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.

Extensions

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.

Write Up & 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 Project10 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 cs152f17project10 in the label field on the bottom of the page. But give the page a meaningful title (e.g. Caitrin'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.


When you are done with the lab exercises, you may start on the rest of the project.


© 2017 Caitrin Eaton.