fang
Class Game

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by fang.GameWindow
                          extended by fang.FrameAdvancer
                              extended by fang.GameLoop
                                  extended by fang.GameRedirection
                                      extended by fang.Game
All Implemented Interfaces:
AlarmScheduler, ActionListener, WindowStateListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer

public class Game
extends GameRedirection

The class representing a FANG video game. This is an "empty" game box. By extending it, a program gets the pretty window, the buttons, and the behavior of every FANG video game. Because the box is empty, there is no actual game contained in this class. Programmers extend Game to create their own games. The extension is usually by defining new versions of setup() and GameRedirection.advance(double) (or advance() if you don't care about elapsed time between frames). Create and initialize game attributes in the setup() method and then update their state in the GameRedirection.advance(double) method. In FANG, a game runs something like this (the following is not actually Java): create Window, create Game g, etc. setup(); while (!g.isGameOver()) { draw all known Sprites check for input from all input devices calculate timeSinceLastCall to advance advance(timeSinceLastCall); }

Author:
Jam Jenkins and the FANG Team
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static Color DEFAULT_BACKGROUND_COLOR
          the color to use when clearing the background
static Dimension DEFAULT_GAME_DIMENSIONS
          default size of canvas
 
Fields inherited from class fang.GameRedirection
finishingGame, firstGame, restarting
 
Fields inherited from class fang.GameLoop
client, player, random, SEED
 
Fields inherited from class fang.FrameAdvancer
canvas, timeInterval
 
Fields inherited from class fang.GameWindow
cards, connectButton, container, createOwnFrame, displayControlButtons, frame, fullScreen, help, helpPlay, loadingMessage, mute, pause, players, playersSelectable, playersSpinner, quit, serverField, serverLabel, serverSelectable, sessionComboBox, sessionLabel, sessionSelectable, title
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Game()
          Create a new Game with the default size and default background color.
Game(Color backgroundColor)
           
Game(Dimension gameDimensions)
          Create a new Game with the default size and default background color.
Game(Dimension gameDimensions, Color backgroundColor)
          Create a new Game with the given size and given background color.
Game(int gamePixelWidth, int gamePixelHeight)
          Create a new Game with the given size and default background color.
Game(int gamePixelWidth, int gamePixelHeight, Color backgroundColor)
          Create a new Game with the given size and given background color.
 
Method Summary
 void addBottom(Sprite... sprite)
           
static void addColor(String name, Color color)
           
static void addColor(String name, String rgb)
           
 void addSprite(double layer, Sprite... sprite)
           
 void addSprite(Sprite... sprite)
           
 void advance()
           
 boolean containsSprite(Sprite sprite)
           
 boolean downPressed()
          Was the down-arrow key pressed as the last key by the default (local) player?
 boolean downPressed(int id)
          Was the down-arrow key pressed as the last key by the given player?
 void flattenLayers()
           
 Sprite[] getAllSprites()
          Get an array of all of the sprites in the game.
 double getAspect()
           
 Location2D getClick2D()
          Get location for the default (local) player's mouse when any button was clicked.
 Location2D getClick2D(int id)
          Get location for the given player's mouse when any button was clicked.
 double getClickX()
          Return the x-coordinate of the default (local) player's mouse when any button was clicked.
 double getClickX(int id)
          Return the x-coordinate of the given player's mouse when any button was clicked.
 double getClickY()
          Return the y-coordinate of the default (local) player's mouse when any button was clicked.
 double getClickY(int id)
          Return the y-coordinate of the given player's mouse when any button was clicked.
static Color getColor(int red, int green, int blue)
          Create a solid, opaque color with the given red, gree, and blue values.
static Color getColor(int red, int green, int blue, int opacity)
          Create a solid, translucent color with the given red, gree, and blue values.
static Color getColor(String name)
           
static Color getColor(String name, int transparency)
           
static Color getColorFromRGB(String rgb)
           
static Color getColorFromRGB(String rgb, int transparency)
           
static String getColorName(Color color)
           
static String getColorName(int r, int g, int b)
           
static String getColorName(String rgb)
           
 char getKeyPressed()
          Returns the last key pressed for the default (local) player.
 char getKeyPressed(int id)
          Returns the last key pressed for the given player.
 Sprite[] getLayer(double layer)
           
 double getLayer(Sprite sprite)
           
 Location2D getLeftClick2D()
          Get location for the default (local) player's mouse when the left button was clicked.
 Location2D getLeftClick2D(int id)
          Get location for the given player's mouse when the left button was clicked.
 double getLeftClickX()
          Return the x-coordinate of the default (local) player's mouse when left button was clicked.
 double getLeftClickX(int id)
          Return the x-coordinate of the given player's mouse when left button was clicked.
 double getLeftClickY()
          Return the y-coordinate of the default (local) player's mouse when left button was clicked.
 double getLeftClickY(int id)
          Return the y-coordinate of the given player's mouse when left button was clicked.
 int getLives()
           
 int getLives(int id)
           
 char getLowerCaseKeyPressed()
          Returns the last key pressed for the default (local) player converted to lowercase.
 char getLowerCaseKeyPressed(int id)
          Returns the last key pressed for the given player converted to lowercase.
 double getMaxX()
           
 double getMaxY()
           
 Object getMessage()
           
 Object getMessage(int id)
           
 Location2D getMiddleClick2D()
          Get location for the default (local) player's mouse when the middle button was clicked.
 Location2D getMiddleClick2D(int id)
          Get location for the given player's mouse when the middle button was clicked.
 double getMiddleClickX()
          Return the x-coordinate of the default (local) player's mouse when middle button was clicked.
 double getMiddleClickX(int id)
          Return the x-coordinate of the given player's mouse when middle button was clicked.
 double getMiddleClickY()
          Return the y-coordinate of the default (local) player's mouse when middle button was clicked.
 double getMiddleClickY(int id)
          Return the y-coordinate of the given player's mouse when middle button was clicked.
 Location2D getMouse2D()
          Get location for the default (local) player's mouse.
 Location2D getMouse2D(int id)
          Get location for a given player.
 double getMouseX()
          Return the x-coordinate of the mouse for the default (local) player.
 double getMouseX(int id)
          Return the x-coordinate of the mouse for a given player id.
 double getMouseY()
          Return the y-coordinate of the mouse for the default (local) player.
 double getMouseY(int id)
          Return the y-coordinate of the mouse for a given player id.
 int getPlayerID()
           
 String getPlayerName()
           
 String getPlayerName(int id)
           
 Random getRandom()
          Return this Game's random number generator.
 Color getRandomColor()
          Deprecated.  
 Location2D getRightClick2D()
          Get location for the default (local) player's mouse when the right button was clicked.
 Location2D getRightClick2D(int id)
          Get location for the given player's mouse when the right button was clicked.
 double getRightClickX()
          Return the x-coordinate of the default (local) player's mouse when right button was clicked.
 double getRightClickX(int id)
          Return the x-coordinate of the given player's mouse when right button was clicked.
 double getRightClickY()
          Return the y-coordinate of the default (local) player's mouse when right button was clicked.
 double getRightClickY(int id)
          Return the y-coordinate of the given player's mouse when right button was clicked.
 int getScore()
           
 int getScore(int id)
           
 char getUpperCaseKeyPressed()
          Returns the last key pressed for the default (local) player converted to UPPERCASE.
 char getUpperCaseKeyPressed(int id)
          Returns the last key pressed for the given player converted to UPPERCASE.
 boolean hasMessage()
           
 boolean hasMessage(int id)
           
 boolean keyPressed()
          Was any key pressed by the default (local) player?
 boolean keyPressed(int id)
          Was any key pressed by the given player?
 boolean leftPressed()
          Was the left-arrow key pressed as the last key by the default (local) player?
 boolean leftPressed(int id)
          Was the left-arrow key pressed as the last key by the given player?
 boolean mouseLeftPressed()
          Was the left button on the default (local) player's mouse pressed during the last frame?
 boolean mouseLeftPressed(int id)
          Was the left button on the given player's mouse pressed during the last frame?
 boolean mouseMiddlePressed()
          Was the middle button on the default (local) player's mouse pressed during the last frame?
 boolean mouseMiddlePressed(int id)
          Was the middle button on the given player's mouse pressed during the last frame?
 boolean mousePressed()
          Was any button on the default (local) player's mouse pressed during the last frame?
 boolean mousePressed(int id)
          Was any button on the given player's mouse pressed during the last frame?
 boolean mouseRightPressed()
          Was the right button on the default (local) player's mouse pressed during the last frame?
 boolean mouseRightPressed(int id)
          Was the right button on the given player's mouse pressed during the last frame?
 boolean randomBoolean()
          Return a randomly selected boolean value.
 Color randomColor()
          Returns a random color.
 double randomDouble()
          Return a uniformly distributed random double on the range [0.0, 1.0).
 double randomDouble(double max)
           
 double randomDouble(double min, double max)
           
 int randomInt()
           
 int randomInt(int max)
           
 int randomInt(int min, int max)
           
 void removeAllSprites()
           
 void removeCursor()
          removes the cursor from the game canvas
 void removeSprite(Sprite... sprite)
           
 void restoreCursor()
          adds the default cursor back to the screen
 boolean rightPressed()
          Was the right-arrow key pressed as the last key by the default (local) player?
 boolean rightPressed(int id)
          Was the right-arrow key pressed as the last key by the given player?
 void setAspect(double aspect)
           
 void setCursor(URL url)
          sets the cursor for the game engine
 void setLives(int lives)
           
 void setLives(int lives, int id)
           
 void setPlayerName(String name)
           
 void setPlayerName(String name, int id)
           
 void setScore(int score)
           
 void setScore(int score, int id)
           
 void setup()
           
 boolean upPressed()
          Was the up-arrow key pressed as the last key by the default (local) player?
 boolean upPressed(int id)
          Was the up-arrow key pressed as the last key by the given player?
 
Methods inherited from class fang.GameRedirection
addGame, addLevel, advance, advanceFrame, advanceLevel, begin, cancel, cancelAlarm, cancelAllAlarms, cancelAllTimedActions, cleanUp, connect, copyFirstFields, copyFrom, disconnect, finishGame, finishLevel, gameIsOver, getAlarms, getAllTimedActions, getCanvas, getCurrentGame, getGameName, getID, getLevelNumber, getNextLevel, getNumberOfPlayers, getPlayer, getPlayer, getPlayer, getScreenRefreshRate, getServerName, getSessionName, getTime, initializePersistantState, isGameOver, isMuted, isPaused, muteSound, pause, pauseToggle, persist, persist, persist, playSound, playSoundImmediately, reallyFinishGame, reallyStartOver, refreshScreen, removeLevelObjects, resetTime, resume, runAsApplication, schedule, scheduleAbsolute, scheduleRelative, sendMessage, serverSaysPauseToggle, setCanvas, setGameName, setGameOver, setHelp, setHelpText, setMinimumModelFrameRate, setNextLevel, setNumberOfPlayers, setServerName, setSessionName, setTitle, startGame, startGameImmediately, startOver, stop, toggleAudible, togglePause, toggleSound, updateModel
 
Methods inherited from class fang.GameLoop
getGameOverLevel, getGameResource, getResource, main, postAdvanceFrame
 
Methods inherited from class fang.FrameAdvancer
setBackground
 
Methods inherited from class fang.GameWindow
actionPerformed, getDefaultSize, getHash, getHelpStyleSheet, getHostname, init, isCreatingOwnFrame, setCreateOwnFrame, setDefaultHelp, setLoadMessage, windowStateChanged
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BACKGROUND_COLOR

public static final Color DEFAULT_BACKGROUND_COLOR
the color to use when clearing the background


DEFAULT_GAME_DIMENSIONS

public static final Dimension DEFAULT_GAME_DIMENSIONS
default size of canvas

Constructor Detail

Game

public Game()
Create a new Game with the default size and default background color. See DEFAULT_GAME_DIMENSIONS and DEFAULT_BACKGROUND_COLOR for definitions of the default values. The game will keep the same aspect ratio (ratio between width and height) even when resized after creation.


Game

public Game(Color backgroundColor)

Game

public Game(Dimension gameDimensions)
Create a new Game with the default size and default background color. See DEFAULT_GAME_DIMENSIONS and DEFAULT_BACKGROUND_COLOR for definitions of the default values. The game will keep the same aspect ratio (ratio between width and height) even when resized after creation.

Parameters:
gameDimensions - initial dimensions of the game field in pixels

Game

public Game(int gamePixelWidth,
            int gamePixelHeight)
Create a new Game with the given size and default background color. See DEFAULT_BACKGROUND_COLOR for definitions of the default values. The game will keep the same aspect ratio (ratio between width and height) even when resized after creation.

Parameters:
gamePixelWidth - initial width of the game field in pixels
gamePixelHeight - initial height of the game field in pixels

Game

public Game(int gamePixelWidth,
            int gamePixelHeight,
            Color backgroundColor)
Create a new Game with the given size and given background color. The game will keep the same aspect ratio (ratio between width and height) even when resized after creation.

Parameters:
gamePixelWidth - initial width of the game field in pixels
gamePixelHeight - initial height of the game field in pixels
backgroundColor - inital background color of the game field

Game

public Game(Dimension gameDimensions,
            Color backgroundColor)
Create a new Game with the given size and given background color. The game will keep the same aspect ratio (ratio between width and height) even when resized after creation.

Parameters:
gameDimensions - initial dimensions of the game field in pixels
backgroundColor - inital background color of the game field
Method Detail

getMouse2D

public Location2D getMouse2D(int id)
Get location for a given player. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates).

