Here is my code. Trying to make a ball bounce down stairs
//code inspired by real class notes
float x = 100; // class code
float y = 200;// class code
float moveX = 5.0;
float moveY = 0.0; //what would happen if y is > 1
float h;
float w;
float gravity = .05; // class
float damping = .77; // class
float friction = .05; // class
void setup () {
size(1000, 1000);
// why is init like this? cause you are calling the function init dumbass
init(x, y, moveX, moveY, w, h);
ball();
}
//what is void draw()
void draw () {
//makes a white background
background(255);
//what does bounce do?
bounce();
//what does collide do?
dontHitWall(); // taken from class code
//would stairs work in here? what if I put a loop before stairs
for (int i=0; i<10; i++) {
//or do you put Stairs(); in between the brackets?
}
stairs();
}
void ball () {
fill(255,0,0);
ellipseMode(CORNER);
ellipse(width/10, 0, width/80, height/80);
}
void stairs (int x = 100, float w = width/10, float h = height/10) {
fill(0);
rectMode(CORNER);
rect(x, x, w, h);
translate(w, h);
}
void bounce() {
x += moveX;
moveY += gravity;
y += moveY;
display();
}
//inspired by class code
void dontHitWall(){
if(x > width-w/2){
moveX *= -.5;
}
if(x < w/2){
spdX *= -.5;
}
if(y > height-h/2){
y = height-h/2;
moveY *= -1;
moveY *= damping;
moveX *= friction;
}
if(y < h/2){
moveY *= -1;
}
}
1