Spring 2016, The College of Saint Rose

Lab 8: Furious Fowl
Due: 11:59 PM, Friday, March 18, 2015

For this lab, you will be developing what I hope you will find to be the most interesting program so far: you will develop a "furious fowl" game (legally distinct from Angry Birds, I'm sure).

You may work alone or with a partner on this lab. Only one submission per group is needed.

Getting Set Up

Download the a starter project with partial implementations of some of the programs from here.

Create a document where you will record your answers to the lab questions. If you use plain text, call it "lab8.txt". If it's a Word document, you can call it whatever you'd like, but when you submit, be sure you convert it to a PDF document "lab8.pdf" before you submit it.

Gravity

We saw a program that simulated acceleration due to gravity in the VanishingScribble example. The FallingLine ActiveObject there starts out moving very slowly but moves a bit faster (10% faster, to be precise) each time through its animation loop.

In the programs you will be writing for this lab, you will also be simulating gravity, but the objects on which gravity acts might be moving up and might be moving down. When moving up, the object slows down due to gravity. When moving down, the object speeds up. Many programmers when confronted with this task overthink the problem. To see one approach to this, study the animation loop in the run method of the BouncyBall class in the BallBounceAround example. Note that (other than the code that changes the color of the ball to shades of red when falling and shades of blue when rising) there is no distinction between upward or downward movement, or how gravity accelerates or decelerates the ball. It is achieved by adding a constant amount to the y speed each iteration. When the ball is going up (i.e., it has a negative y speed), this has the effect of slowing its upward motion. When the ball is going down, the effect is to speed its downward motion.

Practice Program

Since your main programming task this week involves an ActiveObject a bit different from the ones you've seen, we'll start with a practice program to create an ActiveObject that behaves similarly.

In the BallTossAround folder in the starter you downloaded, you will find a window controller class called BallTossAround that creates a FilledOval every time you press the mouse and passes that FilledOval to the constructor of an active object (which you will implement) that is responsible for moving that ball across the screen as if you "tossed" it upward to the right.

Most (all?) of the active objects we have seen so far are responsible for creating the graphical objects they animate. Here, though, the active object takes the object it animates as a parameter to the constructor.

Question 1: Ultimately, you will need to have the FilledOval that is created in the BallTossAround class moved by code in your ActiveObject's run method. What are the steps needed to make a reference to the FilledOval available in that run method? (2 points)

In addition to the reference to the FilledOval as described in the question above, your run method will also need to know about the canvas (or perhaps just its dimensions) so when the run method animates the ball, it can stop when the ball goes off the bottom or right of the canvas. Its run method should start the ball moving up and to the right, but the ball should be subject to "gravity" - its y speed should increase each time around the animation loop. So you should see the ball trace out a parabolic path. When the ball goes off the bounds of the canvas, the loop should stop and the ball should be removed from the canvas.

Practice Program: Complete the implementation of the BallTosser class. (6 points)

Question 2: Experiment with your program to try different values for the initial x and y speeds and acceleration due to gravity. What values work well to give the ball paths that look like each of the following? (2 points)

Furious Fowl

Your programming assignment is to implement a very simplified version of the popular Angry Birds game, where millions of people spend billions of combined hours launching birds at pigs. (Note that I am not judging or criticizing here, I am a recovering Angry Birds addict.) Since your program will have just one bird and one pig, maybe we could call it "Angry Bird". Better yet, we'll just call it "Furious Fowl". No sense drawing the attention of Rovio's lawyers.

The program stars with a bird sitting on a perch near the bottom left and a pig sitting somewhere near the bottom right of the canvas. To play, you press the mouse and drag around near the bird, resulting in a "sling" that follows your mouse around on one end but which remains anchored to the bird on the other. When you release the mouse, the angle of the sling determines a "launch vector" for the bird. The bird starts moving in the direction you launched him, and flies across the canvas, subject to acceleration due to gravity. The game ends in success if your bird bumps into the pig, or failure if your bird leaves the visible bounds of the canvas before bumping into the pig.

A few more details, hints, and other notes:

• Since your bird is already on the canvas before it starts to be animated, you will use the same idea as in the practice program, where you pass the graphical object to be animated as a parameter to the constructor of the active object.
• The pig should be placed somewhere in the lower right 75 ×75 corner of the canvas.
• There should be a message displayed near the top of the canvas that gives game instructions that change as appropriate depending on whether the mouse has not yet been pressed, the player is dragging to select a launch vector, the bird is in transit, or the game has been won or lost. Note that since the win/lose decision can only be made when the bird hits the pig or leaves the canvas, your active object that controls the bird's flight will need to know about the Text object that contains the message.
• There are a number of image files provided that you can use to create VisibleImage objects of the bird and pig. Note that this is only a small part of this assignment and you can earn nearly full credit if you use a couple of FilledOvals to represent the bird and pig.
• You will probably want a larger canvas than the default 400 ×400 for this program. Note that your program should work for any (reasonable) size canvas. Remember you can either change the default size in your BlueJ preferences or use setSize in your begin method to force it when you run.

Bonus Opportunity

You can earn up to 5 points of bonus for enhancements to the programming assignment. Check with your instructor for point values for any enhancements you wish to attempt.

There are two examples posted on the Examples page showing how to play sounds in Java applets - you are welcome to include some sound effects as part of your extra credit for this lab.

Submitting