Parameters:
id - - the identifier of the player to get the mouse for
Returns:
the location of the mouse of the given player

getMouseX

public double getMouseX(int id)
Return the x-coordinate of the mouse for a given player id.

Parameters:
id - - player id to get coordinate for
Returns:
the screen x-coordinate of the given mouse during this frame (0.0 - 1.0 on screen)

getMouseY

public double getMouseY(int id)
Return the y-coordinate of the mouse for a given player id.

Parameters:
id - - player id to get coordinate for
Returns:
the screen y-coordinate of the given mouse during this frame (0.0 - 1.0 on screen)

getMouse2D

public Location2D getMouse2D()
Get location for the default (local) player's mouse. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates).

Returns:
the location of the mouse of the given player

getMouseX

public double getMouseX()
Return the x-coordinate of the mouse for the default (local) player.

Returns:
the screen x-coordinate of the mouse during this frame (0.0 - 1.0 on screen)

getMouseY

public double getMouseY()
Return the y-coordinate of the mouse for the default (local) player.

Returns:
the screen y-coordinate of the mouse during this frame (0.0 - 1.0 on screen)

getClick2D

public Location2D getClick2D(int id)
Get location for the given player's mouse when any button was clicked. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates) where any button was clicked.

Parameters:
id - - player id to get coordinate for
Returns:
the location of the mouse of the given player; null if the player did not click this frame

