CSCI 261 - Programming Concepts (C++)Fall 2017 - Lab 9Quick Links: Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks |
|
| Home | Contact | Syllabus | Assignments | Schedule | Resources | | |
This lab is due by Tuesday, December 05, 2017 11:59 PM . Concepts
You are going to create a magic bouncing ball to watch as it moves
around the screen.
Class Creation
For this lab you must first create a class called
Bubble
. The
Bubble
class should have private data members to store the following
information:
Draw It!
In our
main()
, before we get to the draw loop we want to make an object of our
Bubble
class. We want only one instance to exist in memory. If we made the
object inside the draw loop, then every iteration of the draw loop a
new object would be created.
Then inside our draw loop, after we've cleared the window and before we display the window, we need to display the CircleShape that corresponds to our Bubble object. At this point, you should see a white circle. Perfect! Let's continnue. Move It!
When we create our
Bubble
object, we need to make sure its direction values are set to non-zero
values. Do this now, we suggest using values of 1 & 2 for x & y
respectively.
Then in our draw loop, after we've checked the events we simply need to call our updatePosition() function on the object. It should be moving now. Oh no! It went off the screen. Let's keep it in view. Bop It!
The last part of this lab is have the Bubble bounce around the window.
Recall that the position for a
CircleShape
corresponds to the upperleft corner of a square enclosing the circle.
We need to check if any of the edges of our circle move outside the
window. We can check this by seeing if the position becomes less than
zero (to correspond to the left or top of our window) OR if the position
plus the diameter is greater than the width or height of our window (to
correspond to the right or bottom of our window). If any of these
conditions occur, then we simply need to reverse the corresponding
direction of our Bubble to simulate a bounce. Once we've checked
all four sides, we're contained!
We recommend to start with the right wall first, then bottom, then left, then top. Get them working one at a time and keep adding to your code. Excellent. Move on to the assignment for this week. You will continue right where this Lab left off. Lab Submission
You will submit your solution to this lab with the rest of A9.
Detailed instructions for doing this are posted in Assignment 9.
This lab is due by Tuesday, December 05, 2017 11:59 PM . | |
Last Updated: 11/05/17 20:40
|