Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

There is a problem with my paddle move functions

$
0
0

the paddle wont move/

``/* Name: Brandon Mckenna Program Name: Pong / import ddf.minim.; AudioPlayer player; Minim minim;//audio context

//COLOURS int Black = #000000; int White = #FFFFFF;

//SCREEN VARIABLES final int titleScreen = 0; final int instructionScreen = 1; final int game = 2; final int gameOver = 3; int screen;

//BALL VARIABLES int x = 450; int y = 239; int speedX, speedY;

//SCORE INTS int playerAScore = 0; int playerBScore = 0;

//PADDLE INTS int RPY = 210; int RPX = 45; int LPY = 210; int LPX = 825; int PaddleSpeedY;

void setup() {

size(900, 500); smooth();

screen = 0;

speedX = 0;
speedY = 0;

PaddleSpeedY = 0;

RPY = RPY + PaddleSpeedY; LPY = LPY + PaddleSpeedY;

RPY = 210; RPX = 45; LPY = 210; LPX = 825;

//PONG MUSIC minim = new Minim(this); player = minim.loadFile("PongMusic.mp3", 2048); player.play(); }

void draw() {

switch(screen) {

case titleScreen: titleScreen(); break;

case instructionScreen: titleScreen(); break;

case game: gameScreen(); break;

case gameOver: gameOver(); break; } }

void titleScreen() { displayTitleScreen(); }

void instructionScreen() { displayRules(); }

void gameScreen() { displayRules(); displayGameArea(); displayScore(); rightPaddle(); leftPaddle(); moveRightPaddle(); moveLeftPaddle(); ballMove(); }

void gameOver() { displayGameOver(); }

//======================================================== ////////////////////////////////////////////////////////== ////////////////////////////////////////////////////////== ////////////////////////////////////////////////////////== // == // // FUNCTIONS START BELOW // == // == ////////////////////////////////////////////////////////== ////////////////////////////////////////////////////////== ////////////////////////////////////////////////////////== //========================================================

void displayTitleScreen() {

background(0); textAlign(CENTER, TOP); textSize(20);

fill(White);

rect(245, 355, 200, 60);// "Play" Rectangle rect(450, 355, 200, 60);// "How To Play" Rectangle

fill(Black);

textFont(loadFont("GoodTimes-48.vlw"));

textSize(20);

text("Click To Play", 345, 375); text("How To Play", 555, 375);

fill(White);

textSize(62); text(" PONG", 450, 100);

if (mousePressed == true) { if ((mouseX > 245)&&(mouseX < 445)) if ((mouseY > 355)&&(mouseY < 415)) screen = 2; } if (mousePressed == true) { if ((mouseX > 450)&&(mouseX < 650)) if ((mouseY > 355)&&(mouseY < 415)) screen = 1; } }

void displayRules() {

background(0); text("How To Play", 450, 250); } void displayGameArea() {

background(Black); stroke(White); strokeWeight(8);

line(35, 50, 35, 450); line(35, 50, 850, 50); line(850, 50, 850, 450); line(850, 450, 35, 450);

// line(450, 50, 450, 450); }

void displayScore() {

fill(White); textFont(loadFont("Degrassi-48.vlw")); text("Score:", 455, 6); text(playerAScore, 288, 6); text(playerBScore, 613, 6); noStroke(); noFill(); }

void rightPaddle() {

fill(White); rect(RPX, RPY, 15, 60); }

void leftPaddle() {

fill(White); rect(LPX, LPY, 15, 60); } void moveRightPaddle() { if (keyPressed == true) if (key == 'w') { PaddleSpeedY = -2; } else if (key =='s') {
PaddleSpeedY = 2; } } void moveLeftPaddle() {

if (key == UP) { PaddleSpeedY = -2; } else if (key == DOWN) {
PaddleSpeedY = 2; } } void ballMove() {

ellipse(x, y, 12, 12);

/* IF BALL ITS TOP OR BOTTOM CHANGED DIRECTION if ( y > height || y < 0 ) { speedY = speedY * -1; y = y + speedY; } */ }

void displayGameOver() {

background(0); textAlign(CENTER, TOP); textSize(20); text("Click To Return To TitleScreen", 350, 300);

textSize(72); text(" Game Over", 450, 100);

rect(335, 400, 227, 60);

if (mousePressed == true) { if ((mouseX > 0)&&(mouseX < 900)) if ((mouseY > 0)&&(mouseY < 500)) screen = 1; } }

void stop() { player.close(); minim.stop(); super.stop(); }

void keyPressed() { moveRightPaddle(); moveLeftPaddle(); }

void mousePressed() { print("x: " + mouseX + " y: "+ mouseY +"\n"); } ``


Viewing all articles
Browse latest Browse all 2896

Trending Articles