CMSC 110 (Introduction to Computing)

Fall 2011

Assignment #5

Due by 4:00 pm on Friday, November 23, 2011

Task: Design an underwater creature. Make sure to name the class as <YourFirstInitialLastName>Unit. For example, Michelle Obama's creature will be defined in a class called MObamaUnit. Your class's constructor should take a single float argument that is approximately the object's size. The value of this argument should be roughly the diameter of a circle that encompasses your object. In addition to the constructor, make sure that the class includes one method called display(), and one called move() so that one can incorporate your creature into a sketch with other creatures. Use the following as your starting template.

MObamaUnit myCreature;

void setup() {
  
  size(800, 600);
  smooth();
  float myObjectSize = 75;  // Set this to an appropriate value

  // Create one instance of your creature
  myCreature = new MObamaUnit( myObjectSize );

}

void draw() {

  myCreature.display();   // display the creature
  myCreature.move();      // move it

}

// --------------------------------------------------------------
// Please put this part of your code in a separate file
// Your class should follow this outline

class MObamaUnit {
  float x;      // Current x-position of creature
  float y;      // Current y-position oc creature
  float s;      // A scale parameter that is roughly the creature's diameter

  MObamaUnit( float tsize ) {
    // Init size field
    // Randomly set x and y position in the tank
  }

  void display() {
    // Draw the creature at the current x,y position,
    // scaled by the s parameter
  }

  void move() {
    // Move the position of the creature using some appropriate algorithm
    // Animate the creature with onr or more "move behaviors."
  }
}

The focus should be on the use of classes to define the object factory. You will need to write the constructor, a display() method and a move() method, as described above.

In addition to moving the x,y position of your creature over time, define at least one "move behavior" appropriate to your creature. Some creatures will swim like a fish, or a submarine, some will wiggle about, some might just stay in one place and rotate, bubble, etc.

Note that the final showcase will include one instance of each creature defined by you and your classmates swimming together in a single aquarium sketch.

What to Hand in:

Extra Credit: