MyXlet

org.homebrew

## Class MyXlet

- java.lang.Object
- - java.awt.Component
  - - java.awt.Container
    - - org.homebrew.MyXlet

- All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, java.util.EventListener, javax.tv.xlet.Xlet, org.dvb.event.UserEventListener

      public class MyXlet
      extends java.awt.Container
      implements javax.tv.xlet.Xlet, java.lang.Runnable, org.dvb.event.UserEventListener

  The main game application. This class is responsible for displaying and updating of all the game entities as well as handling user input.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### 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
    Modifier and Type | Field and Description
    --- | ---
    `private java.awt.Image` | `backbuffer` image for double buffering
    `private ImageEntity` | `background` game background
    `private Sprite` | `bird` player sprite
    `(package private) int` | `BIRDDEATHBOUNDRY` constant for y point to determine if bird has died
    `(package private) int` | `BIRDTOPBOUNDRY` constant for y point to clip bird to top of screen
    `private Sprite[]` | `bottomPipe` bottom pipe sprite
    `private java.awt.Font` | `font` scene font for text display
    `private java.lang.Thread` | `gameloop` thread for the game loop
    `(package private) int` | `GRAVITY` gravity
    `private int` | `MAXPIPESPRITES` max number of pipe sprites
    `(package private) int` | `PIPESTARTINGXVELOCITY` constant for pipe starting speed
    `private org.havi.ui.HScene` | `scene` scene to draw on
    `(package private) int` | `score` players score
    `(package private) int` | `SCREENCENTERX` constant for the x coordinate of the center of the screen
    `(package private) int` | `SCREENCENTERY` constant for the y coordinate of the center of the screen
    `(package private) int` | `SCREENHEIGHT` constant for the screen height
    `(package private) int` | `SCREENWIDTH` constant for the screen width
    `(package private) int` | `state` game state
    `private Sprite[]` | `topPipe` top pipe sprite
    `(package private) int` | `UPFORCEY` constant for bird's max up speed
    `private SoundClip` | `wingFlap` sample for wing flap

    - ### 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 and Description
    `MyXlet()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `birdUpdate()` update the birds position
    `void` | `destroyXlet(boolean unconditional)` returns the memory used by the xlet and terminates the thread used for the game loop
    `void` | `drawPipes(java.awt.Graphics backbuffer)` draws the pipes
    `void` | `gameUpdate()` updates all the game objects
    `void` | `initXlet(javax.tv.xlet.XletContext context)` initializes the xlet, starts the background music, creates the double buffer, initializes all the game objects and sets up the input handlers
    `void` | `paint(java.awt.Graphics g)` draws all the game entities to the back buffer and then the back buffer to the screen
    `void` | `pauseXlet()` hides the scene
    `void` | `pipeUpdate()` update the pipes' positions
    `void` | `run()` main game loop
    `void` | `startXlet()` makes the scene visible, starts the game loop and calls repaint to draw the first frame
    `void` | `userEventReceived(org.dvb.event.UserEvent evt)` listens for key events and handles them

    - ### Methods inherited from class java.awt.Container

      `add, add, add, add, add, addContainerListener, addImpl, addNotify, 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, isValidateRoot, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, 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, getAccessibleContext, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, 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, resize, resize, revalidate, setBackground, 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, transferFocusBackward, transferFocusUpCycle`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### SCREENWIDTH

          final int SCREENWIDTH

      constant for the screen width
      See Also:
        Constant Field Values

    - #### SCREENHEIGHT

          final int SCREENHEIGHT

      constant for the screen height
      See Also:
        Constant Field Values

    - #### SCREENCENTERX

          final int SCREENCENTERX

      constant for the x coordinate of the center of the screen
      See Also:
        Constant Field Values

    - #### SCREENCENTERY

          final int SCREENCENTERY

      constant for the y coordinate of the center of the screen
      See Also:
        Constant Field Values

    - #### UPFORCEY

          final int UPFORCEY

      constant for bird's max up speed
      See Also:
        Constant Field Values

    - #### PIPESTARTINGXVELOCITY

          final int PIPESTARTINGXVELOCITY

      constant for pipe starting speed
      See Also:
        Constant Field Values

    - #### GRAVITY

          final int GRAVITY

      gravity
      See Also:
        Constant Field Values

    - #### BIRDTOPBOUNDRY

          final int BIRDTOPBOUNDRY

      constant for y point to clip bird to top of screen
      See Also:
        Constant Field Values

    - #### BIRDDEATHBOUNDRY

          final int BIRDDEATHBOUNDRY

      constant for y point to determine if bird has died
      See Also:
        Constant Field Values

    - #### MAXPIPESPRITES

          private final int MAXPIPESPRITES

      max number of pipe sprites
      See Also:
        Constant Field Values

    - #### scene

          private org.havi.ui.HScene scene

      scene to draw on

    - #### font

          private java.awt.Font font

      scene font for text display

    - #### gameloop

          private java.lang.Thread gameloop

      thread for the game loop

    - #### backbuffer

          private java.awt.Image backbuffer

      image for double buffering

    - #### state

          int state

      game state

    - #### score

          int score

      players score

    - #### background

          private ImageEntity background

      game background

    - #### bird

          private Sprite bird

      player sprite

    - #### topPipe

          private Sprite[] topPipe

      top pipe sprite

    - #### bottomPipe

          private Sprite[] bottomPipe

      bottom pipe sprite

    - #### wingFlap

          private SoundClip wingFlap

      sample for wing flap

  - ### Constructor Detail

    - #### MyXlet

          public MyXlet()

  - ### Method Detail

    - #### initXlet

          public void initXlet(javax.tv.xlet.XletContext context)

      initializes the xlet, starts the background music, creates the double buffer, initializes all the game objects and sets up the input handlers
      Specified by:
        `initXlet` in interface `javax.tv.xlet.Xlet`
      Parameters:
        `context` - xlet context

    - #### startXlet

          public void startXlet()

      makes the scene visible, starts the game loop and calls repaint to draw the first frame
      Specified by:
        `startXlet` in interface `javax.tv.xlet.Xlet`

    - #### pauseXlet

          public void pauseXlet()

      hides the scene
      Specified by:
        `pauseXlet` in interface `javax.tv.xlet.Xlet`

    - #### destroyXlet

          public void destroyXlet(boolean unconditional)

      returns the memory used by the xlet and terminates the thread used for the game loop
      Specified by:
        `destroyXlet` in interface `javax.tv.xlet.Xlet`
      Parameters:
        `unconditional` - terminate conditionally if true, otherwise false

    - #### run

          public void run()

      main game loop
      Specified by:
        `run` in interface `java.lang.Runnable`

    - #### gameUpdate

          public void gameUpdate()

      updates all the game objects

    - #### pipeUpdate

          public void pipeUpdate()

      update the pipes' positions

    - #### birdUpdate

          public void birdUpdate()

      update the birds position

    - #### paint

          public void paint(java.awt.Graphics g)

      draws all the game entities to the back buffer and then the back buffer to the screen
      Overrides:
        `paint` in class `java.awt.Container`
      Parameters:
        `g` - graphics context to use for drawing

    - #### drawPipes

          public void drawPipes(java.awt.Graphics backbuffer)

      draws the pipes
      Parameters:
        `backbuffer` - backbuffer image

    - #### userEventReceived

          public void userEventReceived(org.dvb.event.UserEvent evt)

      listens for key events and handles them
      Specified by:
        `userEventReceived` in interface `org.dvb.event.UserEventListener`
      Parameters:
        `evt` - key event