Assignment 2

In this assignment your task is to implement a simple shooting game: a “gun” shoots a “projectile” that can hit a moving “target”. When the target is hit it “explodes”! All the details are explained in the marking scheme below.

Even though the game is simple (and not much to look at), it does require some effort to get it all working. You will need to solve many little problems along the way.

Screenshot 1:

The shooting game in action.

Screenshot 2:

The shooting game in action.

Marking Scheme

This assignment is marked out of 12. There are no bonus marks.

  • 1 mark for a “gun”, that moves up and down (or left and right) reversing direction when it hits an edge.

    In the sample screenshots, the gun is the grey rectangle (bouncing up and down) on the left side of the screen. However, the exact size, location, and speed of the gun are up to you.

  • 1 mark for a “target”, that moves up and down (or left and right) reversing direction when it hits an edge.

    In the sample screenshots, the target is the green circle (bouncing up and down) on the right side of the screen. However, the exact size, location, and speed of the target are up to you.

  • 2 marks for making a “projectile” appear to come out of the shooter when the mouse is clicked (anywhere) and fly across the screen. The projectile should disappear either when it hits the target or the edge of the screen.

    In the sample screenshots, the projectile is the eyeball. The exact size and speed of the projectile are up to you. Whether or not the projectile hits the target depends upon when the user clicks the mouse.

  • 1 mark for having “gravity” pull on the projectile so that the projectile’s path follows an arc instead of a completely straight line.

  • 1 mark for making the target “explode” in the following way when the edge of the projectile (its left edge in the screenshot) hits the target: the target stops moving and explodes by getting bigger (i.e. inflating) and, at the same time, fading away to invisibility. When the target is completely invisible it should re-appear on the screen with its original size, transparency, and movement (so that the player can shoot at it again).

  • 1 mark for making the “gun” something more graphically interesting than a box. What you decide to draw it as is up to you and should fit with the theme of your game. For instance, you could draw the shooter as a bow (shooting an arrow), or a submarine (shooting a missile), or as a little kid (throwing a snowball), etc.

    You can use either images or shape-drawing commands for this part.

  • 1 mark for making the “target” something more graphically interesting than a box. What you decide to draw it as is up to you and should fit with the theme of your game. For instance, you could draw the target as a bulls eye, or an airplane, or as a little kid (about to be hit by a snowball), etc.

    You can use either images or shape-drawing commands for this part.

  • 1 mark for making the “projectile” something more graphically interesting, and sensible, than an eyeball. What you decide to draw it as is up to you and should fit with the theme of your game. For instance, you could draw the projectile as an arrow, or a missile, or as a snowball, etc.

    You can use either images or shape-drawing commands for this part.

  • 3 marks are for the quality of your source code. Specifically:

    • 1 mark for consistent and sensible indentation of your code.
    • 1 mark for sensible and self-descriptive variable names throughout your code. There may be a lot of variables in this program, so good naming is important!
    • 1 mark for using functions in a sensible and appropriate way in your program.

What to Submit

Please name the program you write for this assignment asn2. Submit the folder called asn2 that contains the program (which should be automatically called asn2.pde) and any image and font files it needs. Compress this folder as an archive named asn2.zip (please only use .zip, and not some other archive format).

Submitting this Assignment

Please submit this assignment on-line no later than the due date listed on the course marking scheme. Late assignments may not be marked.

Hints

  • The first thing you should do is get the gun working. Initially just make it a colored box (as in the sample screenshots).

    The gun will have a number of variables associated with it, and so we suggest you use the following naming convention: gun_x stores its x-position, gun_y stores its y-position, gun_dy stores its vertical velocity, etc.

  • After the gun is working, get the target working. Again, start with a colored rectangle or circle, and, if you choose, make it look nicer after the basic program is working.

    As with the gun, you will need to use a number of variables specific to the target, and you are encouraged to make these variable names begin with target_.

  • After the target is working, get the projectile working. Initially, make it appear on top of (or underneath) the gun when the user clicks a mouse button anywhere on the screen and fly across the screen. Then make it disappear when it hits the target or the edge of the screen.

  • After the gun, target and projectile are working essentially correctly, add the explosion special effect for when the projectile hits the target. Make sure that after the target is completely invisible it is reset so that the player can shoot at it again.

Table Of Contents

Previous topic

Assignment 1

Next topic

Assignment 3