getClickX

public double getClickX(int id)
Return the x-coordinate of the given player's mouse when any button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Parameters:
id - player to find mouse click location for
Returns:
x-coordinate (in screens) where mouse was clicked (if clicked this frame); Double.NaN if no mouse click this frame

getClickY

public double getClickY(int id)
Return the y-coordinate of the given player's mouse when any button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Parameters:
id - player to find mouse click location for
Returns:
y-coordinate (in screens) where mouse was clicked (if clicked this frame); Double.NaN if no mouse click this frame

getClick2D

public Location2D getClick2D()
Get location for the default (local) player's mouse when any button was clicked. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates) where any button was clicked or null if no click.

Returns:
the location of the mouse of the given player; null if the player did not click this frame

getClickX

public double getClickX()
Return the x-coordinate of the default (local) player's mouse when any button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Returns:
x-coordinate (in screens) where mouse was clicked (if clicked this frame); Double.NaN if no mouse click this frame

getClickY

public double getClickY()
Return the y-coordinate of the default (local) player's mouse when any button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Returns:
y-coordinate (in screens) where mouse was clicked (if clicked this frame); Double.NaN if no mouse click this frame

getLeftClick2D

public Location2D getLeftClick2D(int id)
Get location for the given player's mouse when the left button was clicked. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates) where any button was clicked.

