6.837 - Assignment #1
Ground Rules:
- Feel free to discuss assignments and your approach with others.
- The design and code must be your own.
- Don't use code from previous semesters.
- Cite any models, images, ideas, or algorithms that you do not develop yourself
- Assignment is due before midnight of the day indicated
- A working version of your applet and source code must be linked to your course home page
- All source code must also be submitted via Athena's turnin procedure
- Check this page frequently for updates and clarifications
Objective:
In this assignment you will become more familiar with
the Raster object given
in class.
You will extend the Raster class to create both a sprite and scrolling play field
class.
You have a great deal of design freedom in deciding exactly what
you will do in this exercise.
You can simply move sprites in response to mouse clicks
in the sprite's play field; at the other extreme, you can write a
space invader game.
Requirements:
- You should not modify the given Raster object, but extend it.
- Your applet must use at least two different sprites (with different images).
- You must demonstrate your sprites by moving them around the play field.
- Your sprites should be properly clipped against the edges of the play field.
- Your sprites must implement transparent pixel regions. You are not require to implement alpha blending, just opaque and transparent pixels. The idea is that you are loading rectangular images, and your sprites will not be rectangular, hence some of the pixels in your rectangular image will be transparent. As a side note, certain images (some GIFS) set the alpha channel of its pixels for you (ie support transparency in the file format); There are other image formats that don't, namely JPEG. Here you will have to devise your own way to determine which pixels of the image (for example: the white pixels) will be transparent and which will not.
- Your sprites must provide a method that tests if a given
play field coordinate falls upon a non-transparent pixel of the sprite
at its current position. Your applet must demonstrate this capability. For instance, you can have the status bar state whether you are clicking inside the sprite (non-transparent region) or not; This is just one example, you may demonstrate this in any way you choose.
- Your Playfield class must be a initialized with an image and provide
methods for scrolling the image (the background) about the play field. Your applet must demonstrate the scrolling capability of your Playfield. Note that you are not required to animate this capability, you could for instance scroll the background every time you move a sprite or in response to an event.
- You must include your applet on a web page that is linked to your
course web page. This page should include instructions on using your
applet, and any other information or observations that you believe will
be useful to the graders of your project (i.e. you need 10000 points
for another life, unless you are a professor in which case only 5000
points are required).
Discussion:
There is no requirement that you animate your applet. If you wish, you
can make it entirely event driven. For example, a left mouse click on an unoccupied
region of the play field might indicate that a selected Sprite should be moved
to the current mouse location. If you click at a point occupied by a sprite, it might cause
the sprite to be selected print "Ouch" on the status line.
Right mouse clicks might cause the background to shift.
Of course you may add as much animation as you would like to
your system. You can spawn threads for each Sprite so that it moves autonomously using
a timer and various rules. However, I suggest that you get something working that
satisfies the minimum requirements first.
Other Extras (to impress):
- An interesting application/game
- Animated sprites
- Scalable (isotropic or nonisotropic) sprites
- Alpha channels in sprites
- Lots of other stuff
Resources:
Here are some example sprites that you may find useful for this assignment.
You can also use anything else that you find. To make copies
of these using Internet Explorer or Netscape simply right-click on the images
to specify a filename and directory.
Below are a few examples of animated sprites that you can use. You can
download them in exactly the same way as described above. If you choose to
implement an AnimatedSprite class, you can feel free to deviate from the
interface that I gave in class. You might feel tempted to use an animated
GIF files as source images for your AnimatedSprite class. Doing this is
much harder than you might imagine. I have found it much easier to include
all of the frames of the animation (concatenated side-by-side) into a single
image file. There are several image editors that allow you to do this
cutting and pasting operations easily. The number of frames in the animation
can be communicated as a parameter to the applet. If all frames are the same
size the images can be diced up easily.
To give you some idea what I mean, here is the parameter list that I
used for my version of this exercise.
<applet code="Sprite.class" archive="Sprite.zip" height="300" width="400">
<param name="sprite" value="MonkAni.gif, 7, 2,0,0, 1,-13,0, 0,-8,0, 1,-4,0, 2,-13,0, 3,-19,0, 4,-19,0, 3,-4,0, 2,-16,0, 5,0,0, 6,0,0, 5,0,0">
</applet>
The first argument is the image file the second is the number of frames
in the animation. The subsequent sets of triples, indicate an animation
and motion sequence (frame, delta_x, delta_y).
If the idea of parsing a parameter field scares you, take a look at the
StringTokenizer class in the java.util package.
5 frames of a walking ant (750 x 120).
One possible animation of a walking sequence is
0-1-2-1-0-3-4-3.
7 frames of a monkey (897 x 180).
Frames 0-1-2-3-4-3-2-1 are his gait, and the sequence 2-5-6-5-2 is
a turn of his head.
12 frames of a rotating world (768 x 64).
Obvious animations are 0-1-2-...-11.
Last Updated: 9/25/00