Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7496291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:33:20+00:00 2026-05-29T18:33:20+00:00

I’m working on a Pong game for my portfolio right now in Java, and

  • 0

I’m working on a Pong game for my portfolio right now in Java, and I’m just having a slight problem with the Pong paddle movement. Obviously, I don’t want the paddles moving off-screen, so I’m trying to make it so when it reaches a certain point on its Y-axis, it will not move any farther. I’ve gotten it to work for the top of the screen, but not the bottom, and I can’t figure out why. The conditional I’m using SHOULD work, but it will just move right off the bottom of the screen if I go far enough. Here’s the conditionals for each paddle’s movement. If you need more of my code, just ask.

// Check for Left Paddle movement.
if( ( wKey ) && ( paddle_left.getY() >= ( paddle_speed * 2 ) ) )
    paddle_left.setY( paddle_left.getY() - paddle_speed ); 
else if( ( sKey ) && ( paddle_left.getY() <= ( boardHeight - 10 ) ) )
    paddle_left.setY( paddle_left.getY() + paddle_speed );

// Check for Right Paddle movement
if( ( upKey ) && ( paddle_right.getY() >= ( paddle_speed * 2 ) ) )
    paddle_right.setY( paddle_right.getY() - paddle_speed );
else if( ( downKey ) && ( paddle_right.getY() <= ( boardHeight - 10 ) ) )
    paddle_right.setY( paddle_right.getY() + paddle_speed );

The variable paddle_speed is a constant equal to 5. Also, boardHeight is the height of the screen on which everything is drawn, which is equal to 480.

Also, this isn’t as important, but I’ve noticed a slight delay from when I start to hold down the key to when the paddle starts moving. I know it’s because of the initial key press delay set on the user’s computer, but how can I compensate for this?

EDIT:
Ok, I changed my code to reflect your answer and I’ve got this now:

// Check for Left Paddle movement.
if( ( wKey ) && ( paddle_left.getY() >= ( paddle_speed * 2 ) ) ) paddle_left.setY( paddle_left.getY() - paddle_speed );
else if( ( sKey ) && ( paddle_left.getY() <= ( boardHeight - ((paddle_speed * 2) + paddleHeight) ) ) ) paddle_left.setY( paddle_left.getY() + paddle_speed );

// Check for Right Paddle movement.
if( ( upKey ) && ( paddle_right.getY() >= ( paddle_speed * 2 ) ) ) paddle_right.setY( paddle_right.getY() - paddle_speed );
else if( ( downKey ) && ( paddle_right.getY() <= ( boardHeight - ((paddle_speed * 2) + paddleHeight) ) ) ) paddle_right.setY( paddle_right.getY() + paddle_speed );

However, it still goes a little below screen. It does stop now, but it goes maybe 20 pixels beyond the screen still. I don’t get it. I even used Paint and drew the coordinates and simulated how the logic should work, and it should stop 5 pixels from the edge of the bottom of the screen. Can you figure out why it’s not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:33:26+00:00Added an answer on May 29, 2026 at 6:33 pm

    It’s probably because you don’t take the size of your paddle into account when checking for the bottom of the screen. So if your paddle is bigger than your speed size (5) then it will be draw below the bottom of the screen.

    For the key repeat delay problem you will probably have to keep flags for which keys are down. Set the flags on keyPressed() events and clear it on keyReleased() and then update the paddles using a timer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.