Package: com.multiversesocial.hyperview
Class: com.multiversesocial.hyperview.Asteroids
Source: src/com/multiversesocial/hyperview/Asteroids.java

Asteroids

HyperView V3.2 — class
version V3.2 class

Summary

********************************************************************************************* 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...

Source file: Asteroids.java

Hierarchy

Extends: ViewPane

Implements: Runnable

Referenced HyperView classes

Media files used

Declaration & members

public class Asteroids extends ViewPane implements Runnable

Declared in src/com/multiversesocial/hyperview/Asteroids.java, lines 107–1202. 78 field(s), 1 constructor(s), 27 method(s), plus 1 other top-level type(s) in the same file. Every member has an anchor you can link to (e.g. Asteroids.html#<id>).

Fields (78)

DeclarationValue / initializerDescriptionSource
boolean[] asteroidIsSmall= new boolean[MAX_ROCKS]No comment in source; assigned in initAsteroids(), initSmallAsteroids(); used in updateAsteroids().line 167
AsteroidsSprite[] asteroids= new AsteroidsSprite[MAX_ROCKS]No comment in source; assigned in Asteroids(); used in initAsteroids(), initSmallAsteroids(), updateAsteroids(), update().line 157
int asteroidsCounterNo comment in source; assigned in run(), initAsteroids().line 168
int asteroidsLeftNo comment in source; assigned in initAsteroids(), initSmallAsteroids(), updateAsteroids(); used in run().line 170
int asteroidsSpeedNo comment in source; assigned in initGame(), initAsteroids(); used in initSmallAsteroids().line 169
static final int BIG_POINTS= 25 (constant)No comment in source; used in updateAsteroids().line 130
SoundClip crashSoundNo comment in source; assigned in loadSounds(); used in updateUfo(), updateMissle(), updateAsteroids(), inKey().line 174
static final int DELAY= 21 (constant)No comment in source; used in run(); name appears in 1 other source file(s): RunInfoConstants.line 115
boolean detailNo comment in source; assigned in Asteroids(), inKey(); used in explode(), update().line 147
Dimension dim= nullNo comment in source; assigned in Asteroids(); used in update().line 113
boolean down= falseNo comment in source; assigned in inKey(); used in updateShip().line 151
int[] explosionCounter= new int[MAX_SCRAP]No comment in source; assigned in initExplosions(), explode(), updateExplosions(); used in update().line 171
int explosionIndexNo comment in source; assigned in initExplosions(), explode().line 172
AsteroidsSprite[] explosions= new AsteroidsSprite[MAX_SCRAP]No comment in source; assigned in Asteroids(); used in initExplosions(), explode(), updateExplosions(), update().line 158
SoundClip explosionSoundNo comment in source; assigned in loadSounds(); used in updateAsteroids(), inKey().line 175
SoundClip[] fireSound= new SoundClip[MAX_SHOTS]No comment in source; assigned in loadSounds(); used in inKey().line 176
FontMetrics fmNo comment in source; assigned in Asteroids(); used in update().line 189
Font font= new Font("Helvetica", Font.BOLD, 12)No comment in source; used in Asteroids(), update().line 188
int fontHeightNo comment in source; assigned in Asteroids(); used in update().line 191
int fontWidthNo comment in source; assigned in Asteroids(); used in update().line 190
int highScoreNo comment in source; assigned in Asteroids(), run(); used in update().line 140
static final int HYPER_COUNT= 60 (constant)No comment in source; used in updateShip(), inKey(), update().line 121
int hyperCounterNo comment in source; assigned in initShip(), updateShip(), inKey(); used in updateUfo(), updateMissle(), guideMissle(), updateAsteroids(), update().line 161
Object keyWaitObjectNo comment in source; assigned in Asteroids().line 109
boolean left= falseNo comment in source; assigned in inKey(); used in updateShip().line 148
boolean loaded= falseNo comment in source; assigned in run(); used in start(), initShip(), stopShip(), stopUfo(), stopMissle() ….line 143
Thread loadThreadNo comment in source; assigned in start(), halt(); used in run().line 111
Thread loopThreadNo comment in source; assigned in start(), halt(); used in run().line 112
static final int MAX_ROCK_SIDES= 12 (constant)No comment in source; used in initAsteroids(), initSmallAsteroids().line 125
static final int MAX_ROCK_SIZE= 40 (constant)No comment in source; used in updateUfo(), initAsteroids(), initSmallAsteroids().line 127
static final int MAX_ROCK_SPEED= 12 (constant)No comment in source; used in initUfo(), initAsteroids().line 129
static final int MAX_ROCKS= 8 (constant)No comment in source; used in Asteroids(), initAsteroids(), initSmallAsteroids(), updateAsteroids(), update().line 118
static final int MAX_SCRAP= 20 (constant)No comment in source; used in Asteroids(), initExplosions(), explode(), updateExplosions(), update().line 119
static final int MAX_SHIPS= 5 (constant)No comment in source; used in initGame().line 116
static final int MAX_SHOTS= 5 (constant)No comment in source; used in Asteroids(), loadSounds(), initPhotons(), updatePhotons(), updateUfo() ….line 117
static final int MIN_ROCK_SIDES= 8 (constant)No comment in source; used in initAsteroids(), initSmallAsteroids().line 124
static final int MIN_ROCK_SIZE= 20 (constant)No comment in source; used in updateShip(), initMissle(), guideMissle(), initAsteroids(), initSmallAsteroids() ….line 126
static final int MIN_ROCK_SPEED= 2 (constant)No comment in source; used in initGame(), initUfo().line 128
AsteroidsSprite missleNo comment in source; assigned in Asteroids(); used in updateUfo(), initMissle(), updateMissle(), guideMissle(), stopMissle() ….line 155
static final int MISSLE_POINTS= 500 (constant)No comment in source; used in updateMissle().line 133
int missleCounterNo comment in source; assigned in initMissle(), updateMissle(), stopMissle(); used in update().line 166
boolean misslePlayingNo comment in source; assigned in initMissle(), stopMissle(); used in inKey().line 183
SoundClip missleSoundNo comment in source; assigned in loadSounds(); used in initMissle(), stopMissle(), inKey().line 177
static final int NEW_SHIP_POINTS= 5000 (constant)No comment in source; used in initGame(), run().line 134
static final int NEW_UFO_POINTS= 2750 (constant)No comment in source; used in initGame(), run().line 135
int newShipScoreNo comment in source; assigned in initGame(), run().line 141
int newUfoScoreNo comment in source; assigned in initGame(), run().line 142
int numStarsNo comment in source; assigned in Asteroids(); used in update().line 137
Dimension offDimensionNo comment in source; assigned in update().line 185
Graphics offGraphicsNo comment in source; assigned in update().line 187
Image offImageNo comment in source; assigned in update().line 186
boolean pausedNo comment in source; assigned in initGame(), inKey(); used in run().line 144
int[] photonCounter= new int[MAX_SHOTS]No comment in source; assigned in initPhotons(), updatePhotons(), inKey().line 162
int photonIndexNo comment in source; assigned in initPhotons(), inKey().line 163
AsteroidsSprite[] photons= new AsteroidsSprite[MAX_SHOTS]No comment in source; assigned in Asteroids(); used in initPhotons(), updatePhotons(), updateUfo(), updateMissle(), updateAsteroids() ….line 156
boolean playingNo comment in source; assigned in initGame(), endGame(); used in run(), updateShip(), inKey(), update().line 145
boolean right= falseNo comment in source; assigned in inKey(); used in updateShip().line 149
boolean saucerPlayingNo comment in source; assigned in initUfo(), stopUfo(); used in inKey().line 182
SoundClip saucerSoundNo comment in source; assigned in loadSounds(); used in initUfo(), stopUfo(), inKey().line 178
int scoreNo comment in source; assigned in initGame(), updateUfo(), updateMissle(), updateAsteroids(); used in run(), update().line 139
static final int SCRAP_COUNT= 30 (constant)No comment in source; used in stopShip(), explode(), update().line 120
AsteroidsSprite shipNo comment in source; assigned in Asteroids(); used in initShip(), updateShip(), stopShip(), updateUfo(), updateMissle() ….line 153
int shipCounterNo comment in source; assigned in updateShip(), stopShip().line 160
int shipsLeftNo comment in source; assigned in initGame(), run(), stopShip(); used in updateShip(), update().line 159
static final int SMALL_POINTS= 50 (constant)No comment in source; used in updateAsteroids().line 131
boolean soundNo comment in source; assigned in Asteroids(), inKey(); used in initUfo(), updateUfo(), initMissle(), updateMissle(), updateAsteroids() ….line 146
Point[] starsNo comment in source; assigned in Asteroids(); used in update().line 138
static final int STORM_PAUSE= 30 (constant)No comment in source; used in initAsteroids().line 122
boolean thrustersPlayingNo comment in source; assigned in initShip(), stopShip(), inKey().line 181
SoundClip thrustersSoundNo comment in source; assigned in loadSounds(); used in initShip(), stopShip(), inKey().line 179
AsteroidsSprite ufoNo comment in source; assigned in Asteroids(); used in run(), initUfo(), updateUfo(), stopUfo(), initMissle() ….line 154
static final int UFO_PASSES= 3 (constant)No comment in source; used in run().line 123
static final int UFO_POINTS= 250 (constant)No comment in source; used in updateUfo().line 132
int ufoCounterNo comment in source; assigned in initUfo(), updateUfo(), stopUfo().line 165
int ufoPassesLeftNo comment in source; assigned in run(), updateUfo(), stopUfo().line 164
boolean up= falseNo comment in source; assigned in inKey(); used in updateShip().line 150
boolean updated= falseNo comment in source; assigned in update().line 110
SoundClip warpSoundNo comment in source; assigned in loadSounds(); used in inKey().line 180

Constructors (1)

SignatureDescriptionSource
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.line 198

Methods (27)

SignatureDescriptionSource
public void endGame()4 statement(s); calls stopShip(), stopUfo(), stopMissle().line 308
public void explode(AsteroidsSprite s)7 statement(s); calls s.render(), explosions[explosionIndex].shape.addPoint(), Math.random(); creates Polygon.line 822
public String getOrangeInfo()Returns ("Asteroids, Copyright 1998 by Mike Hall. Orange port by Tony Swain").line 193
public void guideMissle()10 statement(s); calls Math.atan(), Math.abs(), Math.sin(), Math.cos().line 656
public void halt()2 statement(s).line 327
public void initAsteroids()11 statement(s); calls Math.random(), Math.round(), Math.sin(), Math.cos(), asteroids[i].shape.addPoint() …; creates Polygon.line 693
public void initExplosions()3 statement(s); creates Polygon.line 811
public void initGame()13 statement(s); calls initShip(), initPhotons(), stopUfo(), stopMissle(), initAsteroids() ….line 291
public void initMissle()11 statement(s); calls missle.render(), Math.max(), missleSound.play().line 610
public void initPhotons()3 statement(s).line 529
public void initShip()11 statement(s); calls ship.render(), thrustersSound.halt().line 451
public void initSmallAsteroids(int n)15 statement(s); calls Math.random(), Math.round(), Math.sin(), Math.cos(), asteroids[i].shape.addPoint() …; creates Polygon.line 739
public void initUfo()12 statement(s); calls Math.random(), ufo.render(), saucerSound.play(), Math.floor(), Math.abs().line 551
public void inKey()5 statement(s); calls tmpKey.getKeyChar(), tmpKey.getKeyCode(), thrustersSound.halt(), initUfo(), thrustersSound.play() ….
Overrides Gadget.inKey()
line 863
public void loadSounds()21 statement(s); calls fireSound[i].play(), fireSound[i].halt(), crashSound.play(), crashSound.halt(), explosionSound.play() …; creates SoundClip.line 412
public void run()10 statement(s); calls Thread.currentThread(), controlThread.setPriority(), loadSounds(), graphics.setClip(), updateShip() ….
Implements Runnable.run()
line 339
public void start()3 statement(s); calls loopThread.start(), loadThread.start(); creates Thread.line 316
public void stopMissle()4 statement(s); calls missleSound.halt().line 684
public void stopShip()5 statement(s); calls thrustersSound.halt().line 518
public void stopUfo()5 statement(s); calls saucerSound.halt().line 600
public void update()28 statement(s); calls curView.createImage(), offImage.getGraphics(), offGraphics.setColor(), offGraphics.fillRect(), offGraphics.drawLine() …; creates Color.line 1074
public void updateAsteroids()3 statement(s); calls asteroids[i].advance(), asteroids[i].render(), asteroids[i].isColliding(), explosionSound.play(), explode() ….line 778
public void updateExplosions()2 statement(s); calls explosions[i].advance(), explosions[i].render().line 851
public void updateMissle()2 statement(s); calls stopMissle(), guideMissle(), missle.advance(), missle.render(), missle.isColliding() ….line 626
public void updatePhotons()2 statement(s); calls photons[i].advance(), photons[i].render().line 539
public void updateShip()12 statement(s); calls Math.sin(), Math.cos(), ship.advance(), ship.render(), initShip() ….line 467
public void updateUfo()3 statement(s); calls ufo.advance(), ufo.render(), initUfo(), stopUfo(), ufo.isColliding() ….line 572

Nested & additional classes

AsteroidsSprite (additional top-level (package-private) class in the same source file, lines 29–101)

class AsteroidsSprite

Fields (12)

DeclarationValue / initializerDescriptionSource
boolean activeActive flag.line 35
double angleCurrent angle of rotation.line 36
Color color= nullNo comment in source; not referenced by name in this type’s methods.line 31
double currentXCurrent position on screen.line 38
double currentYCurrent position on screen.line 38
double deltaAngleAmount to change the rotation angle.line 37
double deltaXAmount to change the screen position.line 39
double deltaYAmount to change the screen position.line 39
static int heightNo comment in source; used in advance(), render().line 33
Polygon shapeInitial sprite shape, centered at the origin (0,0).line 34
Polygon spriteFinal location and shape of sprite after applying rotation and moving to screen position. Used for drawing on the screen and in detecting collisions.line 40
static int widthDimensions of the graphics area.line 32

Constructors (1)

SignatureDescriptionSource
public AsteroidsSprite()10 statement(s); calls super(); creates Polygon.line 44

Methods (3)

SignatureDescriptionSource
public void advance()9 statement(s).line 57
public boolean isColliding(AsteroidsSprite s)3 statement(s); calls this.sprite.contains().line 89
public void render()3 statement(s); calls this.sprite.addPoint(), Math.round(), Math.cos(), Math.sin(); creates Polygon.line 77

Inherited members

Non-private members inherited from HyperView superclasses and not overridden or hidden here.

From ViewPane (16 fields, 11 methods)

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)

From Gadget (33 fields, 24 methods)

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()

From Gob (76 fields, 27 methods)

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()

From Linkable (7 fields, 1 methods)

Fields: attachment, index, linkFlags, name, next, parentList, prev

Methods: inList()

Examples

Real usage taken from elsewhere in the HyperView 3.2 source (file and line shown; source path src/com/multiversesocial/hyperview/).

instantiation — AsteroidsDispatch.java, line 34

   34  asteroids = new
   35   Asteroids(curView,1,16,640,460);  //(HyperView,X,Y,width/height)

Applet hosting

The reference port: Mike Hall’s applet as a ViewPane, hosted by ViewMain through AsteroidsDispatch. See the Applet Migration Guide.

Hits--