CSCI 200 - Summer 2023
Foundational Programming Concepts & Design

A4 - SFML: Bubble Bobble

→This assignment is due by Friday, June 09, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A, L4B
→ Do not forget to complete zyBooks Assignment 4 for this set.←

· Instructions · Rubric · Best Practices · Submission Process · Submission Contents ·


Concepts


You are going to create magic bouncing balls to watch as they move around the screen.


Class Creation


For this assignment you must first create a class calledBubble. The Bubble class needs to have the following private data members to store information:

Be sure to have the necessary getters and setters for your private data members and/or you may make non-default constructors as you deem necessary to set initial values on your Bubble class.


Draw It!


In ourmain(), before we get to the draw loop we want to make our Bubble object. 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.

Next inside our draw loop, after we've cleared the window and before we display the window, we need to draw the bubble. Add a public method to the Bubble class called draw() that accepts an SFML RenderWindow object by reference. The function then draws the CircleShape member of the class.

At this point, run your program and you should see a white circle. Perfect! Let's continue.


Move It!


We need to add another public member function called updatePosition(). This function needs to add the direction values to the position of the CircleShape.

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 in the range of [0, 0.2] for xDir & yDir respectively. (Note: feel free to tweak these values up/down if it moves too slow/fast.)

Now in our draw loop, after we've checked the events we will check the time. If the elapsed time has eclipsed 1/60th of a second, then call updatePosition() on the object.

Run your program. It should be moving now. Oh no! It went off the screen. Let's keep it in view.


Bop It!


The last part of the bubble is have it bounce around the window. Recall that the position for a CircleShape corresponds to the upper left 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!

Modify Bubble::updatePosition() so that it accepts the window width and height as parameters. Now after moving the bubble, check if the bubble went over a wall. If it did, move the bubble backwards and then reverse the necessary direction.

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.

Run the program and watch it stay within the window. Excellent.


Bubbles Bubbles Everywhere


We want to replace our single Bubble object with a vector of Bubbles. Before your draw loop, create a vector of five bubbles initially. Give each bubble a random starting position between 100 and 400 for X and Y and a random direction for X and Y in the range [-0.1667, 0.1667]. Additionally, give each Bubble a random radius between 10 and 50. Lastly, give each Bubble a random color so we can tell them apart.

Inside our draw loop, we now need to draw all the Bubbles in our vector. After our event handling, we'll then need to update the positions of all the Bubbles in our vector. You should now see five Bubbles bouncing around the window. Excellent. Let's have the user interact.


Pop-A-Bubble


When the user clicks the left mouse button, we want to create a new bubble positioned at the location where the user clicked. This new bubble should have the same random starting properties that our original bubbles did. After the user clicks the first time, we should see six bubbles moving around the window. A second click, seven bubbles. And so forth as the user continues to click.

We may get to the point where there are too many Bubbles on the screen. If the user presses the D key, then we want to delete the last bubble that was added to the window. Obviously if there are no Bubbles in the window, then pressing D should do nothing.

If the user starts your program, clicks twice, then presses D three times, we should be seeing four bubbles on the screen.


UI Design


As a final step to make the program more user friendly, if the user presses the Q or Escape key, automatically close the window.


Best Practices To Follow


· Code Style · Code Correctness · Code Structure · Dynamic Memory Management · Software Engineering Design Principles ·

Code Style

The following set of guidelines ensure all code in this class will be written in a similar and consistent manner, allowing any reader to understand the program's intent and contents.

Code Correctness

The following set of guidelines ensure all programs written in this class behave properly without side effects.

Code Structure

The following set of guidelines ensure all programs written in this class are done in an abstracted, modular, extendable, and flexible manner.

Dynamic Memory Management

The following set of guidelines ensure all programs written in this class behave properly without side effects.

Software Engineering Design Principles

The following set of guidelines ensure all program components written in this class are done in an abstracted, modular, extendable, and flexible manner.


Grading Rubric


Your submission will be graded according to the following rubric.

PointsRequirement Description
10 All labs completed and submitted
L4A, L4B
+3 L4B Extra Credit
10 Bubble class created, structured, and implemented correctly. Appropriate member fields and member functions specified.
4 Bubbles move on screen.
4 Bubbles bounce off each wall without getting stuck on the wall.
4 Bubbles can be added and deleted without error.
4 Bubbles added at mouse location.
4 Bubble properties randomized.
3 Window can be closed by user.
5 Best practices are followed:
  • +5 Code is easily readable, follows best practices, well structured
  • +4 Code is easy to follow, only a few small violations of best practices
  • +3 No egregiously bad practices
  • +2 Lots of violations of best practices
  • +1 Little effort to follow best practices
  • +0 No effort to follow best practices
