Homework 10.2

So we were assigned to change one part of our midterm code into class, thus giving me to work with my pong code. Big mistake of my life to even start to try. My midterm was on pong, so I have the option to class up either the ball or the paddle. The ball itself have 3 sets of codes; the speed where it starts, what would happen when it hits the paddle, and because it is linked, the computer paddle follows the ball. If I were to class that, it would mainly just end up as more of a mess than I started with.

EDIT: In case the openprocessing thing doesn’t show, as it doesn’t on my screen. The code:

Ball myBall;
int bally = 300;
int ballx = 500;
int speed = 2;
int directx = speed;
int directy = speed;
float randplacing = 300;
float fast = 1.5;
boolean started = false;
PImage wallpaper;

void setup(){
size (1000,600);
myBall = new Ball();
wallpaper= loadImage(“pongLAfinal191.jpg”);
image(wallpaper,1000,600,width,height);
frameRate(100);
}

void draw(){
background(0);
if(started == false){
if(mouseY 600 && mouseX 600){
fast = 1.5;
speed = 2;
started = true;
myBall.display();
}

}

//Ball
bally = bally + directy;
ballx = ballx + directx;
rectMode(CENTER);
rect(ballx, bally, 10,10);
noStroke();
if (ballx == 990 && bally = mouseY-50) {
//Ball Go upward
if (bally mouseY) {
directx = – speed;
directy = + speed;
}
//Ball Stayput
if (bally == mouseY) {
directx = – speed;
directy = 0 ;
}
}

//Player Paddle
rectMode(CENTER);
rect(990, mouseY, 10 , 80);
noStroke();

//ComputerPaddle
rectMode(CENTER);
rect(10, randplacing, 10, 80);
noStroke();
//Make computerpaddle chase after ball
if(randplacing bally){
randplacing = randplacing – fast ;
}

//Computer Paddle Movement
if (ballx == 20 && bally = randplacing – 50){
// Go Up if ball does
if (bally randplacing) {
directx = speed;
directy = + speed;
}
// Stay if it stays
if (bally == randplacing) {
directx = speed;
directy = 0 ;
}

}

//Wallbounces
//Right
if ( bally == 600) {
directy = – speed;
}
//Left
if ( bally == 0) {
directy = speed;
}
//Reset when Right Scored
if (ballx 1000){
ballx = 400;
bally = 300;
}

}
——————————

class Ball{
color c;
int bally;
int ballx;
int speed;

Ball(){
c = color(0);
bally = 300;
ballx = 500;
speed = 2;
}

void display(){
rectMode(CENTER);
fill(c);
rect(ballx,bally,10,10);
}
}

EDIT#2: Here’s a direct link to open processing

http://www.openprocessing.org/sketch/96414

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Homework 10.2

  1. Jack–

    You have some simple errors in here, such as:

    //Reset when Right Scored
    if (ballx 1000){

    … there’s no evaluation there. You should also be doing these evaluations as a function in your ball class.

Leave a Reply

Your email address will not be published. Required fields are marked *