Parameters:
id - - player id to get coordinate for
Returns:
the location of the mouse of the given player at left click; null if the player did not click this frame

getLeftClickX

public double getLeftClickX(int id)
Return the x-coordinate of the given player's mouse when left button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Parameters:
id - player to find mouse click location for
Returns:
x-coordinate (in screens) where mouse was left clicked (if clicked this frame); Double.NaN if no mouse click this frame

getLeftClickY

public double getLeftClickY(int id)
Return the y-coordinate of the given player's mouse when left button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Parameters:
id - player to find mouse click location for
Returns:
y-coordinate (in screens) where mouse was left clicked (if clicked this frame); Double.NaN if no mouse click this frame

getLeftClick2D

public Location2D getLeftClick2D()
Get location for the default (local) player's mouse when the left button was clicked. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates) where any button was clicked.

Returns:
the location of the mouse of the given player at left click; null if the player did not click this frame

getLeftClickX

public double getLeftClickX()
Return the x-coordinate of the default (local) player's mouse when left button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Returns:
x-coordinate (in screens) where mouse was left clicked (if clicked this frame); Double.NaN if no mouse click this frame

getLeftClickY

public double getLeftClickY()
Return the y-coordinate of the default (local) player's mouse when left button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Returns:
y-coordinate (in screens) where mouse was left clicked (if clicked this frame); Double.NaN if no mouse click this frame

