Class AsteroidsGame

java.lang.Object
  |
  +--AsteroidsGame

class AsteroidsGame
extends java.lang.Object

This container class holds a spritevector with all the sprites, and keeps the SpriteBullet and SpriteExplosion in separate arrays so we can conveniently replace the oldest one when we want to make a new one.


Field Summary
(package private)  SpriteAsteroid[] asteroids
          The asteroids.
(package private)  int bulletIndex
           
(package private)  SpriteBullet[] bullets
          Use a phtons array so that we can always replace the oldest bullet by the newest bullet.
(package private)  boolean collideflag
          Flag for whether or not to calculate collisions between asteroids.
(package private)  boolean diskflag
          Flag for whether to use a rectangle or a disk for your world.
(package private)  int explosionIndex
           
(package private)  SpriteExplosion[] explosions
          So that we can always replace the oldest explosion line by the newest one, we need an array for the explosions.
(package private)  boolean gameonflag
          Flag to indicate if game is started and not yet over.
(package private) static int highScore
          High score for this play session.
(package private) static int MAX_ASTEROIDS
          Number of asteroids that you can get by splitting up.
(package private) static int MAX_BULLETS
          Number of active bullets allowed.
(package private) static int MAX_EXPLOSIONS
          Total number of lines used to represent exploding objects.
(package private) static int MAX_SHIPS
          Starting number of ships per game.
(package private)  SpriteMissile missile
          The missile.
(package private) static int NEW_SHIP_POINTS
          Number of additional points needed to earn a new ship.
(package private) static int NEW_UFO_POINTS
          Number of additional points before a fresh Ufo attacks.
(package private)  boolean paused
          Flag for paused game.
(package private) static int score
          Game score.
(package private)  SpriteShip ship
          It's useful to have a distinguished name for the ship.
(package private)  java.util.Vector spritevector
          The spritevector holds all of the sprites; we walk this array for our updates.
(package private) static double STARDENSITY
          Number of stars per square world unit.
(package private)  Vector2Colored[] stars
          Array for background stars
(package private) static int START_ASTEROIDS
          Number of asteroids in each wave.
(package private)  SpriteUfo ufo
          The flying saucer.
(package private)  SpriteWall wall
          Have a SpriteWall to show when the bounce is on for the ship.
 
Constructor Summary
AsteroidsGame(RealPixelConverter rtopc)
          Construct all your sprites and add them to spritevector.
 
Method Summary
(package private)  void draw(java.awt.Graphics g, RealPixelConverter rtopc, boolean detail)
          Fill in background stars, draw the sprites.
 void gameUpdate(double dt, RealPixelConverter rtopc)
          First call advance for all sprites, then render for all sprites, and then update for all sprites.
 boolean getBounce()
           
 void makenewstars()
           
(package private)  SpriteAsteroid nextAsteroid()
          This returns the slot of the next non-live asteroid, or null if there's no slot.
(package private)  SpriteBullet nextBullet()
           
(package private)  SpriteExplosion nextExplosion()
           
 void resetAsteroids(RealPixelConverter rtopc)
          Create START_ASTEROIDS asteroids, make them faster than before, put them out at the edge of the screen, and set SprieAsteroidpauseCounter.
 void resetBullets(RealPixelConverter rtopc)
           
 void resetExplosions(RealPixelConverter rtopc)
           
 void resetGame(RealPixelConverter rtopc)
          Initialize the game data.
(package private)  void setOwnerApp(Asteroids owner)
           
 void stop()
          Stop ship, flying saucer, guided missile and associated sounds.
 void toggleBounce()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

MAX_SHIPS

static final int MAX_SHIPS
Starting number of ships per game. 3.

MAX_BULLETS

static final int MAX_BULLETS
Number of active bullets allowed. 8.

START_ASTEROIDS

static final int START_ASTEROIDS
Number of asteroids in each wave. 8.

MAX_ASTEROIDS

static final int MAX_ASTEROIDS
Number of asteroids that you can get by splitting up.

MAX_EXPLOSIONS

static final int MAX_EXPLOSIONS
Total number of lines used to represent exploding objects. 30.

NEW_SHIP_POINTS

static final int NEW_SHIP_POINTS
Number of additional points needed to earn a new ship.

NEW_UFO_POINTS

static final int NEW_UFO_POINTS
Number of additional points before a fresh Ufo attacks.

STARDENSITY

static double STARDENSITY
Number of stars per square world unit. We'll have about 250,000 area at present, so keep it low.

stars

Vector2Colored[] stars
Array for background stars

score

static int score
Game score.

highScore

static int highScore
High score for this play session.

gameonflag

boolean gameonflag
Flag to indicate if game is started and not yet over.

paused

boolean paused
Flag for paused game.

collideflag

boolean collideflag
Flag for whether or not to calculate collisions between asteroids.

diskflag

boolean diskflag
Flag for whether to use a rectangle or a disk for your world.

wall

SpriteWall wall
Have a SpriteWall to show when the bounce is on for the ship. We don't add this to the spritevector as it won't be colliding like the others, etc. We will use it in the AsteroidsGame draw method.

spritevector

java.util.Vector spritevector
The spritevector holds all of the sprites; we walk this array for our updates.

ship

SpriteShip ship
It's useful to have a distinguished name for the ship.

bullets

SpriteBullet[] bullets
Use a phtons array so that we can always replace the oldest bullet by the newest bullet.

bulletIndex

int bulletIndex

ufo

SpriteUfo ufo
The flying saucer.

missile

SpriteMissile missile
The missile.

asteroids

SpriteAsteroid[] asteroids
The asteroids.

explosions

SpriteExplosion[] explosions
So that we can always replace the oldest explosion line by the newest one, we need an array for the explosions.

explosionIndex

int explosionIndex
Constructor Detail

AsteroidsGame

public AsteroidsGame(RealPixelConverter rtopc)
Construct all your sprites and add them to spritevector. The first things get drawn first and thus appear furthest in the background. So add the wall first and the ship last.
Method Detail

resetGame

public void resetGame(RealPixelConverter rtopc)
Initialize the game data.

makenewstars

public void makenewstars()

stop

public void stop()
Stop ship, flying saucer, guided missile and associated sounds.

nextExplosion

SpriteExplosion nextExplosion()

nextBullet

SpriteBullet nextBullet()

nextAsteroid

SpriteAsteroid nextAsteroid()
This returns the slot of the next non-live asteroid, or null if there's no slot.

resetBullets

public void resetBullets(RealPixelConverter rtopc)

resetAsteroids

public void resetAsteroids(RealPixelConverter rtopc)
Create START_ASTEROIDS asteroids, make them faster than before, put them out at the edge of the screen, and set SprieAsteroidpauseCounter.

resetExplosions

public void resetExplosions(RealPixelConverter rtopc)

toggleBounce

public void toggleBounce()

getBounce

public boolean getBounce()

gameUpdate

public void gameUpdate(double dt,
                       RealPixelConverter rtopc)
First call advance for all sprites, then render for all sprites, and then update for all sprites. Look at the score and add a new ship life or start a ufo if score is high enough. If all the asteroids are destroyed create a new batch.

draw

void draw(java.awt.Graphics g,
          RealPixelConverter rtopc,
          boolean detail)
Fill in background stars, draw the sprites.

setOwnerApp

void setOwnerApp(Asteroids owner)