top of page
Search

homework update.

  • Writer: Kevin Menelas
    Kevin Menelas
  • Nov 7, 2019
  • 1 min read

I seriously cannot get my version of pong to work right. I can't get the CPU paddle to bounce off the top of the screen or the ball to pounce off the paddles. For some reason the Player paddle only works when it wants to and I don't know why because I never changed. the code for it. Here is the code itself:



var paddle1X;

var paddle1Y;

var paddle2X;

var paddle2Y;

//ball variable

var ballSize

var ballY

var ballX

var ypaddleSpeed

var xpaddleSpeed

var xSpeed

var ySpeed

var ballSize

var ballX

var ballY

var paddleSize


function setup() {

// put setup code here\

createCanvas(1250, 620);

paddle1X = 100;

paddle1Y = 100;

paddle2X = 1150

paddle2Y = 100

ballSize = 100

ballX = 625

ballY = 100

xSpeed = 5;

ySpeed = -2;

paddleSize = 600

paddle2Y = 4

xpaddleSpeed = 0

ypaddleSpeed = 4

}


function draw() {

background(50);

fill( 240, 0, 150);

rect(paddle1X, paddle1Y, 10, 400);

fill(0, 150, 250);

rect(paddle2X, paddle2Y, 10, 400);

fill(255, 228, 0)

ellipse(ballX, ballY, ballSize, ballSize)


ballX += xSpeed;

ballY += ySpeed;

paddle2Y += ypaddleSpeed

paddle2X += xpaddleSpeed


if (paddle2Y > paddleSize/2){

ypaddleSpeed = - ypaddleSpeed;


if (paddle2Y < paddleSize/2){

ypaddleSpeed = - ypaddleSpeed;

}


if (ballY < ballSize/2){

ySpeed = - ySpeed;

}

if (ballY > ballSize/2){

ySpeed = + ySpeed;

}


if ((ballY > (100-ballSize/2)) && (ballX > (paddle1X - paddleSize/2)) &&

(ballX < (paddle1X+paddleSize/2))){

ySpeed = -ySpeed;


if ((ballY > (1150-ballSize/2)) && (ballX > (paddle2X - paddleSize/2)) &&

(ballX < (paddle2X+paddleSize/2))){

ySpeed = -ySpeed;


function keyPressed(){

if (keyCode === UP_ARROW){

paddle1Y -= 10;

}

else if(keyCode === DOWN_ARROW){

paddle1Y += 10;

}

}

}

}

}

}

 
 
 

Recent Posts

See All
PROJECT (FINAL)

This project had many trials and tribulations. It started out as simple game of pong but that did not turn out as planned. So instead I...

 
 
 
Midterm Update

My project is truly and finally done. It was a long road of frustration to get here. My original plan was to to make the game. That was...

 
 
 
Midterm project.

I’ve decided to do a game called gold miner. It on the microbit suggestions. It’s a game where you play as a little bar that has to...

 
 
 

コメント


© 2023 by Name of Site. Proudly created with Wix.com

bottom of page