c# - Why the ball did not bounce off on the edge of the right -


the ball bounced off halfway on right. however, wanted bounce off edge on right. may know how do right? codes have below.

public partial class startgame : form {     int x; //the x axis upper left corner     int y; //the y axis upper left corner      int spdx; //the change of x     int spdy; //the change of y      public startgame()     {         initializecomponent();     }      private void startgame_load(object sender, eventargs e)     {         //loads ball on screen @ bottom of window         spdx = 1; //the speed of ball of y         spdy = 1; //the speed of ball of x         x = this.clientsize.width / 5; //the x axis ball loaded @         y = this.clientsize.height - 10; //the y axis ball loaded @     }      private void startgame_paint_1(object sender, painteventargs e)     {         //this inner paint color of circle 10 10         e.graphics.fillellipse(brushes.blue, x, y, 10, 10);         //this outline paint color of circle 10 10         e.graphics.drawellipse(pens.blue, x, y, 10, 10);      }      private void timer1_tick(object sender, eventargs e)     {         y = y + spdy;         x = x + spdx;          if (y < 0)         {             spdy = -spdy; //if y less 0 change direction         }         else if (x < -5)         {             spdx = -spdx;         }         else if (y + 10 > this.clientsize.height)         {             spdy = -spdy; //if y + 10, radius of circle greater form width change direction         }         else if (x + 10 > this.clientsize.height)         {             spdx = -spdx;         }          this.invalidate();      } 

you're incorrectly checking height 'x' movement.

change:

else if (x + 10 > this.clientsize.height) 

to:

else if (x + 10 > this.clientsize.width) 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -