Playing some Pong!
Getting the project ready.
- Make a new Eclipse Project
- Download pong
- Import pongai.jar
- When importing pongai.jar it will ask if you if you want to overwrite a couple of files, just click yes or yes to all
Make some modifications!
- How can we change the text in the game to say something other than Pong?
-
- How can we make the ball a different size?
- How can we make the ball go faster or slower? [Hint: look in ProjectileTracker.java]
- How can we make the ball simulate gravity?
- How can we make the paddles rectangles instead of circles?
- How can we add another ball?
- Only one ball makes the game change colors when it hits the title, how do we make the other one do it?
- Make a sound when a ball hits a paddle?
- Make the ball our own custom sprite?
Adding some AI:
Find in the code where there is the line "// Computer AI code goes here!"
The following should go right below that line.
Step 1:
paddles[ 1 ].setLocation( paddles[ 1 ].getLocation( ).x, ball.getLocation( ).y ) ;
Step 2 (get rid of the line above and put the below in its place):
double speed = .015 ;
if( Math.abs( paddles[ 1 ].getLocation( ).y - ball.getLocation( ).y ) > speed )
{
if( paddles[ 1 ].getLocation( ).x > ball.getLocation( ).x )
{
if( paddles[ 1 ].getLocation( ).y < ball.getLocation( ).y )
{
paddles[ 1 ].translate( 0, speed ) ;
}
else
{
paddles[ 1 ].translate( 0, -speed ) ;
}
}
else
{
if( paddles[ 1 ].getLocation( ).y < ball.getLocation( ).y )
{
paddles[ 1 ].translate( 0, -speed ) ;
}
else
{
paddles[ 1 ].translate( 0, speed ) ;
}
}
}