Do this project on your own. We'll go back to partners for the final couple weeks.
You may, of course, discuss the project with classmates if that helps you think things through.
We will, together, write a Java program with sprites moving around in a window, making sounds.
This work will be based on the JavaFX library. You can find tutorials on JavaFX in lots of places,
(e.g. this one from JetBrains).
The final main program will be written by Jeff, with one Sprite subclass written by each student.
This main program will not implement the bouncing-ball style of movement found in SpriteWorld.
It will do something different, showing off each student's sprite and then allowing the sprites to
do something fun all together. As long as you pay attention to the expectations listed below, all of this should
go well, and the result will be weirdly spectacular.
What to do
- Pull the latest from
Jeff's CS257 github repository. Open the
sprites project in IntelliJ and play around with it. Take a look in particular at the
start(Stage) method, which is where the user interface gets initialized. Can you replace
the spinning moose with a non-spinning moose? Can you decouple the box around the moose
from the moose to make it go in some other direction? Can you make the green ball blue?
Can you make the ball go twice as fast? etc.
- Create a Sprite subclass called YourUserName.java in sprites/src/sprites/.
You may also add resource files src/res/yourusername1.png, src/res/yourusername1.wav,
etc. as needed. Using your user name in the naming of these files is essential
to prevent naming conflicts when I assemble all the sprites in one place.
- Implement and test your Sprite subclass. In doing so, keep in mind the general
principle that the caller (e.g. the code that instantiates and manipulates
your sprite, like the SpriteWorld class does with SpinningMoose and Ball and Box)
should be given reasonable control over the size, velocity, and position of your sprite.
This principle implies that:
- Your sprite should start out at the position most recently specified via
the setPosition method. The "position" of a sprite refers to the upper left corner
of the sprite's bounding box.
- Your sprite should remain approximately the size most recently specified via
the setSize method. You can test this by doing what I did with the Box object
in my version of SpriteWorld. I created the Box at the same position and velocity
and size as the SpinningMoose, so you could see that the moose didn't wander away
from the Box, or grow outside its bounds. Note that during its spinning, the moose
does slop outside the Box, but it does not go outside the smallest
circle containing the Box.
- Your sprite should move, on average, one velocity's worth of distance for
each time step() is called. You could get creative and, for example, make your sprite speed up
and slow down, but over time, you want the sprite to be approximately where the
Box with its same velocity/position/size would be after the same number of steps.
- To make your sprite adhere to the expectations listed above, you'll likely need to override
Sprite's setSize method to make sure all the child objects in your sprite get resized appropriately.
- To give your sprite interesting behavior, you'll probably want to override Sprite's
step and makeSound methods. Here are a few ideas for making a sprite's behavior interesting
without violating the above expectations:
- Your sprite could expand to 110% of its expected size, contract to 90%, expand to 110%, etc.
over a long enough sequence of calls to step. This would be like making your sprite look
like it's breathing.
- Your sprite could move in a slightly jittery fashion rather than in exactly a straight line.
- Your sprite could have internal animations over multiple steps--maybe an eye could wink,
or a hand could wave, etc.
- As you work on YourUserName.java, you must not alter Sprite.java.
- Submit your sprite by creating a folder called "sprites" at the
top level of your cs257assignments-* github repository, containing a copy of my IntelliJ project
including your new sprite-related files. Tag it "sprite".
This will be an 8-point assignment. 6 points for a sprite that meets the expectations above
without being a copy of my existing sprites. 1 point for a small amount of coolness, and 1 more point
for extra coolness. I will be generous.