title: Brick Breaker help. circles, paddles, and awkward bouncing
body: <p>I've written a simple brick breaker game in OpenGL. The ball is a 2D circle drawn using :</p>
  
  <pre><code>for (float angle = 0; angle &lt; (10); angle+=0.01)
   {
       glVertex2f((x_pos + sin(angle) * RADIUS), (y_pos + (cos(angle)) * RADIUS));
   }
  </code></pre>
  
  <p>This causes distortion when the game is changed to fullscreen. RADIUS is defined as 0.025 .
  I need help in making the paddle movements smooth as well.
  Also, if you play the game a couple of times, you'll notice that towards the extreme left, when the ball hits the paddle, it rises to a certain height and then bounces back down.
  Full code:</p>
  
  <pre><code>#include &lt;GL/openglut.h&gt;
  #include &lt;stdarg.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;cmath&gt;
  #define RADIUS 0.025
  #define SPEED  0.001
  int WIDTH = 900;
  int HEIGHT =  650;
  int RATIO = WIDTH/HEIGHT;
  bool show[5][10];
  float x_brick[4][9];
  float y_brick[4][9];
  float P_XPOS = 0;
  float P_YPOS = -0.8;
  bool phit_center = false , phit_corner = false;
  bool game_over = false;
  bool RIGHT = 1,LEFT = 0,UP = 1,DOWN = 0;
  bool started = false;
  float x_pos = 0,y_pos = -0.75;
  bool hit = false;
  int lives  = 3;
  using namespace std;
  void b_draw()
  {
        glColor3f(1.0,0.0,0.0);
        glBegin(GL_QUADS);
        for(int a = 0; a &lt; 9; a++)
        {
                for(int b = 0; b &lt; 4; b++)
                {
                        if(show[b][a] == 1)
                        {
                                      glVertex2f(x_brick[b][a],y_brick[b][a]);
                                      glVertex2f(x_brick[b][a],y_brick[b][a] - 0.10); 
                                      glVertex2f(x_brick[b][a]+0.2,y_brick[b][a] - 0.10);
                                      glVertex2f(x_brick[b][a]+0.2,y_brick[b][a]);  
                        }
                }
        }
        glEnd();
  }
  void c_draw()
  {
       glColor3f(0.0,0.0,0.0);
       glBegin(GL_TRIANGLE_FAN);
       glVertex2f(x_pos,y_pos);
       for (float angle = 0; angle &lt; (10); angle+=0.01)
       {
           glVertex2f((x_pos + sin(angle) * RADIUS), (y_pos + (cos(angle)) * RADIUS));
       }
       glEnd();
  }
  bool b_hit()
  {
       hit = false;
       int flag = 1;
       for(int a = 0; a &lt; 10; a++)
       {
               for(int b =0; b &lt; 4; b++)
               {
                       if(x_pos &gt;= x_brick[b][a] &amp;&amp; x_pos &lt;= x_brick[b][a] + 0.2)
                       {
                                if(y_pos &lt;= y_brick[b][a] &amp;&amp; y_pos &gt;= y_brick[b][a] - 0.1)
                                {
                                         if(show[b][a] == 1)
                                         {
                                                       show[b][a] = 0;
                                                       flag = 0;
                                                       hit = true;
                                                       break;
                                         }
                                }
                       }
               }
               if(flag == 0)
                       break;
       }
       return hit;
  }
  bool crashed()
  {
       if(y_pos &lt; P_YPOS - 0.05)
                return true;
       else return false;;
  }
  void p_hit()
  {
       phit_corner = false;
       phit_center = false;
       if(x_pos &lt;= P_XPOS + 0.13 &amp;&amp; x_pos &gt;= P_XPOS - 0.13)
       {
                if(y_pos &lt;= P_YPOS)
                {
                         phit_center = true;
                }
       }
       else if((x_pos &gt;= P_XPOS + 0.13 &amp;&amp; x_pos &lt;= P_XPOS + 0.2) || (x_pos &lt;= P_XPOS - 0.13 &amp;&amp; x_pos &gt;= P_XPOS - 0.2))
       {
                 if(y_pos &lt;= P_YPOS)
                 {
                          phit_corner = true;
                 }
       }
  }
   void c_move()
   {
        if(UP &amp;&amp; RIGHT)
        {
             x_pos += (SPEED);
             y_pos += (SPEED);       
        }
        if(UP &amp;&amp; LEFT)
        {
              x_pos -= (SPEED);
              y_pos += (SPEED);
        }
        if(DOWN &amp;&amp; RIGHT)
        {
                x_pos += (SPEED);
                y_pos -= (SPEED);
        }
        if(DOWN &amp;&amp; LEFT)
        {
                x_pos -= (SPEED);
                y_pos -= (SPEED);
        }
        b_hit();
        if(x_pos &gt;= (RATIO-RADIUS))
        {
                 RIGHT = 0;
                 LEFT = 1;
        }
        else if(x_pos &lt;= (-RATIO+RADIUS))
        {
             RIGHT = 1;
             LEFT = 0;
        }
        if(y_pos &gt;= (RATIO-RADIUS) || hit )
        {
                    UP = 0;
                    DOWN = 1;
        }
        else if(y_pos &lt;= (-RATIO+RADIUS) || hit )
        {
             UP = 1;
             DOWN = 0;
        }
        p_hit();
        if(phit_center)
        {
                       DOWN = 0;
                       UP = 1;
        }
        if(phit_corner)
        {
                       if(LEFT)
                       {
                               LEFT = 0;
                               RIGHT = 1;
                       }
                       else
                       {
                           RIGHT = 0;
                           LEFT = 1;
                       }
                       UP = 1;
                       DOWN = 0;
        }
  }
  void p_draw()
  {
       glColor3f(0.0,0.0,0.0);
       glBegin(GL_QUADS);
                        glVertex2f(P_XPOS-0.2,P_YPOS);
                        glVertex2f(P_XPOS+0.2,P_YPOS);
                        glVertex2f(P_XPOS+0.2,P_YPOS-0.05);
                        glVertex2f(P_XPOS-0.2,P_YPOS-0.05);
       glEnd();
  }
  
  void BallLoop()
  {
       glClearColor(1.0,1.0,1.0,0);
       glDisable(GL_DEPTH_TEST);
       glClear(GL_COLOR_BUFFER_BIT);
       glMatrixMode (GL_MODELVIEW);
       glLoadIdentity();
       c_draw();
       b_draw();
       p_draw();
       glFlush();
       if(started)
                  c_move();
       if(crashed())
       {           
                   x_pos = 0;
                   y_pos = -0.7;
                   started = 0;
                   UP = 1;
                   RIGHT = 1;
                   DOWN = 0;
                   LEFT = 0;
       }
  
       glutSwapBuffers();
       glutPostRedisplay();
  }
  void user_input(unsigned char key, int x, int y)
  {
       if(key == 13)
       started = true;
  }
  void ArrowKeys(int key, int x, int y)
  {
       if(key==GLUT_KEY_LEFT &amp;&amp; P_XPOS &gt;= -0.8)
        for(float a = 0; a &lt; 0.05; a+= 0.001)
        {
                                        P_XPOS -=0.003;
                                        BallLoop();
        }
       if(key==GLUT_KEY_RIGHT &amp;&amp; P_XPOS &lt;= 0.8)
       {
                              for(float a = 0; a &lt; 0.05; a+= 0.001)
                              {
                                        P_XPOS +=0.003;
                                        BallLoop();
                              }
       }
  }
  void set_xy()
  {
      for(int a = 0; a &lt; 5; a++)
      {
              for(int b = 0; b &lt; 10; b++)
              {
                      show[a][b] = 1;
              }
      }
      int c = 0;
      for(float a = -0.94; c &lt;= 8; a+=0.21)
      {         
  
                for(int b = 0; b &lt;= 5; b++)
                {
                        x_brick[b][c] = a;
  
                }
                c++;
      }
      int d = 0;
      for(float s = 0.99; d &lt;= 3; s-=0.11)
      {
                for(int  r = 0; r &lt; 9; r++)
                {
                         y_brick[d][r] = s;
                }
                d++;
      }
  }
  void changeSize(int w, int h) 
  {
  
      if(h == 0)
          h = 1;
      RATIO = w/h;
      float ratio = 1.0* w / h;
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glViewport(0, 0, w, h);
      glMatrixMode(GL_MODELVIEW);
      BallLoop();
  }
  int main(int argc, char **argv)
  {
      set_xy();
      glutInit(&amp;argc, argv);
      glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
      glutInitWindowPosition(0,0);
      glutInitWindowSize(WIDTH,HEIGHT);                    
      glutCreateWindow("Brick Breaker - By Viraj");
      glutReshapeFunc(changeSize);
      glutDisplayFunc(BallLoop);
      glutKeyboardFunc(user_input);
      glutSpecialFunc(ArrowKeys);
      glutMainLoop(); 
      return 0;
  }
  </code></pre>