Click me to show description!

Asteroids by Chris

This is a computer game where the player controls a spaceship, shoots objects, and earns points based on object size, speed, and distance from the spaceship.

Code Structure

The JavaScript code is organized into several functions and objects to handle different aspects of the game:

The main game loop is controlled by the update function, which calls various update and drawing functions for the spaceship, objects, shots, and point animations.

Controls

The following keys control the spaceship and game interactions:

Scoring

Points are calculated for each object hit based on its size, speed, and distance from the spaceship. The formula for calculating the points is as follows:

points = base_points * (1 + size_factor + speed_factor + distance_factor)

Software Architecture

The game is built using JavaScript and the HTML5 Canvas API. It follows a modular approach, with each game element (spaceship, object, shot, and point animation) encapsulated in its own object with its own properties and methods. The main game loop (update function) orchestrates the interactions between these elements and handles the game's state. The game also leverages event listeners to handle user input (keyboard events) and detect collisions between game elements. The use of event listeners allows for a responsive and interactive gameplay experience.

Getting Started

Use the arrow keys to control the spaceship and the spacebar to fire shots at the objects. Earn points by hitting objects and see how high of a score you can achieve!