getMiddleClick2D

public Location2D getMiddleClick2D(int id)
Get location for the given player's mouse when the middle button was clicked. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates) where any button was clicked.

Parameters:
id - - player id to get coordinate for
Returns:
the location of the mouse of the given player at middle click; null if the player did not click this frame

getMiddleClickX

public double getMiddleClickX(int id)
Return the x-coordinate of the given player's mouse when middle button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Parameters:
id - player to find mouse click location for
Returns:
x-coordinate (in screens) where mouse was middle clicked (if clicked this frame); Double.NaN if no mouse click this frame

getMiddleClickY

public double getMiddleClickY(int id)
Return the y-coordinate of the given player's mouse when middle button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Parameters:
id - player to find mouse click location for
Returns:
y-coordinate (in screens) where mouse was middle clicked (if clicked this frame); Double.NaN if no mouse click this frame

getMiddleClick2D

public Location2D getMiddleClick2D()
Get location for the default (local) player's mouse when the middle button was clicked. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates) where any button was clicked.

Returns:
the location of the mouse of the given player at middle click; null if the player did not click this frame

getMiddleClickX

public double getMiddleClickX()
Return the x-coordinate of the default (local) player's mouse when middle button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Returns:
x-coordinate (in screens) where mouse was middle clicked (if clicked this frame); Double.NaN if no mouse click this frame

getMiddleClickY

public double getMiddleClickY()
Return the y-coordinate of the default (local) player's mouse when middle button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Returns:
y-coordinate (in screens) where mouse was middle clicked (if clicked this frame); Double.NaN if no mouse click this frame

getRightClick2D

public Location2D getRightClick2D(int id)
Get location for the given player's mouse when the right button was clicked. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates) where any button was clicked.

Parameters:
id - - player id to get coordinate for
Returns:
the location of the mouse of the given player at right click; null if the player did not click this frame

getRightClickX

public double getRightClickX(int id)
Return the x-coordinate of the given player's mouse when right button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Parameters:
id - player to find mouse click location for
Returns:
x-coordinate (in screens) where mouse was right clicked (if clicked this frame); Double.NaN if no mouse click this frame

getRightClickY

public double getRightClickY(int id)
Return the y-coordinate of the given player's mouse when right button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Parameters:
id - player to find mouse click location for
Returns:
y-coordinate (in screens) where mouse was right clicked (if clicked this frame); Double.NaN if no mouse click this frame

getRightClick2D

public Location2D getRightClick2D()
Get location for the default (local) player's mouse when the right button was clicked. Returns the location (a point) in screen coordinates (0.0-1.0 for both x- and y-coordinates) where any button was clicked.

Returns:
the location of the mouse of the given player at right click; null if the player did not click this frame

getRightClickX

public double getRightClickX()
Return the x-coordinate of the default (local) player's mouse when right button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Returns:
x-coordinate (in screens) where mouse was right clicked (if clicked this frame); Double.NaN if no mouse click this frame

getRightClickY

public double getRightClickY()
Return the y-coordinate of the default (local) player's mouse when right button was clicked. If no button was clicked, will return the special numeric value not a number or Double.NaN.

Returns:
y-coordinate (in screens) where mouse was right clicked (if clicked this frame); Double.NaN if no mouse click this frame

mousePressed

public boolean mousePressed(int id)
Was any button on the given player's mouse pressed during the last frame?

Parameters:
id - player whose mouse should be checked
Returns:
true if any button on the mouse was pressed this frame, false otherwise

mousePressed

public boolean mousePressed()
Was any button on the default (local) player's mouse pressed during the last frame?

Parameters:
id - player whose mouse should be checked
Returns:
true if any button on the mouse was pressed this frame, false otherwise

mouseLeftPressed

public boolean mouseLeftPressed(int id)
Was the left button on the given player's mouse pressed during the last frame?

Parameters:
id - player whose mouse should be checked
Returns:
true if any button on the mouse was pressed this frame, false otherwise

mouseLeftPressed

public boolean mouseLeftPressed()
Was the left button on the default (local) player's mouse pressed during the last frame?

Parameters:
id - player whose mouse should be checked
Returns:
true if any button on the mouse was pressed this frame, false otherwise

mouseMiddlePressed

public boolean mouseMiddlePressed(int id)
Was the middle button on the given player's mouse pressed during the last frame?

Parameters:
id - player whose mouse should be checked
Returns:
true if any button on the mouse was pressed this frame, false otherwise

mouseMiddlePressed

public boolean mouseMiddlePressed()
Was the middle button on the default (local) player's mouse pressed during the last frame?

Parameters:
id - player whose mouse should be checked
Returns:
true if any button on the mouse was pressed this frame, false otherwise

mouseRightPressed

public boolean mouseRightPressed(int id)
Was the right button on the given player's mouse pressed during the last frame?

Parameters:
id - player whose mouse should be checked
Returns:
true if any button on the mouse was pressed this frame, false otherwise

mouseRightPressed

public boolean mouseRightPressed()
Was the right button on the default (local) player's mouse pressed during the last frame?

Parameters:
id - player whose mouse should be checked
Returns:
true if any button on the mouse was pressed this frame, false otherwise

getKeyPressed

public char getKeyPressed(int id)
Returns the last key pressed for the given player.

Parameters:
id - - identifer for player owning the keyboard to be checked
Returns:
the last key pressed or Keyboard.NONE if no key was pressed this frame

getKeyPressed

public char getKeyPressed()
Returns the last key pressed for the default (local) player.

Returns:
the last key pressed or Keyboard.NONE if no key was pressed this frame

getLowerCaseKeyPressed

public char getLowerCaseKeyPressed(int id)
Returns the last key pressed for the given player converted to lowercase.

Parameters:
id - - identifer for player owning the keyboard to be checked
Returns:
the last key pressed in lowercase (non-letters unchanged) or Keyboard.NONE if no key was pressed this frame

getLowerCaseKeyPressed

public char getLowerCaseKeyPressed()
Returns the last key pressed for the default (local) player converted to lowercase.

Returns:
the last key pressed in lowercase (non-letters unchanged) or Keyboard.NONE if no key was pressed this frame

getUpperCaseKeyPressed

public char getUpperCaseKeyPressed(int id)
Returns the last key pressed for the given player converted to UPPERCASE.

Parameters:
id - - identifer for player owning the keyboard to be checked
Returns:
the last key pressed in UPPERCASE (non-letters unchanged) or Keyboard.NONE if no key was pressed this frame

getUpperCaseKeyPressed

public char getUpperCaseKeyPressed()
Returns the last key pressed for the default (local) player converted to UPPERCASE.

Returns:
the last key pressed in UPPERCASE (non-letters unchanged) or Keyboard.NONE if no key was pressed this frame

upPressed

public boolean upPressed(int id)
Was the up-arrow key pressed as the last key by the given player?

Parameters:
id - identifier for the player owning the keyboard to be checked
Returns:
true if up-arrow key was last key pressed; false otherwise

upPressed

public boolean upPressed()
Was the up-arrow key pressed as the last key by the default (local) player?

Returns:
true if up-arrow key was last key pressed; false otherwise

downPressed

public boolean downPressed(int id)
Was the down-arrow key pressed as the last key by the given player?

Parameters:
id - identifier for the player owning the keyboard to be checked
Returns:
true if down-arrow key was last key pressed; false otherwise

downPressed

public boolean downPressed()
Was the down-arrow key pressed as the last key by the default (local) player?

Returns:
true if down-arrow key was last key pressed; false otherwise

rightPressed

public boolean rightPressed(int id)
Was the right-arrow key pressed as the last key by the given player?

Parameters:
id - identifier for the player owning the keyboard to be checked
Returns:
true if right-arrow key was last key pressed; false otherwise

rightPressed

public boolean rightPressed()
Was the right-arrow key pressed as the last key by the default (local) player?

Returns:
true if right-arrow key was last key pressed; false otherwise

leftPressed

public boolean leftPressed(int id)
Was the left-arrow key pressed as the last key by the given player?

Parameters:
id - identifier for the player owning the keyboard to be checked
Returns:
true if left-arrow key was last key pressed; false otherwise

leftPressed

public boolean leftPressed()
Was the left-arrow key pressed as the last key by the default (local) player?

Returns:
true if left-arrow key was last key pressed; false otherwise

keyPressed

public boolean keyPressed(int id)
Was any key pressed by the given player?

Parameters:
id - identifier for the player owning the keyboard to be checked
Returns:
true if a key was pressed this frame; false otherwise

keyPressed

public boolean keyPressed()
Was any key pressed by the default (local) player?

Returns:
true if a key was pressed this frame; false otherwise

setAspect

public void setAspect(double aspect)

restoreCursor

public void restoreCursor()
Description copied from class: FrameAdvancer
adds the default cursor back to the screen

Overrides:
restoreCursor in class GameRedirection

removeCursor

public void removeCursor()
Description copied from class: FrameAdvancer
removes the cursor from the game canvas

Overrides:
removeCursor in class GameRedirection

setCursor

public void setCursor(URL url)
Description copied from class: FrameAdvancer
sets the cursor for the game engine

Overrides:
setCursor in class GameRedirection

getMaxX

public double getMaxX()

getMaxY

public double getMaxY()

addSprite

public void addSprite(Sprite... sprite)

addSprite

public void addSprite(double layer,
                      Sprite... sprite)

