We will now work with the ideas of actually controlling the movement of our actors with Vectors and using the methods in the Actor class to detect edges and other actors on the screen..
If you don't remember how to do any of the steps (like, copying, zipping, etc), please refer back to Lab 1.
First, you will need to copy over the scenario for this assignment. If you are working from home, you can download the scenario here. If you are in lab, the scenario is located in /eng/class/notes/cse113/Lab6.
Take note of the following classes in the scenario:
You should create classes for each of the following objects that will be in the scenario: Mushroom, Flower, GoldBall, TeddyBear, Skull. (Note the spelling/case of these class names and follow them exactly.)
Your scenario should open with the following at various locations throughout the world: one hero, six mushrooms, four flowers, one gold ball, one teddy bear.
The hero in this scenario should move "forward" whenever act is called. Note that Hero is a subclass of SmoothMover, so calling the move() method (as is already in act()) will do the job IF a vector whose values are greater than (0,0) has been set as the SmoothMover's vector. You will need to fill in the constructor of Hero so that a proper Vector is given to the superclass via a call to the superclass' constructor.
The hero must check for the edges of the world and wrap around if it reaches an edge left/right and top/bottom. This code needs to be written in the SmoothMover class (there are comments in that file to direct you). Note that in the method in SmoothMover, it first changes the x & y position. From there, you need to make sure that the x & y have not gone off the screen, and if so move the SmoothMover to the opposite end of the world.
When the user presses the right arrow key, the hero should turn right (visually on the screen). The amount of degrees is up to you. Analogously, if the user presses the left arrow key, the hero should turn left. At this point, don't worry about the hero actually changing direction, simply have the graphic change. Note the methods turnRight() and turnLeft() and fill them in appropriately.
Now go back and make the Hero actually rotate and then move in the direction of the rotation. Remember what we know about Vectors. Vectors are a direction (!) and a length. The direction will be the rotation of the actor and the length will remain unchanged. Recall that you can get the movement vector by calling getMovement() and storing it in a local variable. Then, you can setDirection() on that vector to be the new direction.
If the hero encounters a skull, the scenario should stop. Fill in the method named checkForSkull in your Hero class appropriately. In order to test out this functionality, you must manually add a skull to the world.
Once you have completed your work, you will submit the zipped up version of the Lab 6 scenario.
For directions on submitting, please see here.
Please recall that you must achieve a grade of at least 50% on each of the labs to be allowed to take the second practical exam. This means, that your labs are technically all due by the last day of class (December 10th). However, if you want to stay current with the course, I would recommend having this assignment completed soon (like a week), but this material will not be on the first lab practical exam.
Please make sure to look at your grading information on Web-CAT. See the grading information page for more details about how to interpret Web-CAT grade reports.
The following tests were run on your assignment submission. Each test was given equal weight, so 8.3333 points each part.
Lab authored by Adrienne Decker