• fullscreen
  • Keyboard.pde
  • Rabbit.pde
  • RabbitRun_WSS.pde
  • World.pde
  • 
    class Keyboard {
    
      Boolean holdingUp,holdingRight,holdingLeft,holdingSpace;
    
      Keyboard() {
        holdingUp=holdingRight=holdingLeft=holdingSpace=false;
      }
    
    
      void pressKey(int key) 
      {
        if(key == KeyEvent.VK_R) 
        { 
          if(screenNumber == 3)
          {
            resetGame();
          }
        }
    
    
        if (key == KeyEvent.VK_UP) {
          holdingUp = true;
        }
        if (key == KeyEvent.VK_LEFT) {
          holdingLeft = true;
        }
        if (key == KeyEvent.VK_RIGHT) {
          holdingRight = true;
        }
        if (key == KeyEvent.VK_SPACE) {
          holdingSpace = true;
        }
      }
    
      void releaseKey(int key) {
        if (key == KeyEvent.VK_UP) {
          holdingUp = false;
        }
        if (key == KeyEvent.VK_LEFT) {
          holdingLeft = false;
        }
        if (key == KeyEvent.VK_RIGHT) {
          holdingRight = false;
        }
        if (key == KeyEvent.VK_SPACE) {
          holdingSpace = false;
        }
      }
    }
    
    
    class Player {
      PVector position,velocity; 
    
      Boolean isOnGround; 
      Boolean facingRight; 
      int animDelay; 
      int animFrame; 
      int coinsCollected; 
      int checkpoint;
      
      static final float JUMP_POWER = 7.0; 
      static final float RUN_SPEED = 3.0; 
      static final float AIR_RUN_SPEED = 1.0; 
      static final float SLOWDOWN_PERC = 0.6; 
      static final float AIR_SLOWDOWN_PERC = 0.85; 
      static final int RUN_ANIMATION_DELAY = 1; 
      static final float TRIVIAL_SPEED = 1.0;
      
      Player() 
      { 
        isOnGround = false;
        facingRight = true;
        position = new PVector();
        velocity = new PVector();
        reset();
      }
      
      void reset() {
        coinsCollected = 0;
        animDelay = 0;
        animFrame = 0;
        velocity.x = 0;
        velocity.y = 0;
      }
      
      void inputCheck() 
      {
        float speedHere = (isOnGround ? RUN_SPEED : AIR_RUN_SPEED);
        float frictionHere = (isOnGround ? SLOWDOWN_PERC : AIR_SLOWDOWN_PERC);
        
        if(theKeyboard.holdingLeft) 
        {
          velocity.x -= speedHere;
        } else if(theKeyboard.holdingRight) 
        {
          velocity.x += speedHere;
        } 
        velocity.x *= frictionHere; 
        
        if(isOnGround) 
        {
          if(theKeyboard.holdingSpace || theKeyboard.holdingUp) 
          { 
            velocity.y = -JUMP_POWER; 
            isOnGround = false; 
          }
        }
      }
      
      void checkForWallBumping() 
      {
        int guyWidth = guy_stand.width; 
        int guyHeight = guy_stand.height;
        int wallProbeDistance = int(guyWidth*0.3);
        int ceilingProbeDistance = int(guyHeight*0.95);
    
        PVector leftSideHigh,rightSideHigh,leftSideLow,rightSideLow,topSide;
        leftSideHigh = new PVector();
        rightSideHigh = new PVector();
        leftSideLow = new PVector();
        rightSideLow = new PVector();
        topSide = new PVector();
    
    
        leftSideHigh.x = leftSideLow.x = position.x - wallProbeDistance; 
        rightSideHigh.x = rightSideLow.x = position.x + wallProbeDistance; 
        leftSideLow.y = rightSideLow.y = position.y-0.2*guyHeight; 
        leftSideHigh.y = rightSideHigh.y = position.y-0.8*guyHeight;
    
        topSide.x = position.x; 
        topSide.y = position.y-ceilingProbeDistance; 
    
    
        if( theWorld.worldSquareAt(topSide)==World.TILE_KILLBLOCK ||
             theWorld.worldSquareAt(leftSideHigh)==World.TILE_KILLBLOCK ||
             theWorld.worldSquareAt(leftSideLow)==World.TILE_KILLBLOCK ||
             theWorld.worldSquareAt(rightSideHigh)==World.TILE_KILLBLOCK ||
             theWorld.worldSquareAt(rightSideLow)==World.TILE_KILLBLOCK ||
             theWorld.worldSquareAt(position)==World.TILE_KILLBLOCK)
        {
          theWorld.rs();
          return; 
        }
        
     
        
        if( theWorld.worldSquareAt(topSide)==World.TILE_SOLID) 
        {
          if(theWorld.worldSquareAt(position)==World.TILE_SOLID) 
          {
            position.sub(velocity);
            velocity.x=0.0;
            velocity.y=0.0;
          } else {
            position.y = theWorld.bottomOfSquare(topSide)+ceilingProbeDistance;
            if(velocity.y < 0) 
            {
              velocity.y = 0.0;
            }
          }
        }
        
        if(theWorld.worldSquareAt(leftSideLow)==World.TILE_SOLID) 
        {
          position.x = theWorld.rightOfSquare(leftSideLow)+wallProbeDistance;
          if(velocity.x < 0) 
          {
            velocity.x = 0.0;
          }
        }
       
        if( theWorld.worldSquareAt(leftSideHigh)==World.TILE_SOLID) 
        {
          position.x = theWorld.rightOfSquare(leftSideHigh)+wallProbeDistance;
          if(velocity.x < 0) 
          {
            velocity.x = 0.0;
          }
        }
       
        if( theWorld.worldSquareAt(rightSideLow)==World.TILE_SOLID) 
        {
          position.x = theWorld.leftOfSquare(rightSideLow)-wallProbeDistance;
          if(velocity.x > 0) 
          {
            velocity.x = 0.0;
          }
        }
       
        if( theWorld.worldSquareAt(rightSideHigh)==World.TILE_SOLID) 
        {
          position.x = theWorld.leftOfSquare(rightSideHigh)-wallProbeDistance;
          if(velocity.x > 0) 
          {
            velocity.x = 0.0;
          }
        }
      }
    
      void checkForWasteGetting() 
      {
        PVector centerOfPlayer;
        centerOfPlayer = new PVector(position.x,position.y-guy_stand.height/2);
    
        if(theWorld.worldSquareAt(centerOfPlayer)==World.TILE_WASTE) 
        {
          theWorld.setSquareAtToThis(centerOfPlayer, World.TILE_EMPTY);
          coinsCollected++;
        }
      }
      
      void checkForBox1()
      {
        outlinedText("WasteGems Collected:"+thePlayer.coinsCollected,1750, 166);
        PVector centerOfPlayer;
        centerOfPlayer = new PVector(position.x,position.y-guy_stand.height/2);
        
        if(theWorld.worldSquareAt(centerOfPlayer)==World.TILE_MAP1) 
        {
          theWorld.setSquareAtToThis(centerOfPlayer, World.TILE_MAP1);
          image(minimap1,0,0);
        }
      }
    
      void checkForBox2()
      {
        PVector centerOfPlayer;
        centerOfPlayer = new PVector(position.x,position.y-guy_stand.height/2);
        
        if(theWorld.worldSquareAt(centerOfPlayer)==World.TILE_MAP2) 
        {
          theWorld.setSquareAtToThis(centerOfPlayer, World.TILE_MAP2);
          image(minimap2,572,0);
        }
      }
      
      void checkForBox3()
      {
        PVector centerOfPlayer;
        centerOfPlayer = new PVector(position.x,position.y-guy_stand.height/2);
        
        if(theWorld.worldSquareAt(centerOfPlayer)==World.TILE_MAP3) 
        {
          theWorld.setSquareAtToThis(centerOfPlayer, World.TILE_MAP3);
          image(minimap3,1150,0);
        }
      }
      
      void checkForBox4()
      {
        PVector centerOfPlayer;
        centerOfPlayer = new PVector(position.x,position.y-guy_stand.height/2);
        
        if(theWorld.worldSquareAt(centerOfPlayer)==World.TILE_MAP4) 
        {
          theWorld.setSquareAtToThis(centerOfPlayer, World.TILE_MAP4);
          image(minimap4,1800,0);
        }
      }
      
      void checkForCP()
      {
        PVector centerOfPlayer;
        centerOfPlayer = new PVector(position.x,position.y-guy_stand.height/2);
        
        if(theWorld.worldSquareAt(centerOfPlayer)==World.TILE_CP) 
        {
          theWorld.setSquareAtToThis(centerOfPlayer, World.TILE_CP);
          text("Check Point Reach.",1000,50);
        }
      }
      
     
      void checkForEnd()
      {
        PVector centerOfPlayer;
        centerOfPlayer = new PVector(position.x,position.y-guy_stand.height/2);
        
        if(theWorld.worldSquareAt(centerOfPlayer)==World.TILE_END) 
        {
          screenNumber = 4;
        }
      }
      
      
      void checkForFalling() 
      {
    
        if(theWorld.worldSquareAt(position)==World.TILE_EMPTY ||
           theWorld.worldSquareAt(position)==World.TILE_WASTE) 
           {
           isOnGround=false;
        }
        
        if(isOnGround==false) 
        {
          if(theWorld.worldSquareAt(position)==World.TILE_SOLID) 
          { 
            isOnGround = true;
            position.y = theWorld.topOfSquare(position);
            velocity.y = 0.0;
          } else {
            velocity.y += GRAVITY_POWER;
          }
        }
      }
    
      void move() 
      {
        position.add(velocity);   
        checkForWallBumping();    
        checkForWasteGetting();    
        checkForFalling();
        checkForBox1();
        checkForBox2();
        checkForBox3();
        checkForBox4();
        checkForEnd();
        checkForEnd();
        checkForCP();
      }
      
      void draw() 
      {
        int guyWidth = guy_stand.width;
        int guyHeight = guy_stand.height;
        
        if(velocity.x<-TRIVIAL_SPEED) 
        {
          facingRight = false;
        } else if(velocity.x>TRIVIAL_SPEED) 
        {
          facingRight = true;
        }
        
    
        translate(position.x,position.y);
        if(facingRight==false) 
        {
          scale(-1,1); 
        }
        translate(-guyWidth/2,-guyHeight); 
    
        if(isOnGround==false) 
        { 
          image(guy_run1, 0,0); 
        } else if(abs(velocity.x)<TRIVIAL_SPEED) {
          image(guy_stand, 0,0);
        } else { 
          if(animDelay--<0) 
          {
            animDelay=RUN_ANIMATION_DELAY;
            if(animFrame==0) 
            {
              animFrame=1;
            } else {
              animFrame=0;
            }
          }
          
          if(animFrame==0) 
          {
            image(guy_run1, 0,0);
          } else {
            image(guy_run2, 0,0);
          }
        }
        
      }
    }
    
    
    int screenNumber;
    
    import ddf.minim.*;
    Minim minim;
    
    PImage guy_stand, guy_run1, guy_run2;
    PImage screen1, screen2, screen3, win; 
    PImage xbox;
    PImage Background;
    PImage minimap1, minimap2, minimap3, minimap4;
    PImage waste;
    AudioPlayer music; 
    AudioSample sndJump, sndCoin; 
    
    
    float cameraOffsetX;
    
    Player thePlayer = new Player();
    World theWorld = new World();
    Keyboard theKeyboard = new Keyboard();
    
    PFont font;
    
    int gameStartTimeSec,gameCurrentTimeSec;
    
    
    final float GRAVITY_POWER = 0.5; 
    
    void setup() 
    { 
      size(500,368); 
    
      font = loadFont("KristenITC-Regular-20.vlw");
      guy_stand = loadImage("rabbit.gif");
      guy_run1 = loadImage("rabbit1.gif");
      guy_run2 = loadImage("rabbit2.gif");
      screen1 = loadImage("Screen1.gif");
      screen2 = loadImage("Screen2.gif");
      screen3 = loadImage("Lionmouth.gif");
      minimap1 = loadImage("LionEsoph.gif");
      minimap2 = loadImage("LionStomach.gif");
      minimap3 = loadImage("LionIntestine.gif");
      minimap4 = loadImage("LionRectum.gif");
      Background = loadImage("Background.gif");
      win = loadImage("winningscreen.gif");
      xbox = loadImage("Box.gif");
      waste = loadImage("poogem.gif");
      cameraOffsetX = 0.0;
    
      frameRate(30); 
      resetGame();
      screenNumber =0;
    }
    
    void resetGame() {
      thePlayer.reset(); 
      theWorld.reload();
    }
    
    Boolean gameWon() { 
      return (thePlayer.coinsCollected == theWorld.coinsInStage);
    }
    
    void outlinedText(String sayThis, float atX, float atY) {
      textFont(font); 
      fill(0);
      text(sayThis, atX-1,atY);
      text(sayThis, atX+1,atY);
      text(sayThis, atX,atY-1);
      text(sayThis, atX,atY+1);
      fill(255); 
      text(sayThis, atX,atY);
    }
    
    void updateCameraPosition() {
      int rightEdge = World.GRID_UNITS_WIDE*World.GRID_UNIT_SIZE-width;
    
      cameraOffsetX = thePlayer.position.x-width/2;
      if(cameraOffsetX < 0) {
        cameraOffsetX = 0;
      }
    
      if(cameraOffsetX > rightEdge) {
        cameraOffsetX = rightEdge;
      }
    }
    
    void draw() 
    {
      if(screenNumber == 0 )
      {
        image(screen1,0,0);
        if (mousePressed == true) 
        {
          screenNumber = 1;
          mousePressed = false;
        }
      }
       else if(screenNumber == 1)
      {
        image(screen2,0,0);
        fill(255,255,0);
        textFont(font);
        text("Click to Continue...", 250, 100);
        if(mousePressed == true) 
        {
          screenNumber = 2;
          mousePressed = false;
        }
      }
        else if(screenNumber == 2)
      {
        image(screen3,0,0);
         if (mousePressed == true) 
        {
          screenNumber = 3;
          mousePressed = false;
        }
      }
       else if(screenNumber == 3)
      {
        translate(-cameraOffsetX,0.0); 
        updateCameraPosition();
        theWorld.render();
        thePlayer.inputCheck();
        thePlayer.move();
        thePlayer.draw();
    
        if(focused == false) 
        { 
          textAlign(CENTER);
        }else{
          textAlign(LEFT); 
          textAlign(RIGHT);    
          textAlign(CENTER);
        }
      }
      else if(screenNumber == 4)
      {
        image(win,0,-10);
         if (mousePressed == true) 
        {
          screenNumber = 0;
          resetGame();
          mousePressed = false;
        }
     }
    }
    
    
    void keyPressed(KeyEvent evt) 
    {
      theKeyboard.pressKey(evt.getKeyCode());
    }
    
    void keyReleased(KeyEvent evt) 
    {
      theKeyboard.releaseKey(evt.getKeyCode());
    }
    
    
    
    class World 
    {
      int coinsInStage; 
      int coinRotateTimer; 
    
      static final int TILE_EMPTY = 0;
      static final int TILE_SOLID = 1;
      static final int TILE_WASTE = 2;
      static final int TILE_KILLBLOCK = 3;
      static final int TILE_START = 4;
      static final int TILE_BACKGROUND = 5;
      static final int TILE_MAP1 = 6;
      static final int TILE_MAP2 = 7;
      static final int TILE_MAP3 = 8;
      static final int TILE_MAP4 = 9;
      static final int TILE_END = 10;
      static final int TILE_CP = 11;
    
      static final int GRID_UNIT_SIZE = 23;
    
    
      static final int GRID_UNITS_WIDE = 100;
      static final int GRID_UNITS_TALL = 16;
    
      int[][] worldGrid = new int[GRID_UNITS_TALL][GRID_UNITS_WIDE]; 
    
    
      int[][] start_Grid = { 
        {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 9, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 0, 0, 0, 0},};
    
    
      World() 
      { 
        coinRotateTimer = 0;
      }
    
    
      int worldSquareAt(PVector thisPosition) 
      {
        float gridSpotX = thisPosition.x/GRID_UNIT_SIZE;
        float gridSpotY = thisPosition.y/GRID_UNIT_SIZE;
    
    
        if(gridSpotX<0) 
        {
          return TILE_SOLID;
        }
        if(gridSpotX>=GRID_UNITS_WIDE) 
        {
          return TILE_SOLID;
        }
        if(gridSpotY<0) 
        {
          return TILE_SOLID;
        }
        if(gridSpotY>=GRID_UNITS_TALL) 
        {
          return TILE_SOLID;
        }
    
        return worldGrid[int(gridSpotY)][int(gridSpotX)];
      }
    
    
      void setSquareAtToThis(PVector thisPosition, int newTile) 
      {
        int gridSpotX = int(thisPosition.x/GRID_UNIT_SIZE);
        int gridSpotY = int(thisPosition.y/GRID_UNIT_SIZE);
    
        if(gridSpotX<0 || gridSpotX>=GRID_UNITS_WIDE || 
          gridSpotY<0 || gridSpotY>=GRID_UNITS_TALL) 
        {
          return;
        }
    
        worldGrid[gridSpotY][gridSpotX] = newTile;
      }
    
    
      float topOfSquare(PVector thisPosition) 
      {
        int thisY = int(thisPosition.y);
        thisY /= GRID_UNIT_SIZE;
        return float(thisY*GRID_UNIT_SIZE);
      }
      float bottomOfSquare(PVector thisPosition) 
      {
        if(thisPosition.y<0) 
        {
          return 0;
        }
        return topOfSquare(thisPosition)+GRID_UNIT_SIZE;
      }
      float leftOfSquare(PVector thisPosition) 
      {
        int thisX = int(thisPosition.x);
        thisX /= GRID_UNIT_SIZE;
        return float(thisX*GRID_UNIT_SIZE);
      }
      float rightOfSquare(PVector thisPosition) 
      {
        if(thisPosition.x<0) 
        {
          return 0;
        }
        return leftOfSquare(thisPosition)+GRID_UNIT_SIZE;
      }
    
      void reload() 
      {
        coinsInStage = 0; 
    
        for(int i=0;i<GRID_UNITS_WIDE;i++) 
        {
          for(int ii=0;ii<GRID_UNITS_TALL;ii++) 
          {
            if(start_Grid[ii][i] == TILE_START) 
            {
              worldGrid[ii][i] = TILE_EMPTY;
    
    
              thePlayer.position.x = i*GRID_UNIT_SIZE+(GRID_UNIT_SIZE/2);
              thePlayer.position.y = ii*GRID_UNIT_SIZE+(GRID_UNIT_SIZE/2);
            } 
            else 
            {
              if(start_Grid[ii][i]==TILE_WASTE) 
              {
                coinsInStage++;
              }
              worldGrid[ii][i] = start_Grid[ii][i];
            }
          }
        }
      }
    
      void rs()
      {
        for(int i=0;i<GRID_UNITS_WIDE;i++) 
        {
          for(int ii=0;ii<GRID_UNITS_TALL;ii++) 
          {
            if(start_Grid[ii][i] == TILE_CP) 
            {
              worldGrid[ii][i] = TILE_EMPTY;
              thePlayer.position.x = i*GRID_UNIT_SIZE+(GRID_UNIT_SIZE/2);
              thePlayer.position.y = ii*GRID_UNIT_SIZE+(GRID_UNIT_SIZE/2);
            } 
          }
        }
      }
    
    
      void render() 
      { 
        coinRotateTimer--;
        if(coinRotateTimer<-GRID_UNIT_SIZE/3) 
        {
          coinRotateTimer = GRID_UNIT_SIZE/3;
        }
    
        for(int i=0;i<GRID_UNITS_WIDE;i++) 
        { 
          for(int ii=0;ii<GRID_UNITS_TALL;ii++) 
          { 
            switch(worldGrid[ii][i]) 
            { 
            case TILE_SOLID:
              fill(0,0);
              break;
            case TILE_KILLBLOCK:
              fill(0,0);
              break;
            case TILE_BACKGROUND:
              image(Background,0,0);
              break;  
            default:
              break;
            }
    
            if(worldGrid[ii][i]==TILE_WASTE) 
            {
              image(waste,i*GRID_UNIT_SIZE+(GRID_UNIT_SIZE/2),ii*GRID_UNIT_SIZE+(GRID_UNIT_SIZE/2));
            }
            if(worldGrid[ii][i]==TILE_MAP1)
            {
              image(xbox,23,185);
            }
            if(worldGrid[ii][i]==TILE_MAP2)
            {
              image(xbox,800,178);
            }
            if(worldGrid[ii][i]==TILE_MAP3)
            {
              image(xbox,1370,335);
            }
              if(worldGrid[ii][i]==TILE_MAP4)
            {
              image(xbox,2000,25);
            }
          }
        }
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Lemmonade

    Rabbit Run

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

    Get out from the lion!

    Awesome!!!!
    Chris Ball
    11 Oct 2011
    nice!
    You need to login/register to comment.