Computer Science 1xx – Assignment #N

DUE DATE: mmddyyyy  


The Famous 'Burst-A-Bubble' Game!


Learning Objectives:
(This is a list of the major topics that you, as students, will learn in this assignment:)

  1. Inheritance
    In this assignment, you will have to derive a class from the Projectile class, and make use of the inherited methods and/or data fields
  2. Overriding / Polymorphism
    In this assignment, you will have to derive a class from the Projectile class, and then override several methods in order to correctly implement the Fireworks class.
  3. Understanding and Modifying Existing Code
    In this assignment, a major goal is to expose you to a non-trivial amount of code that someone else has written, and make sure that you can add you code to it.  Further, it is not sufficient to just add code until things work - you need to add a minimum amount of code, that exploits and builds upon the provided code, so that your code is really an extension of the provided code (rather than a hacked together after-thought)

Grading Rubric: This document is available for you use - you should use it to  to help guide your work. The rubric is a document which explains how your work will be evaluated, and is located here.


In this assignment, you are going to implement a new class, in order to add a feature to a conceptually simple video game. 


·         The overall objective of this assignment is for you to create a new class, within an existing, non-trivial program.


·         The overall objective of the game is to allow the player to throw small things at floating bubbles, and thus break the bubbles. 


An outline, in pseudocode, of the game is as follows.  The game starts out by creating a BurstABubble object (described briefly, below), which in turn creates many Bubble objects.  The game will then enter the standard XNA main loop, where it repeatedly calls the UpdateWorld method, and automatically draws all objects. 

The person who's throwing things will be represented by a point at the origin (0,0).  The person initially can only throw small rocks.  Each rock that's thrown will be represented by a circle that has a radius of 1. 

Your primary task for this assignment will be to implement a 'Fireworks' class – these can be shot towards the bubbles, after after a predetermined amount of time, will explode.  Amongst other things, the BurstABubble object is responsible for randomly placing bubbles on the screen.  In addition to the primary task listed above, your secondary task is to modify the program so that the radii and locations of the bubbles are chosen randomly. These tasks are described in more detailed below, and listed in the order that the program will execute them.

Please note that you don't need to modify much of the existing program, and that you will be penalized if you do modify parts of the program other parts that you have to modify, in order to accomplish the objectives of this assignment.  Once you've looked at the code, it should be clear what you'll need to modify ; this restriction is here in order to prevent students from (re)writing large blocks of the game's code (instead of figuring out what the code already does, and simply using the existing code).


Secondary Task: Randomly Placing Bubbles

As part of creating a new game, the BurstABubble class will place bubbles on the screen.  You will need to modify this, so that the Bubbles are placed randomly, rather than in fixed locations, which is how they are currently placed, in the student starter project.

Each Bubble has an (X,Y) location (which is the center point of the circle), and a radius between 1 and 5.  Each bubble should be at least 30 units away from the player on each of the X axis, and at least 30 units away on the Y axis – in other words, far enough away that there's a chance the player might miss them (e.g., they don't overlap the origin, etc). Four bubbles should be pretty close (under 50 units' distance on each axis), and four should be farther away (at least 60, and no more than 90 units of distance on the X axis, and at least 10, and no more than 50, units up on the Y axis).  It is fine for any randomly placed bubbles to overlap.  Make sure that you avoid the use of magic numbers in your code.


As you examine the code, you'll notice that the m_bubbles array will have more than 8 spaces in it  - the total number of bubbles will always be 40.  You are required  to place the remaining bubbles on the screen, in one of three ways:

  1. Randomly, anywhere on the screen 
    It is fine for a randomly placed bubble to be partially off the screen, but at least 50% of every bubble must be on the screen.  It is fine for any randomly placed bubbles to overlap.  If you chose this option, it must be possible for a bubble to place at any location that's on the screen (i.e., you can't chose to only place bubbles within a subsection of the screen)

  2. In a nice, visually pleasing (and non-random) pattern of your choosing
    You're welcome to come up with some sort of interesting pattern here - circles, stars, spirals or anything else you can think of.  The only requirements are that
    (a) no two bubbles can be at the exact same location, and
    (b) the 'shape' can't be too simple (i.e., don't use choose this option, then put all the bubbles in a line, in
    order to avoid the work of having to figure out how to randomly place the bubbles anywhere on the board :)  )
    (c) you need to place the bubbles with a (reasonable) minimum of code.  In particular, simply creating 32 ( = 40 - 8) bubbles on 32 separate lines, and hard-coding the location of each individual bubble on each of those lines, will get you no credit.

  3. A combination of the above
    For example, maybe you'd like to create a spiral of 20 bubbles, then place the rest randomly, anywhere on the screen.


Primary Task: Implementing the Firework Class

Before we look at this in detail, let's first get a quick overview of how the logic for the game works.  Keep in mind that most of this logic has been implemented for you – I’m including this description here to help you figure out what you'll need to do.  The game mostly consists of the standard XNA loop, wherein XNA first calls the BurstABubble.InitializeWorld method, and then calls the  BurstABubble.UpdateWorld method (both of which are provided for you in the starter project).  In order to simplify this some, UpdateWorld calls the PlayRound method, whose underlying purpose is  to move everything that the user has thrown (according to the speed each thing is traveling at).  The system continuously draws everything onto the screen in their new, updated positions, so that everything looks right.  Now let's examine the most important parts of the UpdateWorld logic.

First , the game logic that has been provided to you will check to see if the player has decided to throw a Rock or a Fireworks. If so, the provided logic will create the new object, and set up everything so that it will be included in any future updates.  

