EECS 493

EECS 493 Assignment 3: Asteroids Game

Total Released Due
100 points 9/12 9/29 at 11:59 PM ET

Submission Instructions

Please submit your work to Canvas as a zip file, named a3_<uniqname>.zip. Replace <uniqname> with your uniqname: e.g. a3_zhaojer.zip, note that the angle brackets should NOT be included in your filename. Renaming (e.g., “-1”) done by Canvas is fine.

This zip file should have a single directory containing all files and directories provided in the starter code. In other words, the zip file should have the following structure.

a3_uniqname
├── index.html
├── scripts
│   ├── jquery.min.js
│   └── page.js
├── src
│   ├── arrowkeys.png
│   ├── asteroid.png
│   ├── audio
│   │   ├── collect.mp3
│   │   ├── die.mp3
│   │   └── pew.mp3
│   ├── frontpage_background.jpg
│   ├── player
│   │   ├── player.gif
│   │   ├── player_down.gif
│   │   ├── player_left.gif
│   │   ├── player_right.gif
│   │   ├── player_shielded.gif
│   │   ├── player_shielded_down.gif
│   │   ├── player_shielded_left.gif
│   │   ├── player_shielded_right.gif
│   │   ├── player_shielded_up.gif
│   │   ├── player_touched.gif
│   │   └── player_up.gif
│   ├── port.gif
│   └── shield.gif
└── style
    └── index.css

Not following the upload instruction will result in a penalty.

Objective

The objective of this assignment is for you to gain practical experience in building an interactive single-page web application with HTML, CSS, and JavaScript/jQuery. Specifically, you will be creating a game called “Asteroids” as outlined in this spec. No external library, other than jQuery, is allowed.

Watch this video for an overview: https://youtu.be/waDMWIfT8yg

Grading Breakdown

This assignment has 8 main components (denominator of 100 points):

  1. Asteroids spawn randomly from different directions - 25 points
  2. Shields and portals spawn at certain time intervals - 15 points
  3. A rocket (controlled by the user) with the goal of traveling through portals - 15 points
  4. A scoreboard - 5 points
  5. Sounds - 5 points
  6. A “Get Ready” splash screen - 5 points
  7. A game over page - 15 points
  8. Overall functionality - 15 points

Starter Code

You will use the starter code we provide to complete this assignment.

Download and unpack the starter files (either using the following commands or simply navigating to the link).

$ wget https://eecs493staff.github.io/a3-asteroids/starter_code.tar.gz
$ tar -xvzf starter_code.tar.gz

Here’s a brief description of each of the starter files.

index.html Some containers (divs) for the game window and the game board are defined; write your HTML code here
style/index.css Some stylings for the game window, game board, and images are defined; write your CSS code here
scripts/page.js Here is a list of things provided:
  1. Some comments describing the structure of the code
  2. Some global variables for storing game states/data
  3. An Asteroids class is defined (Asteroids that are randomly generated and travels linearly across the gameboard)
  4. Event handler for arrow key presses
  5. Additional helper functions (e.g. determining collision);
write your JS code here
scripts/jquery.min.js jQuery library source code; do NOT modify
src/ Images and audios for your website; do NOT modify

Remarks:

Helpful Resources

Before starting with this assignment, we recommend that you check out the following 2 resources that will make your progress in this assignment much easier.

Group OH

This is a recording of a group office hour session from Fall 2022, which contains an overview of both Assignment 2 and Assignment 3, how to start, and some challenging aspects students had questions about.

The video is 2 hours long: Everything, except the portion from 29:30 to 1:07:30, is relevant for this assignment. Timestamp is provided in the video description.

Recording link: https://youtu.be/hXilQo1lMjE

Blaster Game Demo

This demo is on creating a simple game with JS from many semesters ago. It goes over some common JS functions for manipulating the DOM, which are important for this current assignment too. The demo is about 45 minutes.

Blaster Game Video: (Consider downloading for better quality! Captions have been added also.) https://drive.google.com/file/d/1ttQV8_Wzm37cXrbEYuBXPAixG_UzQNFZ/view?usp=sharing

Blaster Game Starter Code: https://drive.google.com/file/d/1r5YC7vx_9l5GBzTYRpGE-5ewFbGN12Lk/view?usp=sharing

Screenshots

“Get Ready” Splash Screen

Gameplay & Scoreboard

Game Over Page

The remaining pages are the same as Assignment 2.

Requirements

We outline the requirements for each of the components below. Everything listed in this section, unless labeled as “Suggested”, is required. The demo video & screenshots may be helpful in understanding the game; however, your game does NOT need to look exactly like them.

General

Asteroids spawn randomly from different directions (25 points)

Shields and portals appear at certain time intervals (15 points)

A rocket (controlled by the user) with the goal of traveling through portals (20 points)

Scoreboard (5 points)

Sounds (5 points)

“Get Ready” Splash Screen (5 points)

Main Components

Required

Suggested Style

Game Over Page (15 points)

Main Components

Required

Overall Functionality (10 points)

Hints

Changing Item Size

If you are trying to set the width and height for asteroid elements but it’s not working, double check what element you’re actually setting the width and height for. If you are setting the width and height on the “div” containing the image, this doesn’t actually affect the image size; it’s simply a container for the image. You likely will need to set the width and height for the image element itself.

Event Listeners

If you think your event listeners aren’t being triggered, one common error occurs when event listeners are created (and attached) before relevant DOM objects exist.

A way around this is to create event listeners that are attached to the body, or another element that exists immediately on the page, and then filter events for a given selector. For example, if I have a UI where I expect items to get added to the page dynamically, and I want to have a “delete” button next to each dynamically added element, I might create the event listener this way:

$("body").on("click", ".deleteX", function(event){
 
});

Here, the “body” is listening for all click events, and is essentially only passing them to the callback if the item clicked actually had the “deleteX” class. See the “selector” arg here: https://api.jquery.com/on/

FAQ

Is it OK if the asteroids spawn outside the game window?

Yes.

Is the assignment graded for style?

If “style” refers to coding style, then no. However, make sure you are following the rules listed under the General section in the spec. If “style” refers to CSS style, then yes, at least for some pages.

Can I use <some JS/CSS functions> to achieve <some behavior>?

Yes, as long as it does not involve any external libraries (other than jQuery).

What happens when a rocket carrying a shield comes into contact with another shield spawning on the game board?

Up to you! The simplest solution is to do nothing.

How can I make the rocket move “smoothly”?

I recommend using a setInterval() which constantly checks (e.g. every 20 ms) whether UP, DOWN, LEFT, RIGHT variables (set by the keypress event handlers) are true, and moves the player accordingly if so.

Is it OK if the shielded rocket images appear smaller/larger than the non-shielded images?

Yes.

Is it OK if there is a gap between the asteroid and the rocket when they collide?

Yes.

Does it matter where the rocket spawns?

No.

Acknowledgments

Original spec written by Zirui Zhao zhaojer@umich.edu. Updated by the EECS 493 team.

This document is licensed under a Creative Commons Attribution-NonCommercial 4.0 License. You’re free to copy and share this document, but not to sell it. You may not share source code provided with this document.