java - stanford cs106a Bouncing Ball code questions -


I am a new learner of public sources of Stanford CS 106A

checkForCollision is the method code for the bottom of this page, when I was given the reading bouncing ball, then I \ To do code ball.move (0, -2 * diff) , especially execute -2 * diff , I can not understand this math code. Is it OK for the ball ball.move (0, -diff) ? What is the difference? What is the bounce argument? Anyone here can help me understand this code, I am not good at mathematics Thank you very much

  / * * File: Bouncingball.Java * -------- ------------------ * This program graphically a bouncing ball * / import acm.program. *; Import acm.graphics *; Public class rant ball extends the graphics program {/ ** ball size (diameter) * / personal fixed end-end DIAM_BALL = 30; / ** quantity Y velocity gravity * / personal constant final dual = 3 each cycle increases as the result; / ** Animation delay or break time between call moves * / personal fixed final interval = 50; / ** Initial X and Y position of the ball * / personal static last double X_START = DIAM_BALL; Private Stable Last Double Y_START = 100; / ** x velocity * / personal static last double X_VEL = 5; / ** Zodiac velocity decreases when * / personal static last double BOUNCE_REDUCE = 0.9; / ** start x and y velocity * / personal double excel = X_VEL; Private Double-Val = 0.0; / * Personal example variable * / private ball ball; Public run zero () {Setup (); // Simulation ends when the ball emerges from the right hand / while at the end of the screen (ball .getX ()  getHeight () - DIAM_BALL) {// Ball Y's velocity now bounce upwards. yVel = -YVEL * BOUNCE_REDUCE; // Assume that the bounce will bring the ball above one amount from the top / the amount equal to that floor which will pull it out of the double gap = the ball below the floor. () - (getHeight () - DIAM_BALL); Ball.move (0, -2 * diff); }}}}    

when called ball.move The ball has moved forward from the surface which it bounces, then -def will take it back to the surface, it bounces by -2 * diff .

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -