Class Player

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
GamePiece
Player
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Player
extends GamePiece
Player.java - A ship for the player to manipulate during game
See Also:
Serialized Form
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    class  Player.LeftPressed
    An inner class to respond to left arrow keyboard input (Pressing)
    class  Player.LeftReleased
    An inner class to respond to left arrow keyboard input (Releasing)
    class  Player.RightPressed
    An inner class to respond to right arrow keyboard input (Pressing)
    class  Player.RightReleased
    An inner class to respond to right arrow keyboard input (Releasing)
    class  Player.SpacePressed
    An inner class to respond to space keyboard input (Pressing)
    class  Player.SpaceReleased
    An inner class to respond to space keyboard input (Releasing)
    class  Player.UpPressed
    An inner class to respond to up arrow keyboard input (Pressing)
    class  Player.UpReleased
    An inner class to respond to up arrow keyboard input (Releasing)

    Nested classes/interfaces inherited from class javax.swing.JComponent

    javax.swing.JComponent.AccessibleJComponent

    Nested classes/interfaces inherited from class java.awt.Container

    java.awt.Container.AccessibleAWTContainer

    Nested classes/interfaces inherited from class java.awt.Component

    java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
  • Field Summary

    Fields inherited from class javax.swing.JComponent

    listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW

    Fields inherited from class java.awt.Component

    accessibleContext, 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

    Constructors 
    Constructor Description
    Player​(double x, double y)
    Constructor takes player's x and y coordinates in the game window
  • Method Summary

    Modifier and Type Method Description
    void destroy()
    Destroys this object, disabling it permanently
    double[] getCenter()
    Returns double array holding x and y coordinates of ship center
    double getMaskRadius()
    Returns radius of mask to be used in collision checking
    boolean isEnabled()
    Returns if this object is in an enabled state
    boolean isInvulnerable()
    Returns if this object is invulnerable
    void move()
    Move ship based on momentum vector
    void paintComponent​(java.awt.Graphics g)
    Paints component on graphics canvas
    void respawn()
    Temporarily disables object, respawning it at center of screen
    void rotateImage()
    Rotate image based on ship heading
    void screenWrap()
    Wrap ship around screen if window boundaries are exceeded
    void setInvulnerable()
    Set invulnerability for two seconds
    void shoot()
    Creat a bullet that travels in direction ship is currently facing
    void tick()
    Update player each frame
    double x()
    Returns x coordinate
    double y()
    Returns y coordinate

    Methods inherited from class javax.swing.JComponent

    addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI

    Methods inherited from class java.awt.Container

    add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Player

      public Player​(double x, double y)
      Constructor takes player's x and y coordinates in the game window
      Parameters:
      x - Player x coordinate
      y - Player y coordinate
  • Method Details

    • paintComponent

      public void paintComponent​(java.awt.Graphics g)
      Paints component on graphics canvas
      Overrides:
      paintComponent in class javax.swing.JComponent
      Parameters:
      g - Canvas to paint on
    • setInvulnerable

      public void setInvulnerable()
      Set invulnerability for two seconds
    • tick

      public void tick()
      Update player each frame
      Specified by:
      tick in class GamePiece
    • screenWrap

      public void screenWrap()
      Wrap ship around screen if window boundaries are exceeded
    • move

      public void move()
      Move ship based on momentum vector
      Specified by:
      move in class GamePiece
    • shoot

      public void shoot()
      Creat a bullet that travels in direction ship is currently facing
    • rotateImage

      public void rotateImage()
      Rotate image based on ship heading
    • x

      public double x()
      Returns x coordinate
      Returns:
      x coordinate
    • y

      public double y()
      Returns y coordinate
      Returns:
      y coordinate
    • getMaskRadius

      public double getMaskRadius()
      Returns radius of mask to be used in collision checking
      Specified by:
      getMaskRadius in class GamePiece
      Returns:
      Collision mask
    • getCenter

      public double[] getCenter()
      Returns double array holding x and y coordinates of ship center
      Specified by:
      getCenter in class GamePiece
      Returns:
      double array representing object center
    • destroy

      public void destroy()
      Destroys this object, disabling it permanently
      Specified by:
      destroy in class GamePiece
    • isEnabled

      public boolean isEnabled()
      Returns if this object is in an enabled state
      Overrides:
      isEnabled in class java.awt.Component
      Returns:
      Returns true if object is in an enabled state
    • isInvulnerable

      public boolean isInvulnerable()
      Returns if this object is invulnerable
      Returns:
      Returns true if object is invulnerable
    • respawn

      public void respawn()
      Temporarily disables object, respawning it at center of screen