top of page
Search
  • jficco2

Assignment 3: A Bouncing Ball




//These will keep track of positions

var xPos;

var yPos;


var xSpeed;

var ySpeed;


var ballsize;


var g;

var r;

var b;


function setup() {

createCanvas(400, 400);


//Setting my initial position

xPos=200;

yPos=200;

xSpeed=5;

ySpeed=5;

g=0;

r=1;

b=2;

}


function draw() {

background(220);

//Conditional

//If the ball touches right hand side of window

if(xPos>400-25){

//Then move ball to the left

//console.log("WE DID IT")

xSpeed=-xSpeed;

g= random(0,255);

r= random(255,0)

}

if(xPos<0 + 25){

xSpeed=-xSpeed

g= random(0,255);

r= random (1,255);

b= random (2,255);

}


//Conditional

if(yPos>400-25){

ySpeed=-ySpeed

g=random(0,255);

r=random(255,0)

}


if(yPos<0 + 25){

g=random(0,255);

r=random(1,255);

b=random(2,255);

}

/*if((xPos > 400) || (xPos < 0)){

xSpeed = -xSpeed;

}*/


/*if (xPos > 400){

xSpeed=-xSpeed

}

else if (xPos < 0){

xSpeed=-xSpeed

}*/


//move the ball

xPos=xPos+xSpeed;

//Drawing my ball

fill (r, g, b)

ellipse(xPos, yPos, 50, 50)

}


3 views0 comments

Recent Posts

See All

Final Project

Completely scratched the Pacman idea and went back to the drawing board since I got so many errors. I decided to go with Doodle Jump. Although it doesn't do everything I want it to such as keep score

Assignment 9: Final Project Brainstorm

I would like to try doing my take on a Pacman type game, some media sources I may use are pictures of the Pacman characters or characters of my own, I haven't seen any examples yet but plan on looking

Midterm

https://editor.p5js.org/jon_ficco/sketches/tf19icH2_ I wanted to add a score board but every time I tried the whole thing wouldn't work for some reason

Post: Blog2_Post
bottom of page