CSCI 261 - Programming Concepts (C++)

Fall 2016 - Lab 12

Quick Links: Blackboard | EECS | Mines | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This lab is due by December 05, 2016 08:00am.


Concepts



For this lab you should download the SFML template that has initial code and other resource files for you to get started.

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:
  • a CircleShape which will be used to draw the Bubble
  • two doubles to store the XY direction the Bubble should move
Be sure to have the necessary getters and setters for your private data members. You may make non-default constructors as you deem necessary to set initial values on your Bubble class. Additionally, we want two public member functions:
  • UpdatePosition(): which should add the direction values to the position of the CircleShape


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 Week12. Detailed instructions for doing this are posted in Assignment 12.



This lab is due by December 05, 2016 08:00am.
Last Updated: 01/01/70 00:00


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0