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 classPlayer.LeftPressedAn inner class to respond to left arrow keyboard input (Pressing)classPlayer.LeftReleasedAn inner class to respond to left arrow keyboard input (Releasing)classPlayer.RightPressedAn inner class to respond to right arrow keyboard input (Pressing)classPlayer.RightReleasedAn inner class to respond to right arrow keyboard input (Releasing)classPlayer.SpacePressedAn inner class to respond to space keyboard input (Pressing)classPlayer.SpaceReleasedAn inner class to respond to space keyboard input (Releasing)classPlayer.UpPressedAn inner class to respond to up arrow keyboard input (Pressing)classPlayer.UpReleasedAn inner class to respond to up arrow keyboard input (Releasing)Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent -
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 -
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 voiddestroy()Destroys this object, disabling it permanentlydouble[]getCenter()Returns double array holding x and y coordinates of ship centerdoublegetMaskRadius()Returns radius of mask to be used in collision checkingbooleanisEnabled()Returns if this object is in an enabled statebooleanisInvulnerable()Returns if this object is invulnerablevoidmove()Move ship based on momentum vectorvoidpaintComponent(java.awt.Graphics g)Paints component on graphics canvasvoidrespawn()Temporarily disables object, respawning it at center of screenvoidrotateImage()Rotate image based on ship headingvoidscreenWrap()Wrap ship around screen if window boundaries are exceededvoidsetInvulnerable()Set invulnerability for two secondsvoidshoot()Creat a bullet that travels in direction ship is currently facingvoidtick()Update player each framedoublex()Returns x coordinatedoubley()Returns y coordinateMethods inherited from class GamePiece
distanceTo, getAnimationImage, getImage, getRotatedImage, isCollidingWith, setAnimationImage, setImage, setRotatedImageMethods 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, updateUIMethods 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, validateTreeMethods 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
-
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 coordinatey- Player y coordinate
-
-
Method Details
-
paintComponent
public void paintComponent(java.awt.Graphics g)Paints component on graphics canvas- Overrides:
paintComponentin classjavax.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 -
screenWrap
public void screenWrap()Wrap ship around screen if window boundaries are exceeded -
move
public void move()Move ship based on momentum vector -
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:
getMaskRadiusin classGamePiece- Returns:
- Collision mask
-
getCenter
public double[] getCenter()Returns double array holding x and y coordinates of ship center -
destroy
public void destroy()Destroys this object, disabling it permanently -
isEnabled
public boolean isEnabled()Returns if this object is in an enabled state- Overrides:
isEnabledin classjava.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
-