Example #1
0
  /**
   * Touching is the method of movement. Touching the touchscreen, that is. A player can join in
   * simply by touching where they would in a normal game.
   */
  public boolean onTouch(View v, MotionEvent mo) {
    if (v != this || !gameRunning()) return false;

    // We want to support multiple touch and single touch
    InputHandler handle = InputHandler.getInstance();

    // Loop through all the pointers that we detected and
    // process them as normal touch events.
    for (int i = 0; i < handle.getTouchCount(mo); i++) {
      int tx = (int) handle.getX(mo, i);
      int ty = (int) handle.getY(mo, i);

      // Bottom paddle moves when we are playing in one or two player mode and the touch
      // was in the lower quartile of the screen.
      if (mBlue.player && mBlue.inTouchbox(tx, ty)) {
        mBlue.destination = tx;
        mGreen.destination = tx;
        mCyan.destination = tx;
      } else if (mRed.player && mRed.inTouchbox(tx, ty)) {
        mRed.destination = tx;
        mYellow.destination = tx;
        mOrange.destination = tx;
      } else if (mo.getAction() == MotionEvent.ACTION_DOWN && mPauseTouchBox.contains(tx, ty)) {
        if (mCurrentState != State.Stopped) {
          mLastState = mCurrentState;
          mCurrentState = State.Stopped;
        } else {
          mCurrentState = mLastState;
          mLastState = State.Stopped;
        }
      }

      // In case a player wants to join in...
      if (mo.getAction() == MotionEvent.ACTION_DOWN) {
        if (!mBlue.player && mBlue.inTouchbox(tx, ty)) {
          mBlue.player = true;
        } else if (!mRed.player && mRed.inTouchbox(tx, ty)) {
          mRed.player = true;
        }
      }
    }

    return true;
  }
Example #2
0
  private void initializePaddles() {
    // Order from top to bottom; Red, Green, Orange, Cyan, Yellow, Blue

    Rect redTouch = new Rect(0, 0, getWidth(), getHeight() / 8);
    Rect blueTouch = new Rect(0, 7 * getHeight() / 8, getWidth(), getHeight());
    Rect greenTouch = new Rect(0, 4 * getHeight() / 16, getWidth(), (getHeight() / 16) * 5);
    Rect orangeTouch = new Rect(0, 6 * getHeight() / 16, getWidth(), (getHeight() / 16) * 7);
    Rect yellowTouch = new Rect(0, 11 * getHeight() / 16, getWidth(), (getHeight() / 4) * 3);
    Rect cyanTouch = new Rect(0, 9 * getHeight() / 16, getWidth(), (getHeight() / 16) * 10);

    mRed = new Paddle(Color.RED, redTouch.bottom + PADDING);
    mBlue = new Paddle(Color.BLUE, blueTouch.top - PADDING - Paddle.PADDLE_THICKNESS);
    mGreen = new Paddle(Color.GREEN, greenTouch.centerY() + PADDING);
    mYellow = new Paddle(Color.YELLOW, yellowTouch.centerY() + PADDING);
    mOrange = new Paddle(Color.rgb(255, 128, 0), orangeTouch.centerY() + PADDING);
    mCyan = new Paddle(Color.rgb(0, 255, 255), cyanTouch.centerY() + PADDING);

    mRed.setTouchbox(redTouch);
    mBlue.setTouchbox(blueTouch);
    mGreen.setTouchbox(greenTouch);
    mYellow.setTouchbox(yellowTouch);
    mOrange.setTouchbox(orangeTouch);
    mCyan.setTouchbox(cyanTouch);

    mRed.setHandicap(mCpuHandicap);
    mBlue.setHandicap(mCpuHandicap);
    mGreen.setHandicap(mCpuHandicap);
    mYellow.setHandicap(mCpuHandicap);
    mOrange.setHandicap(mCpuHandicap);
    mCyan.setHandicap(mCpuHandicap);

    mRed.player = mRedPlayer;
    mBlue.player = mBluePlayer;

    mRed.setSlave(mOrange);
    mBlue.setSlave(mCyan);
    mOrange.setSlave(mYellow);
    mCyan.setSlave(mGreen);

    mRed.setLives(STARTING_LIVES + mLivesModifier);
    mBlue.setLives(STARTING_LIVES + mLivesModifier);
  }
Example #3
0
  @Override
  public boolean onTrackballEvent(MotionEvent event) {
    if (!gameRunning()) return false;

    if (mBlue.player == false) {
      mBlue.player = true;
      mBlue.destination = mBlue.centerX();
    }

    switch (event.getAction()) {
      case MotionEvent.ACTION_MOVE:
        mBlue.destination =
            (int)
                Math.max(
                    0, Math.min(getWidth(), mBlue.destination + SCROLL_SENSITIVITY * event.getX()));
        break;
    }

    return true;
  }