getLayer

public double getLayer(Sprite sprite)

getLayer

public Sprite[] getLayer(double layer)

flattenLayers

public void flattenLayers()

removeSprite

public void removeSprite(Sprite... sprite)

removeAllSprites

public void removeAllSprites()

containsSprite

public boolean containsSprite(Sprite sprite)

getAllSprites

public Sprite[] getAllSprites()
Get an array of all of the sprites in the game. This will contain all of the Sprites which have been added (through addSprite) and not removed (through removeSprite).

Returns:
an array of all of the Sprites that are in the game

addBottom

public void addBottom(Sprite... sprite)

getAspect

public double getAspect()

getColor

public static Color getColor(int red,
                             int green,
                             int blue)
Create a solid, opaque color with the given red, gree, and blue values.

Parameters:
red - the amount of red to include; range is [0..255] with 0 meaning no red
green - the amount of green to include; range is [0..255] with 0 meaining no green
blue - the amount of blue to include; range is [0..255] with 0 meaning no blue
Returns:
a Color object for the given shade

getColor

public static Color getColor(int red,
                             int green,
                             int blue,
                             int opacity)
Create a solid, translucent color with the given red, gree, and blue values. The opacity value determines how opaque the color is with 0 being completely transparent and 255 being completely opaque.

Parameters:
red - the amount of red to include; range is [0..255] with 0 meaning no red
green - the amount of green to include; range is [0..255] with 0 meaining no green
blue - the amount of blue to include; range is [0..255] with 0 meaning no blue
opacity - the amount of opaqueness for the color; range is [0..255] with 0 meaning transparent and 255 meaning opaque
Returns:
a Color object for the given shade

getColor

public static Color getColor(String name)

getColor

public static Color getColor(String name,
                             int transparency)

getColorName

public static String getColorName(int r,
                                  int g,
                                  int b)

getColorName

public static String getColorName(String rgb)

getColorName

public static String getColorName(Color color)

getColorFromRGB

public static Color getColorFromRGB(String rgb)

getColorFromRGB

public static Color getColorFromRGB(String rgb,
                                    int transparency)

addColor

public static void addColor(String name,
                            Color color)

addColor

public static void addColor(String name,
                            String rgb)

getRandomColor

@Deprecated
public Color getRandomColor()
Deprecated. 

Returns:

randomColor

public Color randomColor()
Returns a random color. The random color is safe across multiple instances.

Returns:
a randomly selected color.

getRandom

public Random getRandom()
Return this Game's random number generator.

Returns:
the Random used by this game to generate random numbers.

randomBoolean

public boolean randomBoolean()
Return a randomly selected boolean value. The result is true and false half of the time each.

Returns:
a randomly selected boolean value.

randomDouble

public double randomDouble()
Return a uniformly distributed random double on the range [0.0, 1.0).

Returns:

randomDouble

public double randomDouble(double max)

randomDouble

public double randomDouble(double min,
                           double max)

randomInt

public int randomInt()

randomInt

public int randomInt(int max)

randomInt

public int randomInt(int min,
                     int max)

getLives

public int getLives(int id)

getLives

public int getLives()

setLives

public void setLives(int lives,
                     int id)

setLives

public void setLives(int lives)

getPlayerName

public String getPlayerName(int id)

getPlayerName

public String getPlayerName()

setPlayerName

public void setPlayerName(String name,
                          int id)

setPlayerName

public void setPlayerName(String name)

getScore

public int getScore(int id)

getScore

public int getScore()

setScore

public void setScore(int score,
                     int id)

setScore

public void setScore(int score)

getPlayerID

public int getPlayerID()

hasMessage

public boolean hasMessage(int id)

hasMessage

public boolean hasMessage()

getMessage

public Object getMessage(int id)

getMessage

public Object getMessage()

advance

public void advance()
Specified by:
advance in class GameRedirection

setup

public void setup()
Specified by:
setup in class GameRedirection