CSCI 107 Solitaire Pong

Don’t get frustrated. We’ll do something more reasonable next week.


Copying your stuff

I’m not sure if your files are being saved this term. Try copying them over to Google Drive for next class.

Figuring out the look

Don’t start by trying to program the game. Just figure out what you want you want your game board to look like. Mine looks something like the following:
game board

Here’s a big start for your program. I’m giving you this so you will get into the habit of using variables, such as paddleColor, rather than “magic” constants, such as #DBC3A3.

color boardColor = #49311C ;

color ballColor = #DDDDDD ;
float ballXPos ;
float ballYPos ;
float ballWidth = 100 ;
float ballXSpeed = 2.5 ;
float ballYSpeed = 1.5 ;

color paddleColor = #DBC3A3 ;
float paddleXPos ;
float paddleYPos ;
float paddleHeight = 200 ;
float paddleWidth = 50 ;

void setup() {
  size(900, 800);
  noStroke() ;
  paddleXPos = width-100 ;
  paddleYPos = (height-paddleHeight)/2 ;
  ballXPos = 200 ;
  ballYPos = height/2 ;

void draw() {
  background(boardColor) ;
  // Draw the paddle and the ball

At a minimum, add the code to draw the paddle and ball and change the colors. You can use the HTML Color Picker to find garish colors.

Processing references

Always take a look at the Processing references. Notice the difference between rect() and ellipse(). One uses the center and the other uses the corner.

Moving the paddle

If you modify your program to change the value of paddleYPos, the paddle will move. Here are two possibilities for doing this.

Struggle your own for a few minutes before consulting with a guru. By the way, you can use both the mouse and the arrow keys to control the paddle.

Processing references

Bouncing off the left and right walls

Try to move the ball horizontally by changing ballXPos inside the draw() method. This is similar to what we did last week and pretty hard. Solve this part in steps. Use ballXSpeed to control how fast the ball moves.

OK. Here are two big hints.

Processing references

Bouncing off all walls

If you copy your code for moving the ball left and right and change the X’s within the variable names to Y’s, you are very close to having the ball bounce off all four edges.