• fullscreen
  • Mr_Happy.pde
  • Platformer.pde
  • animationWalk.pde
  • blink.pde
  • jumping.pde
  • platform.pde
  • class Nubbles {
      
    float v1 = 255;
    float v2 = 255;
    float v3 = 255;
    color charColor = color(v1,v2,v3);  
    
      float rotFoot = 0;
      float rotFoot2 = 0;
    
      float charRot = 0;
      
      Nubbles() {
      }
    
      void Happy() {
    
        translate(moveX,moveY + 100);
        rotate(radians(charRot));
        translate(-80, -100);
        scale(direction,2);
    
        // the stroke
        pushMatrix();
        fill(0);
        stroke(0);
        //right foot
        pushMatrix();
        translate(Xpos + animateFeet1,Ypos + FeetUp1);
        rotate(rotFoot);
        arc(0, 0, 13.5, 13.5, 9.4, 12.55);
        line(-6, 0.5, 6, 0.5);
        popMatrix();
        //right arm
        ellipse(Xpos + animateArm1, Ypos + raiseArm1,8,8);
        //body
        ellipse(Xpos + 20,Ypos + 20,Xsize +1,Ysize +1);
        //left foot
        pushMatrix();
        translate(Xpos + animateFeet2,Ypos + FeetUp2);
        rotate(rotFoot2);
        arc(0,0, 13.5, 13.5, 9.4,12.55);
        line(-6.5, 0.5, 6.5, 0.5);
        popMatrix();
        //left arm
        ellipse(Xpos + animateArm2,Ypos + raiseArm2,8,8);
        popMatrix();
    
        //the body
        noStroke();
        fill(charColor);
        //right foot
        pushMatrix();
        translate(Xpos + animateFeet1,Ypos + FeetUp1);
        rotate(rotFoot);
        arc(0, 0, 13, 13, 9.4, 12.55);
        line(-6, 0, 6, 0);
        popMatrix();
        //the right arm
        ellipse(Xpos + animateArm1, Ypos + raiseArm1,7,7);
        //the body
        stroke(0);
        fill(0);
        arc(Xpos + 20,Ypos + 20,Xsize + 0.5,Ysize + 0.5, 1,2.9);
        noStroke();
        fill(charColor);
        ellipse(Xpos + 20,Ypos + 20,Xsize,Ysize);
        //left foot
        pushMatrix();
        translate(Xpos + animateFeet2,Ypos + FeetUp2);
        rotate(rotFoot2);
        stroke(0);
        arc(0,0, 14, 13, 9.4,10);
        arc(0,0, 14, 13, 11.4,12.55);
        noStroke();
        arc(0,0, 13, 13, 9.4,12.55);
        stroke(0);
        line(-6.5, 0.5, 6.5, 0.5);
        noStroke();
        popMatrix();
        //the left arm
        fill(0);
        arc(Xpos + animateArm2 + 1,Ypos + raiseArm2 - 0.2,8,8, 1.3, 8);
        fill(charColor);
        ellipse(Xpos + animateArm2,Ypos + raiseArm2,7.7,7.7);
        //the eyes
        fill(0);
        stroke(0);
        if (eyeBall) { 
          ellipse(Xpos + eyeX1,Ypos + eyeY,3,3);
          ellipse(Xpos + eyeX2,Ypos + eyeY,3,3);
        }
        if (brow) line(Xpos + eyeX1 - 2, Ypos + eyeY - 1.6, Xpos + eyeX2 + 2, Ypos + eyeY - 1.6);
      }
    
    
    
    Nubbles Bubble;
    
    PImage doughNut;
    
    
    Boolean MrHappy = true;
    Boolean moves = true;
    Boolean eyes = true;
    Boolean JumpButton = true;
    
    void setup() {
      size(800,700);
      doughNut = loadImage("doughnut.png");
      
      Bubble = new Nubbles();
    }
    
    void draw() {
      background(0,255,0);
      smooth();
      rect(0,499.5,800,700);
      pushMatrix();  
      //this is the main character
    
      if (MrHappy)
      Bubble.Happy(); 
      
      if(moves)
      Bubble.animate(); 
      
      if(eyes)
      Bubble.eyeControl();
      
      if(JumpButton)
      Bubble.Jump();
      
      popMatrix(); 
    
      scale(0.5);
      image(doughNut,0,0);
    
      //experiment v delet soon  
      if(keyPressed) {
        if(key=='d') {
          // charRot += 5;
        }
        else if(key=='a') {
          // charRot += -5;
        }
      }
      // scale(2);
      //ellipse(moveX,moveY,20,20);
    }
    
    
    
    // this is where the character is
    float Ypos = 20;
    float Xpos = 0;
    float direction = 2;
    
    //this is where the character will go
    float moveX = 0;
    float moveY = 400;
    
    //this is his feet motions
    float motion = -1;
    float motionUp = -1;
    float motion2 = -1;
    float motionUp2 = -1;
    
    //this is feet positons
    float animateFeet1 = 25;
    float animateFeet2 = 15;
    float FeetUp1 = 30;
    float FeetUp2 = 30;
    
    //body animations
    float bobbing = 1;
    float Xsize = 20;
    float Ysize = 20;
    
    //hand animations
    float animateArm1 = 10;
    float raiseArm1 = 20;
    float animateArm2 = 25;
    float raiseArm2 = 18;
    
    float motionArm1 = 0.3;
    float motionArm2 = -0.3;
    
    void animate() {
      //this makes Happy walk
      if (keyLeft) {
        //this moves the character left
        moveX += -3;
        direction = 2;
        Xpos = 0;
        Ypos = 15;
        //right foot
        animateFeet1 += motion;
        FeetUp1 += motionUp;
        //left foot
        animateFeet2 += motion2;
        FeetUp2 += motionUp2;
        //body
        Ypos += bobbing;
        //arm motions
        animateArm1 += motionArm1;
        animateArm2 += motionArm2; 
    
        //this tells the feet where to go
        //right foot
        if (animateFeet1 > 25) {
          animateFeet1 = 25;
          motion = -0.5;
          motionUp = -1;
        }
        if (animateFeet1 < 14) {
          animateFeet1 = 14;
          motion = 0;
          motionUp = 1;
        }
        if (FeetUp1 < 24) {
          FeetUp1 = 24;
          motionUp = 1;
          motion = -1;
        }
        if (FeetUp1 > 35) {
          FeetUp1 = 35;
          motionUp = 0;
          motion = 1;
        }
        //tells hands where to go
        if (animateArm1 > 11) {
          motionArm1 = -0.3;
        }
        if (animateArm1 < 7) {
          motionArm1 = 0.3;
        }
        if (animateArm2 > 27) {
          motionArm2 = -0.3;
        }
        if (animateArm2 < 23) {
          motionArm2 = 0.3;
        }
    
        //left foot
        if (animateFeet2 > 25) {
          animateFeet2 = 25;
          motion2 = -0.5;
          motionUp2 = -1;
        }
        if (animateFeet2 < 14) {
          animateFeet2 = 14;
          motion2 = 0;
          motionUp2 = 1;
        }
        if (FeetUp2 < 24) {
          FeetUp2 = 24;
          motionUp2 = 1;
          motion2 = -1;
        }
        if (FeetUp2 > 35) {
          FeetUp2 = 35;
          motionUp2 = 0;
          motion2 = 1;
        }
        //body position
        if (Ypos >= 15) {
          // Ypos+=bobbing;
          bobbing = -0.5;
        }
        if (Ypos <= 10.5) {
          //  Ypos+= bobbing;
          bobbing = 0.5;
        }
      } 
      else if (keyRight) {
        //this moves the character right
        moveX += 3;
        direction = -2;
        Xpos = 0;
        Ypos = 15;
        //right foot
        animateFeet1 += motion;
        FeetUp1 += motionUp;
        //left foot
        animateFeet2 += motion2;
        FeetUp2 += motionUp2;
        //body
        Ypos += bobbing;
        //arm motions
        animateArm1 += motionArm1;
        animateArm2 += motionArm2;
    
        //this tells the feet where to go
        //right foot
        if (animateFeet1 > 25) {
          animateFeet1 = 25;
          motion = -0.5;
          motionUp = -1;
        }
        if (animateFeet1 < 14) {
          animateFeet1 = 14;
          motion = 0;
          motionUp = 1;
        }
        if (FeetUp1 < 24) {
          FeetUp1 = 24;
          motionUp = 1;
          motion = -1;
        }
        if (FeetUp1 > 35) {
          FeetUp1 = 35;
          motionUp = 0;
          motion = 1;
        }
        //tells hands where to go
        if (animateArm1 > 11) {
          motionArm1 = -0.3;
        }
        if (animateArm1 < 7) {
          motionArm1 = 0.3;
        }
        if (animateArm2 > 27) {
          motionArm2 = -0.3;
        }
        if (animateArm2 < 23) {
          motionArm2 = 0.3;
        }
    
        //left foot
        if (animateFeet2 > 25) {
          animateFeet2 = 25;
          motion2 = -0.5;
          motionUp2 = -1;
        }
        if (animateFeet2 < 14) {
          animateFeet2 = 14;
          motion2 = 0;
          motionUp2 = 1;
        }
        if (FeetUp2 < 24) {
          FeetUp2 = 24;
          motionUp2 = 1;
          motion2 = -1;
        }
        if (FeetUp2 > 35) {
          FeetUp2 = 35;
          motionUp2 = 0;
          motion2 = 1;
        }
        //body position
        if (Ypos > 15) {
          bobbing = -0.5;
        }
        if (Ypos < 10.5) {
          bobbing = 0.5;
        }//this is the end of the walking animation
      }
    
    
      else {//this resets everything
        if (bored) {
          animateFeet1 = 15;
          animateFeet2 = 25;
          FeetUp1 = 30;
          FeetUp2 = 30;
          motion = 1;
          motion2 = 1;
          motionUp = 1;
          motionUp2 = -1;
          Ypos = 20;
          animateArm1 = 10;
          raiseArm1 = 20;
          animateArm2 = 25;
          raiseArm2 = 18;
          motionArm1 = 0.3;
          motionArm2 = -0.3;
        }
      }
    }
    
    
    
    float eyeX1 = 15;
    float eyeX2 = 19;
    float eyeY = 14;
    float blinkTime = 0;
    float currBlink = blinkTime;
    float armTime = 0;
    float currArm = armTime;
    Boolean brow = false;
    Boolean eyeBall = true;
    Boolean bored = true;
    
    void eyeControl() {
      blinkTime += 1;
      currBlink = blinkTime;
      armTime += 1;
      currArm = armTime;
      if(keyPressed) {
        if(key == CODED) {
          if(keyCode == UP) {
            eyeY = 12;
            eyeX1 = 16;
          } 
          else if (keyCode == DOWN) {
            eyeY = 16;
            eyeX1 = 14;
            brow = true;
          }
        }
      } 
      else {
        eyeX1 = 15;
        eyeX2 = 19;
        eyeY = 14;
        brow = false;
      }
      //this makes him blink
      if(currBlink > 100) {
        eyeBall = false;
        //brow = true;
        blinkTime = blinkTime - currBlink;
      } 
      else {
        eyeBall = true;
      }
      if(currArm >= 600) {
        bored = false;
        animateArm1 += motionArm1;
        animateArm2 += motionArm2;
        //tells hands where to go
        if (animateArm1 > 10) {
          motionArm1 = -0.2;
        }
        if (animateArm1 < 7) {
          motionArm1 = 0.2;
        }
        if (animateArm2 > 26) {
          motionArm2 = -0.2;
        }
        if (animateArm2 < 23) {
          motionArm2 = 0.2;
        }
      } 
      else if(keyPressed) {
        bored = true;
        armTime = armTime - currArm;
      }
      if(currArm > 700) {
        animateArm1 = 10;
        raiseArm1 = 20;
        animateArm2 = 25;
        raiseArm2 = 18;
        armTime = armTime - currArm;
      }
    }
    
    
    
    float gravity = 0;
    float freeFall = -100;
    //float jumpTime = 0;
    float currJump = 0;
    Boolean mass = true;
    Boolean jumpUp = false;
    Boolean moveAir = false;
    Boolean leapLeft = false;
    Boolean leapRight = false;
    
    
    float charRotToSpot = 0;
    void Jump() {
      //activates jump  
      if (mass) {
        if(keyPressed) {
          if(key == ' ') {
            jumpUp = true;
            moves = false;
            mass = false;
            moveAir = true;
          }
        }
    
        if (keySpace && keyLeft) {
          jumpUp = true;
          moves = false;
          mass = false;
          leapLeft = true;
          moveAir = false;
        }
        if (keySpace && keyRight) {
          jumpUp = true;
          moves = false;
          mass = false;
          leapRight = true;
          moveAir = false;
        }
      }
      // makes happy move in air
      if (moveAir) {
        if(keyPressed) {
          if(key == CODED) {
            if(keyCode == LEFT) {
              direction = 2;
              moveX += -2;
            } 
            else if(keyCode == RIGHT) {
              direction = -2;
              moveX += 2;
            }
          }
        }
      }
      // jumps up
      if (jumpUp) {
        moveY += gravity;
        currJump += gravity;
        gravity = -3;
    
        //jumping animation
        Ysize += 1.5;
        FeetUp1 += 1.1;
        FeetUp2 += 1.1;
        rotFoot += 0.1;
        rotFoot2 += -0.1;
        animateFeet1 = 13;
        animateFeet2 = 27;
    
        eyeY = 10;
    
        raiseArm1 += -1.5;
        raiseArm2 += -1.5;
    
        if (leapLeft) {
          moveX += -4;
          charRot -= 2;
          Ypos = 15;
        }
        if (leapRight) {
          moveX += 4;
          charRot += 2;
          Ypos = 15;
        }
    
        if(charRot <= -23)
          charRot = -23;
    
        if(charRot >= 23)
          charRot = 23;
    
        if(FeetUp1 >= 40) {
          FeetUp1 += 0;
          FeetUp1 = 39;
        }
        if(FeetUp2 >= 40) {
          FeetUp2 += 0;
          FeetUp2 = 39;
        }
        if(raiseArm1 <= 8) {
          raiseArm1 = 8;
        }
        if(raiseArm2 <= 8) {
          raiseArm2 = 8;
        }
        if(Ysize >= 30) {
          Ysize += 0;
          Ysize = 30;
        }
        if(rotFoot >= 0.5)
          rotFoot = 0.5;
    
        if(rotFoot2 <= -0.5)
          rotFoot2 = -0.5;
        //end of jump animation
      }
      // falls down
      if(currJump < -100) {
        moveY += gravity;
        gravity += 0.2;
        freeFall += 2.1;
        jumpUp = false;
        if (leapLeft) {
          moveX += -3;
        }
        if (leapRight) {
          moveX += 3;
        }
        //falling animation
        Ysize -= 0.5;
        eyeY += 0.5;
        rotFoot += -0.1;
        rotFoot2 += 0.1;
        FeetUp1 -= 0.25;
        FeetUp2 -= 0.25;
        raiseArm1 += 0.25;
        raiseArm2 += 0.25;
        animateArm1 = 11;
        animateArm2 = 29;
    
        if(Ysize <= 17) {
          Ysize += 0;
          Ysize = 17;
        }
        if(eyeY >= 16)
          eyeY = 16;
    
        if(charRot == -23.0) {
          charRotToSpot = 24;
        } 
        else if(charRot == 23.0) {
          charRotToSpot = -24;
        }
        if(charRot < charRotToSpot)
          charRot += 2.1;
    
        if(charRot > charRotToSpot)
          charRot -=2.1;
    
        if(raiseArm1 >= 14) {
          raiseArm1 = 14;
        }
        if(raiseArm2 >= 14) {
          raiseArm2 = 14;
        }
        if(FeetUp2 <= 30)
          FeetUp2 = 30;
    
        if(FeetUp1 <= 30)
          FeetUp1 = 30;
    
        if(rotFoot2 >= 0.5)
          rotFoot2 = 0.5;
    
        if(rotFoot <= -0.5)
          rotFoot = -0.5;
        //end of fall animation
      }
      // hits ground
      //note, change V that
      if(freeFall >= 6) {
        freeFall = -100;
        gravity = 0;
        currJump = 0;
        mass = true;
        moves = true;
        moveAir = false;
        leapLeft = false;
        leapRight = false;
    
        if (bored) {
          animateFeet1 = 15;
          animateFeet2 = 25;
          FeetUp1 = 30;
          FeetUp2 = 30;
          motion = 1;
          motion2 = 1;
          motionUp = 1;
          motionUp2 = -1;
          Ypos = 20;
          animateArm1 = 10;
          raiseArm1 = 20;
          animateArm2 = 25;
          raiseArm2 = 18;
          motionArm1 = 0.3;
          motionArm2 = -0.3;
          rotFoot = 0;
          rotFoot2 = 0;
          Ysize = 20;
          charRot = 0;
          charRotToSpot = 0;
        }
      }
      if(direction == 2) {
        Xpos = 20;
      } 
      else if(direction == -2) {
        Xpos = -60;
      }
    }
    
    }
    
    Boolean keySpace = false;
    Boolean keyLeft = false;
    Boolean keyRight = false;
    
    // this tells if a key is being pressed
    void keyPressed() {
      if (key==CODED) {
        if (keyCode == LEFT) keyLeft = true;
        else if (keyCode == RIGHT) keyRight = true;
      }
      if (key==' ') keySpace = true;
    }
    
    void keyReleased() {
      if (key==CODED) {
        if (keyCode == LEFT) keyLeft = false;
        else if (keyCode == RIGHT) keyRight = false;
      }
      if (key==' ') keySpace = false;
    }
    
    //}
    
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Jeremy Green

    Nubbles

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    This is my first animated character in processing.

    EDIT: found out that this is extremely laggy(probably from the smooth function)
    It doesn't run this slowly straight from the code on my computer.

    You need to login/register to comment.