CMSC 110 (Introduction to Computing)
Fall 2012 - Section 2
Assignment #6
Due by 4:00 pm on Tuesday, November 27, 2012
Task: Design an underwater creature that will live in a virtual aquarium.
Your creature should be implemented as a child class of the Creature class (defined below). Name your child class after your Emailusername. For example, my creature child class will be named Mfrusso. Your child class's constructor should take a single numeric size argument. The size of your creature should be close to that of a circle with diameter equal to the size argument. Make sure your child class includes one method called draw() and one called move() so that I can incorporate your creature into a sketch with other creatures. The move() method causes the creature to swim about using some model of motion. The draw() method draws your creature at its current location. Finally, your Creature child class should implement some special "move behavior." Some creatures will swim like a fish, or a submarine, some will wiggle, some might just stay in one place and rotate, flash, bubble, etc.
Steps:
from Processing import * # Base class for all creatures class Creature: # Construct the class def __init__(self, size): self.size = size self.x = random( width() ) self.y = random( height() ) # Move the creature def move(self): pass # Draw the creature def draw(self): ellipse(self.x, self.y, self.size, self.size) # Return the location of the creature as a dictionary def location(self): return {'x':self.x, 'y':self.y} # Your custom Creature child class goes here. # Use your email username as the name of the custom child class. # Override Creature base class methods as necessary to create custom behavior. # List of all creatures creatures = [] # Create at least three creatures and add to creatures list. # Create instances of your subclass here, not the Creature base class. creatures.append( Creature(50) ) creatures.append( Creature(75) ) creatures.append( Creature(60) ) # Create sketch window window(800, 600) # Draw all creatures def draw(o, e): # Draw the tank background background(128, 128, 255) # Draw and animate each of the creature objects for c in creatures: c.move() c.draw() # Draw all frameRate(30) onLoop += draw loop()
Extra Credit:
For up to 20 points extra credit, have your creature react to nearby creatures in the aquarium. Use the global creatures list to access all other creatures in the aquarium. Call the base class location() method to get the x-y location of each creature. If another creature is sufficiently close to your creature, modify the appearance of your creature in some way. Some might turn red or puff out, others might swim away.
If you choose to complete the extra credit, be certain to clearly indicate that fact in your assignment and include a description of your creature's behavior.
Requirements:
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.