Package: com.multiversesocial.hyperview
Class: com.multiversesocial.hyperview.Asteroids
Source: src/com/multiversesocial/hyperview/Asteroids.java
********************************************************************************************* Original version by Mike Hall; Hacked and ported to HyperView by Tony Swain. Asteroids.java Todo: reduce spinning of new Objects & implement Gobs instead of lines. (After finishing PointInPoly based collision detection) Keyboard Controls: S - Start Game P - Pause Game Cursor Left - Rotate Left Cursor Up - Fire Thrusters Cursor Right - Rotate Right Cursor Down - Fire Retro Thrusters Spacebar - Fire Ca...
crash.auexplosion.aumissle.auphoton.ausaucer.authrusters.auwarp.aupublic class Asteroids extends ViewPane implements Runnable
| Declaration | Value / initializer | Description | Source |
|---|---|---|---|
boolean[] asteroidIsSmall | = new boolean[MAX_ROCKS] | No comment in source; assigned in initAsteroids(), initSmallAsteroids(); used in updateAsteroids(). | |
AsteroidsSprite[] asteroids | = new AsteroidsSprite[MAX_ROCKS] | No comment in source; assigned in Asteroids(); used in initAsteroids(), initSmallAsteroids(), updateAsteroids(), update(). | |
int asteroidsCounter | No comment in source; assigned in run(), initAsteroids(). | ||
int asteroidsLeft | No comment in source; assigned in initAsteroids(), initSmallAsteroids(), updateAsteroids(); used in run(). | ||
int asteroidsSpeed | No comment in source; assigned in initGame(), initAsteroids(); used in initSmallAsteroids(). | ||
static final int BIG_POINTS | = 25 | No comment in source; used in updateAsteroids(). | |
SoundClip crashSound | No comment in source; assigned in loadSounds(); used in updateUfo(), updateMissle(), updateAsteroids(), inKey(). | ||
static final int DELAY | = 21 | No comment in source; used in run(); name appears in 1 other source file(s): RunInfoConstants. | |
boolean detail | No comment in source; assigned in Asteroids(), inKey(); used in explode(), update(). | ||
Dimension dim | = null | No comment in source; assigned in Asteroids(); used in update(). | |
boolean down | = false | No comment in source; assigned in inKey(); used in updateShip(). | |
int[] explosionCounter | = new int[MAX_SCRAP] | No comment in source; assigned in initExplosions(), explode(), updateExplosions(); used in update(). | |
int explosionIndex | No comment in source; assigned in initExplosions(), explode(). | ||
AsteroidsSprite[] explosions | = new AsteroidsSprite[MAX_SCRAP] | No comment in source; assigned in Asteroids(); used in initExplosions(), explode(), updateExplosions(), update(). | |
SoundClip explosionSound | No comment in source; assigned in loadSounds(); used in updateAsteroids(), inKey(). | ||
SoundClip[] fireSound | = new SoundClip[MAX_SHOTS] | No comment in source; assigned in loadSounds(); used in inKey(). | |
FontMetrics fm | No comment in source; assigned in Asteroids(); used in update(). | ||
Font font | = new Font("Helvetica", Font.BOLD, 12) | No comment in source; used in Asteroids(), update(). | |
int fontHeight | No comment in source; assigned in Asteroids(); used in update(). | ||
int fontWidth | No comment in source; assigned in Asteroids(); used in update(). | ||
int highScore | No comment in source; assigned in Asteroids(), run(); used in update(). | ||
static final int HYPER_COUNT | = 60 | No comment in source; used in updateShip(), inKey(), update(). | |
int hyperCounter | No comment in source; assigned in initShip(), updateShip(), inKey(); used in updateUfo(), updateMissle(), guideMissle(), updateAsteroids(), update(). | ||
Object keyWaitObject | No comment in source; assigned in Asteroids(). | ||
boolean left | = false | No comment in source; assigned in inKey(); used in updateShip(). | |
boolean loaded | = false | No comment in source; assigned in run(); used in start(), initShip(), stopShip(), stopUfo(), stopMissle() …. | |
Thread loadThread | No comment in source; assigned in start(), halt(); used in run(). | ||
Thread loopThread | No comment in source; assigned in start(), halt(); used in run(). | ||
static final int MAX_ROCK_SIDES | = 12 | No comment in source; used in initAsteroids(), initSmallAsteroids(). | |
static final int MAX_ROCK_SIZE | = 40 | No comment in source; used in updateUfo(), initAsteroids(), initSmallAsteroids(). | |
static final int MAX_ROCK_SPEED | = 12 | No comment in source; used in initUfo(), initAsteroids(). | |
static final int MAX_ROCKS | = 8 | No comment in source; used in Asteroids(), initAsteroids(), initSmallAsteroids(), updateAsteroids(), update(). | |
static final int MAX_SCRAP | = 20 | No comment in source; used in Asteroids(), initExplosions(), explode(), updateExplosions(), update(). | |
static final int MAX_SHIPS | = 5 | No comment in source; used in initGame(). | |
static final int MAX_SHOTS | = 5 | No comment in source; used in Asteroids(), loadSounds(), initPhotons(), updatePhotons(), updateUfo() …. | |
static final int MIN_ROCK_SIDES | = 8 | No comment in source; used in initAsteroids(), initSmallAsteroids(). | |
static final int MIN_ROCK_SIZE | = 20 | No comment in source; used in updateShip(), initMissle(), guideMissle(), initAsteroids(), initSmallAsteroids() …. | |
static final int MIN_ROCK_SPEED | = 2 | No comment in source; used in initGame(), initUfo(). | |
AsteroidsSprite missle | No comment in source; assigned in Asteroids(); used in updateUfo(), initMissle(), updateMissle(), guideMissle(), stopMissle() …. | ||
static final int MISSLE_POINTS | = 500 | No comment in source; used in updateMissle(). | |
int missleCounter | No comment in source; assigned in initMissle(), updateMissle(), stopMissle(); used in update(). | ||
boolean misslePlaying | No comment in source; assigned in initMissle(), stopMissle(); used in inKey(). | ||
SoundClip missleSound | No comment in source; assigned in loadSounds(); used in initMissle(), stopMissle(), inKey(). | ||
static final int NEW_SHIP_POINTS | = 5000 | No comment in source; used in initGame(), run(). | |
static final int NEW_UFO_POINTS | = 2750 | No comment in source; used in initGame(), run(). | |
int newShipScore | No comment in source; assigned in initGame(), run(). | ||
int newUfoScore | No comment in source; assigned in initGame(), run(). | ||
int numStars | No comment in source; assigned in Asteroids(); used in update(). | ||
Dimension offDimension | No comment in source; assigned in update(). | ||
Graphics offGraphics | No comment in source; assigned in update(). | ||
Image offImage | No comment in source; assigned in update(). | ||
boolean paused | No comment in source; assigned in initGame(), inKey(); used in run(). | ||
int[] photonCounter | = new int[MAX_SHOTS] | No comment in source; assigned in initPhotons(), updatePhotons(), inKey(). | |
int photonIndex | No comment in source; assigned in initPhotons(), inKey(). | ||
AsteroidsSprite[] photons | = new AsteroidsSprite[MAX_SHOTS] | No comment in source; assigned in Asteroids(); used in initPhotons(), updatePhotons(), updateUfo(), updateMissle(), updateAsteroids() …. | |
boolean playing | No comment in source; assigned in initGame(), endGame(); used in run(), updateShip(), inKey(), update(). | ||
boolean right | = false | No comment in source; assigned in inKey(); used in updateShip(). | |
boolean saucerPlaying | No comment in source; assigned in initUfo(), stopUfo(); used in inKey(). | ||
SoundClip saucerSound | No comment in source; assigned in loadSounds(); used in initUfo(), stopUfo(), inKey(). | ||
int score | No comment in source; assigned in initGame(), updateUfo(), updateMissle(), updateAsteroids(); used in run(), update(). | ||
static final int SCRAP_COUNT | = 30 | No comment in source; used in stopShip(), explode(), update(). | |
AsteroidsSprite ship | No comment in source; assigned in Asteroids(); used in initShip(), updateShip(), stopShip(), updateUfo(), updateMissle() …. | ||
int shipCounter | No comment in source; assigned in updateShip(), stopShip(). | ||
int shipsLeft | No comment in source; assigned in initGame(), run(), stopShip(); used in updateShip(), update(). | ||
static final int SMALL_POINTS | = 50 | No comment in source; used in updateAsteroids(). | |
boolean sound | No comment in source; assigned in Asteroids(), inKey(); used in initUfo(), updateUfo(), initMissle(), updateMissle(), updateAsteroids() …. | ||
Point[] stars | No comment in source; assigned in Asteroids(); used in update(). | ||
static final int STORM_PAUSE | = 30 | No comment in source; used in initAsteroids(). | |
boolean thrustersPlaying | No comment in source; assigned in initShip(), stopShip(), inKey(). | ||
SoundClip thrustersSound | No comment in source; assigned in loadSounds(); used in initShip(), stopShip(), inKey(). | ||
AsteroidsSprite ufo | No comment in source; assigned in Asteroids(); used in run(), initUfo(), updateUfo(), stopUfo(), initMissle() …. | ||
static final int UFO_PASSES | = 3 | No comment in source; used in run(). | |
static final int UFO_POINTS | = 250 | No comment in source; used in updateUfo(). | |
int ufoCounter | No comment in source; assigned in initUfo(), updateUfo(), stopUfo(). | ||
int ufoPassesLeft | No comment in source; assigned in run(), updateUfo(), stopUfo(). | ||
boolean up | = false | No comment in source; assigned in inKey(); used in updateShip(). | |
boolean updated | = false | No comment in source; assigned in update(). | |
SoundClip warpSound | No comment in source; assigned in loadSounds(); used in inKey(). |
| Signature | Description | Source |
|---|---|---|
Asteroids(HyperView tView, int tx, int ty, int tWidth, int tHeight) | 53 statement(s); calls super(), wait(), notifyAll(), getSize(), Math.random() …; creates Object, Point, AsteroidsSprite. |
| Signature | Description | Source |
|---|---|---|
public void endGame() | 4 statement(s); calls stopShip(), stopUfo(), stopMissle(). | |
public void explode(AsteroidsSprite s) | 7 statement(s); calls s.render(), explosions[explosionIndex].shape.addPoint(), Math.random(); creates Polygon. | |
public String getOrangeInfo() | Returns ("Asteroids, Copyright 1998 by Mike Hall. Orange port by Tony Swain"). | |
public void guideMissle() | 10 statement(s); calls Math.atan(), Math.abs(), Math.sin(), Math.cos(). | |
public void halt() | 2 statement(s). | |
public void initAsteroids() | 11 statement(s); calls Math.random(), Math.round(), Math.sin(), Math.cos(), asteroids[i].shape.addPoint() …; creates Polygon. | |
public void initExplosions() | 3 statement(s); creates Polygon. | |
public void initGame() | 13 statement(s); calls initShip(), initPhotons(), stopUfo(), stopMissle(), initAsteroids() …. | |
public void initMissle() | 11 statement(s); calls missle.render(), Math.max(), missleSound.play(). | |
public void initPhotons() | 3 statement(s). | |
public void initShip() | 11 statement(s); calls ship.render(), thrustersSound.halt(). | |
public void initSmallAsteroids(int n) | 15 statement(s); calls Math.random(), Math.round(), Math.sin(), Math.cos(), asteroids[i].shape.addPoint() …; creates Polygon. | |
public void initUfo() | 12 statement(s); calls Math.random(), ufo.render(), saucerSound.play(), Math.floor(), Math.abs(). | |
public void inKey() | 5 statement(s); calls tmpKey.getKeyChar(), tmpKey.getKeyCode(), thrustersSound.halt(), initUfo(), thrustersSound.play() …. | |
public void loadSounds() | 21 statement(s); calls fireSound[i].play(), fireSound[i].halt(), crashSound.play(), crashSound.halt(), explosionSound.play() …; creates SoundClip. | |
public void run() | 10 statement(s); calls Thread.currentThread(), controlThread.setPriority(), loadSounds(), graphics.setClip(), updateShip() …. | |
public void start() | 3 statement(s); calls loopThread.start(), loadThread.start(); creates Thread. | |
public void stopMissle() | 4 statement(s); calls missleSound.halt(). | |
public void stopShip() | 5 statement(s); calls thrustersSound.halt(). | |
public void stopUfo() | 5 statement(s); calls saucerSound.halt(). | |
public void update() | 28 statement(s); calls curView.createImage(), offImage.getGraphics(), offGraphics.setColor(), offGraphics.fillRect(), offGraphics.drawLine() …; creates Color. | |
public void updateAsteroids() | 3 statement(s); calls asteroids[i].advance(), asteroids[i].render(), asteroids[i].isColliding(), explosionSound.play(), explode() …. | |
public void updateExplosions() | 2 statement(s); calls explosions[i].advance(), explosions[i].render(). | |
public void updateMissle() | 2 statement(s); calls stopMissle(), guideMissle(), missle.advance(), missle.render(), missle.isColliding() …. | |
public void updatePhotons() | 2 statement(s); calls photons[i].advance(), photons[i].render(). | |
public void updateShip() | 12 statement(s); calls Math.sin(), Math.cos(), ship.advance(), ship.render(), initShip() …. | |
public void updateUfo() | 3 statement(s); calls ufo.advance(), ufo.render(), initUfo(), stopUfo(), ufo.isColliding() …. |
class AsteroidsSprite
| Declaration | Value / initializer | Description | Source |
|---|---|---|---|
boolean active | Active flag. | ||
double angle | Current angle of rotation. | ||
Color color | = null | No comment in source; not referenced by name in this type’s methods. | |
double currentX | Current position on screen. | ||
double currentY | Current position on screen. | ||
double deltaAngle | Amount to change the rotation angle. | ||
double deltaX | Amount to change the screen position. | ||
double deltaY | Amount to change the screen position. | ||
static int height | No comment in source; used in advance(), render(). | ||
Polygon shape | Initial sprite shape, centered at the origin (0,0). | ||
Polygon sprite | Final location and shape of sprite after applying rotation and moving to screen position. Used for drawing on the screen and in detecting collisions. | ||
static int width | Dimensions of the graphics area. |
| Signature | Description | Source |
|---|---|---|
public AsteroidsSprite() | 10 statement(s); calls super(); creates Polygon. |
| Signature | Description | Source |
|---|---|---|
public void advance() | 9 statement(s). | |
public boolean isColliding(AsteroidsSprite s) | 3 statement(s); calls this.sprite.contains(). | |
public void render() | 3 statement(s); calls this.sprite.addPoint(), Math.round(), Math.cos(), Math.sin(); creates Polygon. |
Fields: f1, frameColor1, frameColor2, frameColor3, keyboard, menuPaneColor, mpHeight, mpWidth, mpX, mpX2, mpY, mpY2, selectString, textColor, titleString, viewPaneNumber
Methods: cleanUp(), drawString(String, int, int), drawString(String, int, int, int), drawStrings(StringArr, int, int), erase(), eraseMenuPane(), getSize(), makeBitMap(), reSize(int, int), setFont(int), setTitle(String)
Fields: backColor, conFont, cursorGraphics, cursorHeight, cursorImage, cursorName, cursorScrollXOffset, cursorScrollYOffset, cursorWidth, cursorX, cursorY, displayInfo, fGColor, flipCount, gadFlags, gadFlags2, gadNumber, lastCursorX, lastCursorY, lineColorA, lineColorB, lineColorC, locked, method, parentTitlebar, stringHeight, stringWidth, stringX, stringY, tc1, tc2, tc3, tc4
Methods: addDispatch(Dispatch), allKeyMsgENA(), drawCursor(), drawOutline(), drawOutline2(), getForeground(), inString(String), isEnabled(), isShowing(), isVisible(), keyReleaseENA(), keyTypedENA(), layerDisable(), layerENA(), makeBitmap(Font), mouseWheelMoved(MouseWheelEvent), onMouseOver(), setEnabled(boolean), setForeground(int), setName(String), setVisible(boolean), toFront(), toString(), updateText()
Fields: asynchGraphics1, asynchGraphics2, asynchImage1, asynchImage2, attachedGob, attachedIndex, backGround, bgMemoryImageSource, bGPen, bottomMax, clickX, clickY, collisionClassMask, curAttached, currentZIndex, curView, depth, destGob, destGraphics, dispatchHoldCount, drawMode, dX, dY, dZ, fgMemoryImageSource, fGPen, gobEventFlags, gobFlags, gobFlags2, gobGadIndex, gobHx, gobHy, gobHz, gobName, gobNumber, gobOrbitRadius, gobPic, gobTypeFlags, graphics, gravity, height, heightBase, hSin, hyp, infoString, lClickX, lClickY, leftMin, maxAttached, memoryCounter, moveNum, mX, mX2, mY, mY2, oldX, oldY, oldZ, orbitGob, rightMax, scanLine, selectGraphics, selectImage, selectTime, spline, tint, topMin, totalAttached, width, widthBase, wSin, x, x2, y, y2, z
Methods: addGob(Gob), addSpline(Spline), center(), collisionOff(), collisionOn(), disable(), enable(), getGraphics(), getImageFromJar(String), getPixels(), gobZInit(), initScanline(int), inView(), isInView(), isMemoryImageSource(), move(int, int), move(Gadget, int, int), moveNext(), onClick(), onDisplay(), onRelease(), printGobAttr(HyperView), printScanLines(), remGob(), remove(), zENA(), zOff()
Fields: attachment, index, linkFlags, name, next, parentList, prev
Methods: inList()
instantiation — AsteroidsDispatch.java, line 34
34 asteroids = new 35 Asteroids(curView,1,16,640,460); //(HyperView,X,Y,width/height)
The reference port: Mike Hall’s applet as a ViewPane, hosted by ViewMain through AsteroidsDispatch. See the Applet Migration Guide.