Second, the game will go through the array of things that have been thrown, and moves each thing (by calling the DoObjectUpdate method).  For example, in the DoObjectUpdate method, each Rock is moved based on the X, Y speed of the Rock.  Note that since we're not looking to accurate simulate physics in this code, we keep track of the speed in the X direction, and simply add the speed in the X direction to the current position's X value.  Similarly for the Y speed and position.  After moving each thing, the program roughly approximates the effect of gravity on each Rock by adjusting the vertical speed of the thing (gravity should pull the rock downward at a rate of .005 units of speed per update). 

As the program moves each thing, it checks to see if the thing overlaps one of the Bubbles.  If the thing does, then the Bubble will be removed the screen.  If a thing hits the ground (it's vertical height becomes zero), then it is removed from play (it doesn't bounce, etc).  Each thing disappears once it's clear that the rock/Fireworks/etc can't possibly interact with any bubbles (i.e., once the rock has gone past the bubbles, or hit the ground)


Your task, for this assignment, is to implement the Fireworks class.  In order to successfully accomplish this, you'll need to fill in a small (but important!) amount of code in the Fireworks.cs file itself (which is located in the Projectiles folder).  The key difference between a Fireworks object and Rock object is that the Rock object will always be the same size (until it is removed from the screen), whereas a Fireworks object will stay the same size for some amount of time, then explode.  When it explodes it expand to a radius of 20 units.(after is explodes, the fireworks is removed from play, no matter where it is on the screen).  As you're implementing the Fireworks class, keep in mind that our fireworks aren't affected by gravity – they change their X & Y position based on their X & Y speed each round, and nothing else.


Since one of the objectives for this assignment is to start getting used to working with non-trivial amounts of pre-existing code, you will need to utilize existing code, rather than (re)writing the logic from scratch.  For example, you'll notice that the starter code (in Fireworks.cs) that has been provided to you already inherits from the Projectile class.  Thus, you'll need to first spend some time examining how the existing game code decides to remove an object from the screen, how to set the size of an object, etc, etc, and only after you've done that, will you then implement your Fireworks class.  It is recommended that you find something similar to the Fireworks class (such as the Rock class), and spend some time examining how that similar class works, in order to figure out what abstract & virtual methods you need to override, and how you should go about overriding them.  If you wish to improve the game (i.e., go above and beyond the requirements of this assignment, and add a feature(s) that aren't already present in the program), you should talk to the instructor, first, in order to make sure that you don't accidentally violate the rule that you're not allowed to unnecessarily modify code to complete the assignment.


Also, the .ZIP of the starter project contains a SampleSolution folder, you can double click on the the .EXE in that folder to examine the Fireworks implementation (although the bubbles locations' aren't randomized), in case you want to play around with how the game 'should' work.




Getting started on the assignment:

Here is the starter project where you should work to complete the assignment. You should be able to compile and have a skeleton program where you can burst bubbles with rocks (Button-A). The .exe file in the SampleSolution folder of the start project is an implementation of solution. Check out the fireworks that you can release with Button-B!

How To Play The Game:


How To Play The Game:
Game/Program Controls:XBox
When running the game/program, you can control it using the following Gamepad controls:
  • 'A' button to throw a Rock

  • 'B' button to shoot off a Firework

  • Left Thumbstick controls the direction & initial speed of the thing that is being thrown/shot.

Game/Program Controls: PC
When running the game/program, you can control it using the following keyboard controls:

Here is the keyboard to controller mapping.


Using a keyboard: Here is the keyboard to controller mapping.


Group Work, Commenting:


            You are not allowed to work in groups for this assignment.  You should start, finish, and do all the work on your own.  If you have questions, please contact the instructor.


            Additionally, you should aggressively comment your code, paying particular attention to areas that are difficult to understand.  If you found something to be tricky when you wrote it, make sure to comment it so that the next person (the instructor, who's grading you) understands what your code is doing.  It is not necessary to comment every single line.


The purpose of this requirement is to both help you understand, and have you demonstrate, a thorough understanding of exactly how your program works.


Every file that you turn in should have:

·        At the top of each file that you normally edit     , you should put your name (first and last), the name of this class (“BIT 142”), and the year and quarter, and the assignment number, including the revision number, which starts at 0 (“A4.0”).  If you’re handing this in again for a regrade, make sure to increase the minor version number by one (from “A4.0”, to “A4.1").
You normally edit the C# source code files (.CS files), and any Word documents that you're handing in (if any).
You do not normally edit the .SLN or .CSPROJ files, and so you should not try to put this identifying information in those files.


In general, you should make sure to do the following before handing in your project:

·        All variables used should have meaningful names.

·        The code should be formatted consistently, and in an easy to read format.   


What to turn in:


·        A single electronic folder (a directory).  This folder should contain:

o       The source code for the classes.  For this assignment, each class should go into a separate .CS file.

o       The project files – stuff ending in .SLN and .VCPROJ, so I can build your project more easily.

o       You have to name the folder with your last name, then first name, then the assignment number (both the major version – 4, and the minor (revision) number – 0).  Example: "Panitz, Mike, A4.0"


·        You should not include the bin or obj subdirectories, or anything from it.  I will dock you a couple points if you do.  Also, you don't need to include your .NCB file, or the .SUO file, if it's present.


How to electronically submit your homework:

There's a link on the homework page to the document that guides you through handing in your work, using the SourceGear Vault program.


This document and the related materials are developed with support from Microsoft Research Computer Gaming Initiative under the Computer Gaming Curriculum in Computer Science RFP, Award Number 15871.