NOTE:
This game is a LWJGLized implementation of the Space Invaders game by Kevin
Glass. The original implementation is renderer agnostic and supports other
OpenGL implementations as well as Java2D. This version has been made specific
for LWJGL, and has added input control as well as sound (which the original doesn't,
at the time of writing).
You can find the original article here:
http://www.cokeandcode.com
| Modifier and Type | Field and Description |
|---|---|
| private int | alienCount
The number of aliens left on the screen |
| private ArrayList | entities
The list of all the entities that exist in our game |
| private boolean | fireHasBeenReleased
True if the fire key has been released |
| private long | firingInterval
The interval between our players shot (ms) |
| private int | fps
The recorded fps |
| private boolean | fullscreen
Whether we're running in fullscreen mode |
| public static boolean | gameRunning
True if the game is currently "running", i.e. the game loop is looping |
| private Sprite | gotYou
The sprite containing the "You lose!" message |
| private int | height
The height of the game display area |
| private static boolean | isApplication
Is this an application or applet |
| private long | lastFire
The time at which last fired a shot |
| private long | lastFpsTime
The time since the last record of fps |
| private long | lastLoopTime
The time at which the last rendering looped started from the point of view of the game logic |
| private boolean | logicRequiredThisLoop
True if game logic needs to be applied this loop, normally as a result of a game event |
| private Sprite | message
The message to display which waiting for a key press |
| private int | mouseX
Mouse movement on x axis |
| private float | moveSpeed
The speed at which the player's ship should move (pixels/sec) |
| private Sprite | pressAnyKey
The sprite containing the "Press Any Key" message |
| private ArrayList | removeList
The list of entities that need to be removed from the game this loop |
| private ShipEntity | ship
The entity representing the player |
| private int | shotIndex
Last shot index |
| private ShotEntity[] | shots
List of shots |
| private int | SOUND_HIT
ID of hit effect |
| private int | SOUND_LOOSE
ID of loose sound |
| private int | SOUND_SHOT
ID of shot effect |
| private int | SOUND_START
ID of start sound |
| private int | SOUND_WIN
ID of win sound |
| private SoundManager | soundManager
SoundManager to make sound with |
| private TextureLoader | textureLoader
The loader responsible for converting images into OpenGL textures |
| private static long | |
| private boolean | waitingForKeyPress
True if we're holding up game play until a key has been pressed |
| private int | width
The width of the game display area |
| private String | WINDOW_TITLE
The normal title of the window |
| private Sprite | youWin
The sprite containing the "You win!" message |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| private void | |
| public Sprite | |
| public static long | Returns: The high resolution time in millisecondsGet the high resolution time in milliseconds |
| private boolean | |
| private void | |
| public void | |
| public static void | |
| public void | |
| public void | |
| public void | |
| public void | |
| private boolean | |
| public static void | sleep(long
The amount of time in milliseconds to sleep for duration)Sleep for a fixed number of milliseconds. |
| private void | |
| public void | |
| public void | updateLogic()
Notification from a game entity that the logic of the game should be run at the next opportunity (normally as a result of some game event) |
| alienCount | back to summary |
|---|---|
| private int alienCount The number of aliens left on the screen | |
| entities | back to summary |
|---|---|
| private ArrayList<Entity> entities The list of all the entities that exist in our game | |
| fireHasBeenReleased | back to summary |
|---|---|
| private boolean fireHasBeenReleased True if the fire key has been released | |
| firingInterval | back to summary |
|---|---|
| private long firingInterval The interval between our players shot (ms) | |
| fps | back to summary |
|---|---|
| private int fps The recorded fps | |
| fullscreen | back to summary |
|---|---|
| private boolean fullscreen Whether we're running in fullscreen mode | |
| gameRunning | back to summary |
|---|---|
| public static boolean gameRunning True if the game is currently "running", i.e. the game loop is looping | |
| gotYou | back to summary |
|---|---|
| private Sprite gotYou The sprite containing the "You lose!" message | |
| height | back to summary |
|---|---|
| private int height The height of the game display area | |
| isApplication | back to summary |
|---|---|
| private static boolean isApplication Is this an application or applet | |
| lastFire | back to summary |
|---|---|
| private long lastFire The time at which last fired a shot | |
| lastFpsTime | back to summary |
|---|---|
| private long lastFpsTime The time since the last record of fps | |
| lastLoopTime | back to summary |
|---|---|
| private long lastLoopTime The time at which the last rendering looped started from the point of view of the game logic | |
| logicRequiredThisLoop | back to summary |
|---|---|
| private boolean logicRequiredThisLoop True if game logic needs to be applied this loop, normally as a result of a game event | |
| message | back to summary |
|---|---|
| private Sprite message The message to display which waiting for a key press | |
| mouseX | back to summary |
|---|---|
| private int mouseX Mouse movement on x axis | |
| moveSpeed | back to summary |
|---|---|
| private float moveSpeed The speed at which the player's ship should move (pixels/sec) | |
| pressAnyKey | back to summary |
|---|---|
| private Sprite pressAnyKey The sprite containing the "Press Any Key" message | |
| removeList | back to summary |
|---|---|
| private ArrayList<Entity> removeList The list of entities that need to be removed from the game this loop | |
| ship | back to summary |
|---|---|
| private ShipEntity ship The entity representing the player | |
| shotIndex | back to summary |
|---|---|
| private int shotIndex Last shot index | |
| shots | back to summary |
|---|---|
| private ShotEntity[] shots List of shots | |
| SOUND_HIT | back to summary |
|---|---|
| private int SOUND_HIT ID of hit effect | |
| SOUND_LOOSE | back to summary |
|---|---|
| private int SOUND_LOOSE ID of loose sound | |
| SOUND_SHOT | back to summary |
|---|---|
| private int SOUND_SHOT ID of shot effect | |
| SOUND_START | back to summary |
|---|---|
| private int SOUND_START ID of start sound | |
| SOUND_WIN | back to summary |
|---|---|
| private int SOUND_WIN ID of win sound | |
| soundManager | back to summary |
|---|---|
| private SoundManager soundManager SoundManager to make sound with | |
| textureLoader | back to summary |
|---|---|
| private TextureLoader textureLoader The loader responsible for converting images into OpenGL textures | |
| timerTicksPerSecond | back to summary |
|---|---|
| private static long timerTicksPerSecond | |
| waitingForKeyPress | back to summary |
|---|---|
| private boolean waitingForKeyPress True if we're holding up game play until a key has been pressed | |
| width | back to summary |
|---|---|
| private int width The width of the game display area | |
| WINDOW_TITLE | back to summary |
|---|---|
| private String WINDOW_TITLE The normal title of the window | |
| youWin | back to summary |
|---|---|
| private Sprite youWin The sprite containing the "You win!" message | |
| Game | back to summary |
|---|---|
| public Game(boolean fullscreen) Construct our game and set it running. | |
| execute | back to summary |
|---|---|
| public void execute() | |
| frameRendering | back to summary |
|---|---|
| public void frameRendering() Notification that a frame is being rendered. Responsible for running game logic and rendering the scene. | |
| gameLoop | back to summary |
|---|---|
| private void gameLoop() Run the main game loop. This method keeps rendering the scene and requesting that the callback update its screen. | |
| getSprite | back to summary |
|---|---|
| public Sprite getSprite(String ref) Create or get a sprite which displays the image that is pointed to in the classpath by "ref" | |
| getTime | back to summary |
|---|---|
| public static long getTime() Get the high resolution time in milliseconds
| |
| hasInput | back to summary |
|---|---|
| private boolean hasInput(int direction) | |
| initEntities | back to summary |
|---|---|
| private void initEntities() Initialise the starting state of the entities (ship and aliens). Each entitiy will be added to the overall list of entities in the game. | |
| initialize | back to summary |
|---|---|
| public void initialize() Intialise the common elements for the game | |
| main | back to summary |
|---|---|
| public static void main(String[] argv) The entry point into the game. We'll simply create an instance of class which will start the display and game loop.
| |
| notifyAlienKilled | back to summary |
|---|---|
| public void notifyAlienKilled() Notification that an alien has been killed | |
| notifyDeath | back to summary |
|---|---|
| public void notifyDeath() Notification that the player has died. | |
| notifyWin | back to summary |
|---|---|
| public void notifyWin() Notification that the player has won since all the aliens are dead. | |
| removeEntity | back to summary |
|---|---|
| public void removeEntity(Entity entity) Remove an entity from the game. The entity removed will no longer move or be drawn.
| |
| setDisplayMode | back to summary |
|---|---|
| private boolean setDisplayMode() Sets the display mode for fullscreen mode | |
| sleep | back to summary |
|---|---|
| public static void sleep(long duration) Sleep for a fixed number of milliseconds.
| |
| startGame | back to summary |
|---|---|
| private void startGame() Start a fresh game, this should clear out any old data and create a new set. | |
| tryToFire | back to summary |
|---|---|
| public void tryToFire() Attempt to fire a shot from the player. Its called "try" since we must first check that the player can fire at this point, i.e. has he/she waited long enough between shots | |
| updateLogic | back to summary |
|---|---|
| public void updateLogic() Notification from a game entity that the logic of the game should be run at the next opportunity (normally as a result of some game event) | |