Tino Intro To Java

Last modified: April 25, 2023

Greenfoot Practice Quiz 1

This is a practice quiz designed to prepare you for the Greenfoot Unit Test.

Practice Quiz Instructions

  1. Here is a video of what the final product looks like.
  2. Make a new project
  3. Make the MyWorld unbounded by modifying the call to super()
  4. Create a class named Laser and choose an image for the laser.
  5. When a laser is in the world, it travels straight in whatever direction it is going until the center of the laser gets to an edge and then removes itself. You decide the speed.

    Test your code at this point. Drop a new Laser in the world and see what it does. It should go to the right. Drop a new Laster in the world and right click on it and call setRotation to change the rotation. Press run and the laser should go in the direction you set the rotation to.

  6. Create an animal class of your choice (you pick the name and image).

  7. Animals should appear in random locations fully on canvas every 100 frames.

    Test your code at this point. Animals should appear every 100 frames.

  8. When an animal is on the canvas, it always moves either left, right, up or down but never diagonally.

    • It starts out in a random direction and there is a 5% chance every frame that the direction will change to a new random direction.
    • If an animal touches an edge (edge of image is past an edge), it picks a new direction excluding the direction of the edge.

      To make things simpler at first, you could say an Animal is touching an edge if its center reaches an edge of the canvas. You can adjust the edge detection later.

  9. Lasers fire from the center of the bottom edge of the canvas toward a random Animal every 50 frames ONLY if there is an animal in the world. It's ok if there is more than one laser in the world.

    Hint: If using turnTowards(), the Laser must be added to the World first, before calling turnTowards()

  10. When an animal touches a laser, the animal and laser should both be removed.

Submission Instructions

Zip your entire project folder and submit it below.

  • Name your project folder PX_LastName_FirstName_PracticeQuiz.
  • Right click on your project folder and Send To -> Compressed (zipped) folder. On a mac compressing is similar, using a right click, but has a slightly different option.
    • You should end up with a zip file named PX_LastName_FirstName_PracticeQuiz.zip. For example if you were in 3rd period and named Michael Wang, then you would name the file P3_Wang_Michael_PracticeQuiz.zip
  • Fill out the Greenfoot Practice Quiz 1 Self Assessment to indicate what is working and what is broken.

You must Sign In to submit to this assignment

Dark Mode

Outline