// Stuff that bounces // Variables & Basic Ifs //A float is a decimal, just makes the movement of the block smoother float x, y; float sx, sy; void setup() { size(500, 500); x = 250; //Start position for the block y = 250; sx = 0; //Start speed of the block sy = 0; } void draw() { fill(0, 0, 0); rect(0, 0, width, height); //The background fill(255, 0, 0); //The color of the block rect(x, y, 30, 30); //Draw the block that blounces sx = sx + 0.1; //Provides the acceleration to change the speed x = x + sx; //Makes the position change based on the speed //Right bounce and position correction if (x > width - 30) { sx = sx * (-0.9); //Bounce!, I picked 0.9 so it would lose a bit of its speed each bounce x = width - 30; //This keeps it from getting "stuck" in the edge of the screen } //Left bounce and position correction if (x < 0) { sx = sx * (-0.9); //Exactly the same deal as above x = 0; //Also, keeps it from getting "stuck" by moving it off the wall a bit } //I leave the copy and paste of the X coordinate stuff to make the Y coordinate stuff //up to you. Its like some kind of work at home }