CS324e - Assignment 6

Placed Online: Tuesday, March 29
Due: Friday, April 15, no later than 11 pm
Points: 100, 10% of the final grade
Provided Program Files: EleBricks.java, BricksPanel.java, ImagesLoader.java, ImagesPlayer.java, ImagesPlayerWatcher.java, Sprite.java, various images and imsInfo.txt for your use. (All of these files are in this jar file.)

This is an pair assignment. You may complete the assignment with one other person from the class or you may complete it by yourself. I strongly urge you to work with a partner. You may use the examples shown in class as a guide, but you may not get help from anyone besides you partner, the instructor, and the TA. Copying code or getting code from anyone besides the the instructor or TA will result in an F in the course. You can discuss approaches to the problem with others as long as you don't write code or look at code. You may get help on syntax errors from others. You may refer to descriptions of algorithms (not source code) from sources on the web or from books.

If you are working with a partner turn in one version of the assignment to either partner's turnin account. If you work with a partner, both student's in a pair will get the same grade on the assignment.

The purpose of the assignment is to create a game that makes use of the Sprite class and the ImagesLoader class from the textbook.

The default game to create is the classic Breakout, renamed EleBricks for this assignment.

If you wish to implement a different game you must get permission from the instructor. Email me with a description of the game. If it is similar to a pre-existing game and a web page exists (Wikipedia is fine) describing the game please include a link for me to follow. If doing your own game, there must be a minimum of 3 different sprites that interact with each other and the enclosing panel with a complexity as least as difficult as that of EleBricks. That is the minimum for a grade of 80 on the assignment on a non EleBricks program.. To get a score greater than 80 the game must include more kinds of sprites with more complicated kinds of actions. Please realize doing something other than EleBricks will be more work and I may not be able to answer questions about your specific game.

If you want to complete a game other than EleBricks you must email me the description of your game by 5 pm on Friday, April 1 and get a return email from me. I will send these no later than Monday, April 4.

The rest of these instructions cover how to implement EleBricks,

Getting started:

  1. Download the jar file above and save it to a convenient spot on your system.

  2. Create a new project in Eclipse. Import the archive file to the default package. Do not create a named package for your code. (There shall be no package line in your source code files.)

  3. In Eclipse go to File -> Import

  4. In the window that pops up expand the General option and select Archive File


  5. In the Import window that pops up press the Browse... button


  6. In the file choosing window that pops up, browse to the location of the jar file you downloaded in step 1, select it, and click the open button.

  7. The .java source code files and the images folder with the images and imsInfo.txt file that contains information for the ImagesLoader class with the names of the images available should be added to your project.

  8. You should now be able to run the program, although nothing happens. The panel is blank.

Minimum Requirements for a Score of 80 on the EleBricks program:

To get 100 you must complete at least 4 of the following requirements to the game: (5 points each. You may complete one additional requirement for 5 points extra credit.)

In the header at the top of your EleBricks.java file list the extra requirements you have completed

The basic version of the game will look like this: (A few of the bricks have been knocked out)

Suggested Steps for Completing The Minimum Requirements Program

Note, these are general guidelines, not detailed instructions. You will find it useful to refer to the documentation for the Sprite class as well as the examples from chapter 11, the BallSprite class,  the BatSprite class, and possible BugPanel.

Don't try to code this all at once and then test. Code one bullet as described below and then test before going on to the next.

  1. Complete the requirements for the paddle:
    - create a Paddle class that is a descendant of Sprite
    - update the BricksPanel class to create, update, and draw a Paddle sprite
    - when the mouse is moved, have the handleMouseMove method update the desired position for the paddle
    - override the updateSprite method so that the paddle cannot move past the edges of the panel

  2. Complete the requirements for the bricks:
    create a Brick class that is a descendant of Sprite
    - update the BricksPanel class to create, update, and draw a couple of bricks sprite. (Just to test the class and the image.) In the basic version of the program Bricks do not move
    - create a Wall class. (This is not a descendant of Sprite. It is used to manage all of the Bricks.)
    - the Wall class maintains a 2D array (6 rows, 10 columns per row) of Brick objects.  When constructed, fill the 2D array with Brick objects at the various coordinates. so that a wall is completed
    - add a method to draw all of the Bricks
    - because bricks don't move there is no need to override the update method in the Ball class

  3. Complete the requirements for the ball: (The ball is the most difficult part because it interacts with all of the other sprites.)
    create a Ball class that is a descendant of Sprite. The Ball needs to have instance variables for the Wall of Bricks and the Paddle
    - when a Ball is constructed place it just below the bricks and set its dx and dy values so that it moves down. I found it best to have an instance variable for the balls speed. Pick a random angle between 20 and 70 degrees. Convert the degrees to radians with the Math.toRadians( ) method. The dy will be the balls speed times the cosine of the angle and the dx will be the sine of the angle. (More methods in the Math class to get these.)
    - override the updateSprite method for the ball. The updateSprite method for the ball is fairly complex. It must check several:
        - if the ball has hit the left, right, or upper walls of the panel it must bounce correctly. (dx = -dx for left and right walls, dy = -dy for top wall)
        - if the ball has hit the paddle and is moving down it must reverse direction to move up (dy = -dy)
        - the Ball needs to check with the Wall to see if it hit any bricks. (This is a new method for the Wall class. If a brick was hit its setActive( ) method must be called with a parameter of false.) It is easiest to use the balls rectangle from the getRectangle method and each Bricks rectangle. There is a method in the Rectangle class name intersects(Rectangle r). This is an easy way to see if the ball has collided with a Brick.
        - first just get the ball to make bricks disappear when it hits them. Don't worry about bouncing off the bricks at first.
        - when you have the bricks disappearing when the ball hits them go back and make the ball bounce off the brick it hit. Getting this right is tricky because the ball could bounce off the side of the brick which alters it dx or it could bounce of the top or bottom of the brick which alters its dy.

When you complete the assignment fill in the header information at the top of the EleBricks.java class. (Eclipse sometimes collapses this comment, so be sure to expand it.) If you are doing a game other than EleBricks be sure to include a header at the top of you class that has the main method and ensure that class has Main  in its name.

Because there are so many files you will turn in a jar file with your source code and the images folder with imsInfo.txt and all of the image files your program uses. This is not an executable jar, simple an archive, like a zip file. Refer to this page and follow the instructions carefully to create your jar using Eclipse. The jar shall be named A6.jar. (If you are unable to create a jar, but you can create a zip, you can turn in a zip file with your code and the folder with all of the images data..) Turn in the jar using the turnin program. This page contains instructions for using turnin. Be sure you upload the file to your CS324e folder.