Kamis, 16 April 2020

Asteroids Starter Code Asteroids Java Game

Asteroids Starter Code

(You should do a save-as on this link. Name the file Morphic-Asteroids.st.)

What we provide

We provide you with a chunk of code which will help you get started. This code implements a basic arcade game, and will set you in the right direction (hopefully). As a game, it works, but if you play it, you'll see that many snazzy features of real game are missing: score keeping, levels, asteroids that split when shot, UFOs, etc. You are of course free to start from scratch. If you understand this code should be easy to modify it implement other arcade games of the same flavor: Time Pilot, Galaga, Space Invaders, etc. Please note that this is not a "plug and play" project: even if you undertake the Asteroids project, you will have to understand and modify almost all of the code we provide in some manner.

The world, roughly speaking, consists of three entities. The player's ship, a collection of bad things (called blobs: asteroids, UFOs, UFO bullets, etc.), and a collection of good things (essentially this is just the player's bullets). While the world could consist just of a single collection of all of the things it contains, it turns out to be more efficient and slightly easier to conceptualize if we organize it this way. All objecs are submorphs of a toplevel morph called WorldMorph. We let the morphic framework classes gather events and step (update) each of the objects in our world.

The code we provide is broken down into the following classes:

  • WorldMorph This class maintains the state for the game. It holds collections for the blobs and bullets, the ship, and any other state which is important for the management of the game. An instance of world deals with updating the objects it contains.
  • SpaceMorph This is the parent class of all objects in the game. It defines the basic behavior of all objects which float around in outer space. An instance of this class is an object which has a velocity, a shape, and other important state. These objects know how to draw themselves, and a bunch of other basic behaviors.
    • ShipMorph This class inherits from SpaceThing and defines the behavior of a space ship. Currently, a SpaceShip is only used to implement the player's ship, so it does basically everything a SpaceThing does, except that it also handles keyboard events, and has a different default shape. Certain keystrokes cause it to change its angle in in the world, fire bullets, etc.
    • BulletMorph This class inherits from SpaceMorph. It is basically identical except that it dies after a certain number of cycles. When it is dead, it will be removed from the simulation.

Getting Started (Do this Soon!)

  1. First, download, open, and try the given code. You ought to be able to evaluate "WorldMorph test" in a workspace and play the game.
  2. When you get bored, start looking at the provided code. It's all in a category called "Morphic-Asteroids". Understand how it all fits together. Draw pictures of how the various objects relate to each other.

Making Changes

Once you've understood the provided code, you're ready to start extending and changing it. Make the game more/less realistic -- ships shouldn't just pass through asteroids. Make the game more/less violent -- add different kinds of weapons or turn the game into a civilization-style game, where asteroids are mined or colonized. Add other kinds of (smart) entities, such as UFOs, Klingons, etc. Think about ship health -- using bullets, shields, etc. should cause the ship's health to drop. Add new levels after the current one is complete. Make the game more efficient -- right now, collision detection is "very N-squared" -- data structure gurus will see real possibilities for improving the game in this area.

0 Comments

Posting Komentar