I can't make the jumping smooth, any ideas? This is object for jumping. since it's not going to fit.

edited July 2015 in Questions about Code
        class Players {
          float x = 0;
          float y = 0;
          float px = 100;
          float py = 20;
          float g = 0.1; // Gravity
          float s = 0; // Speed
          float speed = 9;
          float s1 = 1; // Acceleration
          boolean jumping = false;
          boolean can_jump = false;

          Players(float _x, float _y) {
            x = _x;
            y = _y;
          }

          void simulate() {
            if (jumping) {
              can_jump = false;
              py-=2;
              if (py<height-50) {
                jumping = false;
              }
            }
            if (py<height-20) {
              if (!jumping) {
                py+=2;
              }
            } else {
              can_jump = true;
            }
          }

          void display() {
            fill(255, 0, 0);
            noStroke();
            arc(x, y, 100, 100, -PI, 0);
            arc(x, y, 100, 10, -PI, 0);
          }

          void display2() {
            fill(0, 255, 0);
            noStroke();
            arc(x, y, 100, 100, -PI, 0);
            arc(x, y, 100, 10, -PI, 0);
          }

          /**void gravityPlayer() {
           y = y + s*2; // Assigning y to itself plus the speed
           s = s + g*2; // Assigning speed to itself plus the gravity
           }*/

          void moveP1Left() {
            // Move Left
            if (keyCode == LEFT) {
              x = x - 3;
            }
          }

          void moveP1Right() {
            // Move Left
            if (keyCode == RIGHT) {
              x     = x + 2;
                }
              }

              void moveP1Jump() {
                // Jump
                //gravityPlayer();
                /**if (y >= height - 13) {
                 y = height - 13;
                 println(y);
                 }*/
              }

              void run() {
                display();
              }

              void run2() {
                display2();
              }
            }
Tagged:
This discussion has been closed.