0 Submission structured appropriately. Submissions structured improperly will receive deductions.
48 Total Points

→This assignment is due by Friday, June 09, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A, L4B
→ Do not forget to complete zyBooks Assignment 4 for this set.←


Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.

It is critical that you follow these steps when submitting homework.

If you do not follow these instructions, your assignment will receive a major deduction. Why all the fuss? Because we have several hundred of these assignments to grade, and we use computer tools to automate as much of the process as possible. If you deviate from these instructions, our grading tools will not work.


Submission Instructions



Here are step-by-step instructions for submitting your homework properly:

  1. Make sure you have the appropriate comment header block at the top of every source code file for this set. The header block should include the following information at a minimum.
    /* CSCI 200: Assignment 4: A4 - SFML: Bubble Bobble
     *  * Author: XXXX (INSERT_NAME) * Resources used (Office Hours, Tutoring, Other Students, etc & in what capacity):  * // list here any outside assistance you used/received while following the * // CS@Mines Collaboration Policy and the Mines Academic Code of Honor *  * XXXXXXXX (MORE_COMPLETE_DESCRIPTION_HERE)  */
    Be sure to fill in the appropriate information, including:
    • Assignment number
    • Assignment title
    • Your name
    • If you received any type of assistance (office hours - whose, tutoring - when), then list where/what/who gave you the assistance and describe the assistance received
    • A description of the assignment task and what the code in this file accomplishes.

    Additionally, update the Makefile for A4 to generate a target executable named A4.

  2. File and folder names are extremely important in this process. Please double-check carefully, to ensure things are named correctly.
    1. The top-level folder of your project must be named Set4
    2. Inside Set4, create 3 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g. L4A, L4B, and A4).
    3. Copy your files into the subdirectories ofSet4 (steps 2-3), zip this Set4 folder (steps 4-5), and then submit the zipped file (steps 6-11) to Canvas.
    4. For example, when you zip/submit Set4, there will be 3 sub-folders called L4A, L4B, and A4 inside the Set4 folder, and each of these sub-folders will have the associated files.

  3. Using Windows Explorer (not to be confused with Internet Explorer), find the files named main.cpp, Makefile, *.h, *.hpp, *.cpp.

    STOP: Are you really sure you are viewing the correct assignment's folder?

  4. Now, for A4, right click on main.cpp, Makefile, *.h, *.hpp, *.cpp to copy the files. Then, return to the Set4/A4 folder and right click to paste the files. In other words, put a copy of your homework's main.cpp, Makefile, *.h, *.hpp, *.cpp source code into the Set4/A4 folder.

    Follow the same steps for each lab to put a copy of each lab's deliverable into the Set4/L4 folders. Do this process for Set4/L4A (Warehouse.h, Warehouse.cpp), Set4/L4B (main.cpp, Makefile, data/*).

    STOP: Are you sure your Set4 folder now has all your code to submit?

    The structure of the submission is as follows:
    • Set4/
      • A4/
        • main.cpp
        • Makefile
        • *.h
        • *.hpp
        • *.cpp
      • L4A/
        • Warehouse.h
        • Warehouse.cpp
      • L4B/
        • main.cpp
        • Makefile
        • data/*
    Include any files denoted by * only if present and appropriate to the implementation.

  5. Now, right-click on the "Set4" folder.
    1. In the pop-up menu that opens, move the mouse "Send to..." and expand the sub-menu.
    2. In the sub-menu that opens, select "Compressed (zipped) folder".

    STOP: Are you really sure you are zipping a Set4 folder with sub-folders that each contain a main.cpp file in it?

  6. After the previous step, you should now see a "Set4.zip" file.

  7. Now visit the Canvas page for this course and click the "Assignments" button in the sidebar.

  8. Find Set4, click on it, find the "Submit Assignment" area, and then click the "Choose File" button.

  9. Find the "Set4.zip" file created earlier and click the "Open" button.

    STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?

  10. WAIT! There's one more super-important step. Click on the blue "Submit Assignment" button to submit your homework.

  11. No, really, make sure you click the "Submit Assignment" button to actually submit your homework. Clicking the "Choose File" button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!

  12. Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!

In summary, you must zip the "Set4" folder and only the "Set4" folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this homework, and you must click the "Submit Assignment" button. Not doing these steps is like bringing your homework to class but forgetting to hand it in. No concessions will be made for incorrectly submitted work. If you incorrectly submit your homework, we will not be able to give you full credit. And that makes us unhappy.


→This assignment is due by Friday, June 09, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A, L4B
→ Do not forget to complete zyBooks Assignment 4 for this set.←