DescriptionIn this activity you'll learn about a Greenfoot support class that can move smoothly across a world. Smoothly moving actors will be useful in future activities and games development.
- Start up Greenfoot.
- From the Scenario menu, select the scenario called Monsters.
- Create a new subclass of class Actor called SmoothMover. Open the editor and copy the source code for SmoothMover. Compile to make sure this part is correct.
- If you got an error “cannot find symbol - class Vector not found” you’re on the right track! Also notice that in the editor window, the symbol Vector is highlighted. This is one of the features of the Greenfoot IDE where it can help you debug your errors. If you take a peek at the code for SmoothMover, you’ll notice it makes use of a class called Vector. This is a Greenfoot Support class, not a standard Java class and is not part of the Actor hierarchy. We’ll need to copy and create this class in our own library. You’ll likely want to do this with other classes in the future.
- From the “Edit” menu, select “New Class…”. Name it Vector. A new class will appear in the box “Other classes” with this name. Open the editor for Vector and copy and paste the source code for Vector. Compile all. You should no longer see the error message.
- Create a new monster class (SmoothMonster?) by subclassing SmoothMover. You can use your own image, select from the image library or try this image.
- Using the editor, add these constructors for SmoothMonster.
- To make this new class do something, you will need to modify the act() method. Again, use the editor for SmoothMonster. This time we'll ask you to show your creativity instead of yet-another-cut-and-paste.
- Compile, add a SmoothMonster and run the scenario.
- Read Digging Deeper on Vector and SmoothMover to learn about Greenfoot support classes and the Vector and SmoothMover classes.
- Please read the following instructions for preparing your work prior to submission to this activity.
- Select Scenario -> Export. Choose Webpage (from Publish, Webpage, Application) and select a location to save the scenario as an applet (a jar file and a .html file).
- Export this as a jar file and submit for this activity.