The purpose of this project is to get you warmed up on programming in Java, and to start you thinking about program structures that make use of polymorphism and inheritance.
Your program will start with a class named Animation.java
, which
will have the main
method that launches the program. You'll
run your program via a command line like this:
java Animation sprites.txt 500 300
where sprites.txt
contains a textual description of the
various objects (sprites)
that will be moving around in your animation, and 500 and 300 are examples
of the animation window width and height, in pixels.
When you run this program, some sort of animation will take place. Spaceships in space, butterflies in a meadow, cars in a city, zombies in the park, or whatever strikes your fancy. The keys to this program will be the use of Java and adherence to the structure described in the next section, so the particulars of your animation don't matter a great deal.
I know that some of you likely did a similar project in CS 111 (or 117 if you've been around here long enough). If so, just start this one fresh, pay attention to the guidelines below, and pick a new animation context.
Your program will consist of:
A main
method in Animation.java
with a
structure like this (in pseudo-code):
You may want to just erase the whole canvas in your "do forever" loop. Note that I am not looking for smooth animation.
A top-level Sprite
class like this (assuming you
use the Canvas library
Canvas.java):
Sprite
,
representing the various kinds of objects you want to include in
your animation. These classes will contain overrides of the
methods in Sprite
to arrange for the drawing, stepping, etc.A factory method
in
Animation.java
that returns a reference to a newly instantiated
object of whatever subclass of Sprite
is indicated in
the description
string. We'll talk more about this in class.
The sprite file will consist of lines of text, one per sprite, of this format:
For example:
would, presumably, cause the instantiation of an object of type Goat
with initial position (200, 100) and initial velocity (10, 0) and initial
color purple.
You are free to add features to your particular sprite types, making corresponding additions to the "other info" section of the sprite description line in the sprites file.
Questions? Let me know.
Have fun.