Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*

 Blinken - By: P.Y. Boulerice
 
 /////////////////////////////////////////////////////////////////////////////
 Play as a small enthusiastic cube as he tries to put his world back together.
 An unknown enemy has wripped it appart. Find him. Destroy him. And restore
 balance. Goodluck young one!
 /////////////////////////////////////////////////////////////////////////////
 */

// Variables
float x;
float y;

boolean playerBlink = false;
float blinkUnit = 0;
boolean jumping = false;
boolean jumpStatus = false;
float jump = 0;

// Door Keys
boolean door1 = false; // to world2
boolean door2 = false; // key
boolean door3 = false; // to boss1
boolean door4 = false; // to world1
boolean door5 = false;

// Notifications
float notif = 0;
float notifY = 480;
float notifTimer = 0;
boolean notifSwitch = false;

// CHARACTERS

// Stalker
float stalkerX = 550;
float stalkerY = 240;
float stalkerSize = 80;
boolean stalkerApple = false;
boolean stalkerBlink = false;
float stalkerBlinkUnit = 0;

// Boss
float bossX = 260;
float bossY = 0;
float bossSize = 200;
boolean bossBlink = false;
float bossBlinkUnit = 0;
boolean fistSmash = false;
float fistState = 0;
float fistY = 40;
float fistX = 0;
float fistAcc = 1;
float bossHealth = 3;

// Boss Switch
boolean bossHurtDown = false;
boolean bossSwitchDir = false;
float bossSwitchSize = 20;
float bossSwitchX = 150;
boolean bossSwitchTriggered = false;

// Boss Explosion
float explosionStage = 0;
float explosionSize = 200;
float explosionTimer = 0;

// Mentor
float mentorX = 0;
float mentorY = 240;
boolean mentorBlink = false;
float mentorBlinkUnit = 0;
float mentorSize = 40;


// Story
boolean story = false;
float storyStage = 2;
float storyTimer = 0;

// Character is notified that he or she needs a key a the watchpoint.
boolean storyEvent1 = false;

// Screen Animation
float sa = 0;

// Spike
boolean spikeDirection = true;
float spike1X = 0;
float spike1Y = 0;
float spike1Acc = 1;
boolean spikeCanDie = false;

// Box 1
float box1X;
float box1Y;
float box1DoorSize;
float box1Size = 50;

// EvilBall1_1
float eb1X = 550;
float eb1Y = 100;
float eb1YV = 1;
float eb1Size = 30;
float eb2Size = 30;
float eb3Size = 30;
boolean eb1JumpDir = false;

// Building1_1
float build1_1X = 650;
float build1_1Y = 240;
float build1_1Size = 50;
float build1_1DoorSize = 0;

// WatchPoint1_1
float watchPoint1_1X = -100;
float watchPoint1_1Y = 240;
float watchPoint1_1Size = 40;
float watchPoint1_1DoorSize = 0;

// Box 2
float box2X;
float box2Y;
float box2DoorSize;
float box2Size = 50;

// Box 3
float box3X;
float box3Y;
float box3DoorSize;
float box3Size = 50;

// Apples
float apple1X = -500;
float apple1Y = 250;

float targetX;
float targetY;
boolean globalMove;
float allMover;
float dir;
boolean playerMoving;
float center;

float speed;

color currentColor = color(#90AEFF);
color hoverColor = 0;


boolean doorContact = false;
boolean fillr = false;

float world = -1;
float worldSave = -1;

// Colors
color world1Color = color(0);
color world2Color = color(0);
color world3Color = color(0);
color world4Color = color(0);

// Maintains
float mountX = 0;
float mountY = 240;

void setup()
{
  size(720, 480);

  noStroke();

  // variables
  x = width / 2;
  y = height / 2;

  // box 1
  box1X = 200;
  box1Y = height / 2;
  box1DoorSize = 0;

  // box 2
  box2X = 900;
  box2Y = height / 2;
  box2DoorSize = 0;

  // box 3
  box3X = -200;
  box3Y = height / 2;
  box3DoorSize = 0;

  center = (width / 2) - 10;

  globalMove = false;
  dir = 0;
  allMover = 0;

  targetX = -1.;
  targetY = -1.;

  playerMoving = false;
  speed = 5.;

  // Boss
  fistX = width / 2;

  //A52445
  //F3921E
  //CD4544
  //470B37
  //05C096 //048D6E //024032
  //8D7D4A

  world1Color = color(#470B37);
  world2Color = color(#F3921E);
  world3Color = color(#05C096);
  world4Color = color(#A52445);

  currentColor = 0;
  background(#05C096);
}

void draw()
{
  // HOUSEKEEPING
  houseKeeping();
  //background(#A52445);
  //javaTest();

  // Watch Points
  watchPoint1_1();

  // Secret Door to Gun

  // Boss

  // Spikes
  spikeEngine();
  spike2(spike1X + 100);
  spike2(spike1X + 70);
  spike2(spike1X + 40);

  // BOX PORTALS BETWEEN WORLDS
  box1();
  box2();
  box3();

  build1_1();

  //EvilBall
  evilBallEngine();

  evilBall1((eb1X + 1));
  evilBall1((eb1X - 500));

  evilBall3(100);
  evilBall3(620);

  // Items and Keys
  apple1();

  // World Stuff
  mountains();

  // Boss
  bossSwitch();
  boss();
  bossExplosion();

  // Stalker
  stalker1();

  // Floor
  if (world > -1)
  {
    player();
  }

  if (world > 0)
  {
    fill(255, 50);
    for (int i = 0; i < 730; i+=5)
    {
      rect(i, height/2 + 20, 4, 4);
    }
  }

  // Characters
  characterMentor((width / 2) - 50., mentorY);

  // Story Engine
  storyEngine();

  // Notifications
  notifications();

  // World 4 Fade in Screen Animation (SA)
  world4();

  // Dead
  dead();

  // Pause Menu
  pause();

  // Menu
  menu();

  // Player Clasping
  playerClasping();
}

void reset()
{
  x = width / 2;
  y = height / 2;
  playerBlink = false;
  blinkUnit = 0;
  jumping = false;
  jumpStatus = false;
  jump = 0;

  // Story
  story = false;

  // Spike
  spikeDirection = true;

  // Stalker
  stalkerX = 550;
  stalkerY = 240;
  stalkerSize = 80;
  stalkerBlink = false;
  stalkerBlinkUnit = 0;

  // Mentor
  mentorX = 0;
  mentorY = 240;
  mentorBlink = false;
  mentorBlinkUnit = 0;

  // Box 1
  box1X = 200;
  box1Y = height / 2;
  box1DoorSize = 0;
  box1Size = 0;

  // EvilBall1_1
  eb1X = 550;
  eb1Y = 100;
  eb1YV = 1;
  eb1Size = 30;
  eb1JumpDir = false;

  // Spikes
  spikeDirection = true;
  spike1X = 0;
  spike1Y = 0;
  spike1Acc = 1;
  spikeCanDie = false;

  // Building1_1
  build1_1X = 650;
  build1_1Y = 240;
  build1_1Size = 50;
  build1_1DoorSize = 0;

  // WatchPoint1_1
  watchPoint1_1X = -100;
  watchPoint1_1Y = 240;
  watchPoint1_1Size = 40;
  watchPoint1_1DoorSize = 0;

  // Box 2
  box2X = 800;
  box2Y = height / 2;
  box2DoorSize = 0;
  box2Size = 0;

  // Box 3
  box3X = -50;
  box3Y = height / 2;
  box3DoorSize = 0;
  box3Size = 50;

  // Apples
  apple1X = -500;
  apple1Y = 250;

  targetX = -1.;
  targetY = -1.;
  globalMove = false;
  allMover = 0;
  dir = 0;
  playerMoving = false;
  center = (width / 2) - 10;

  speed = 5.;

  // Boss
  fistX = width / 2;
  bossHealth = 3;

  currentColor = color(0);
  hoverColor = 0;

  doorContact = false;
  fillr = false;

  world = 1;

  // Maintains
  mountX = 0;
  mountY = 240;
}

void houseKeeping()
{
  background(currentColor);

  if (world == 1)
  {
    currentColor = world1Color;
  } else if (world == 2)
  {
    currentColor = world2Color;
  } else if (world == 3)
  {
    currentColor = world3Color;
  } else if (world == 4)
  {
    currentColor = world4Color;
  }
}

void playerClasping()
{
  if (world == 2)
  {
    if (stalkerApple == false)
    {
      if (x > stalkerX - 50)
      {
        targetX = stalkerX - 50;

        // Push Notification
        notifSwitch = true;
        notifTimer = 0;
        notif = 3;
      }
    } else if (door5 == true)
    {
      if (x > stalkerX - 70)
      {
        door5 = false;
      }
    }
  }
}

void storyEngine()
{
  if (story == true)
  {
    if (storyStage == 1)
    {
      playerMoving = true;
      if (world == 1)
      {
        storyTimer++;
        if (storyTimer < 400)
        {
          fill(255);
          textSize(18);
          text("This world is unstable. It has been fractured!?!", 250, 380);
        } else if (storyTimer > 400 && storyTimer < 800)
        {
          fill(255);
          textSize(18);
          text("Travel through it's broken pieces using the", 250, 380);
          text("'Portalways'. SOLVE THIS IMPOSSIBILITY!", 250, 400);
        } else if (storyTimer > 800 && storyTimer < 1100)
        {
          fill(255);
          textSize(18);
          text("Use 'e' to interact with things.", 250, 380);
          text("Also, click around to move.", 250, 400);
        } else if (storyTimer > 1100)
        {
          story = false;
          storyStage = 2;
          storyTimer = 0;
          playerMoving = false;
        }
      }
    } else if (storyStage == 2)
    {
      playerMoving = true;
      if (world == 1)
      {
        storyTimer++;
        if (storyTimer < 400)
        {
          if (globalMove == false && targetX == -1.)
          {
            fill(255);
            textSize(18);
            text("You have found your first Portalway!", 250, 380);
            text("Go on... Explore! (use 'E' to interact)", 250, 400);
          }
        } else if (storyTimer > 400)
        {
          playerMoving = false;
          story = false;
          storyStage = 2;
          storyTimer = 0;
          notifTimer = 0;
          notif = 1;
          notifSwitch = true;
        }
      }
    } else if (storyStage == 3)
    {
      playerMoving = true;
      if (world == 2)
      {
        storyTimer++;
        if (storyTimer < 400)
        {
          if (globalMove == false && targetX == -1.)
          {
            fill(255);
            textSize(18);
            text("You need a key to unlock that...", 250, 380);
            text("Try going the other way...", 250, 400);
          }
        } else if (storyTimer > 400)
        {
          playerMoving = false;
          story = false;
          storyStage = 3;
          storyTimer = 0;
        }
      }
    } else if (storyStage == 4)
    {
      playerMoving = true;
      if (world == 4)
      {
        storyTimer++;
        if (storyTimer < 400)
        {
          if (globalMove == false && targetX == -1.)
          {
            fill(255);
            textSize(18);
            text("You did it... You really did it...", 250, 380);
            text("But how???", 250, 400);
          }
        } else if (storyTimer > 400 && storyTimer < 800)
        {
          fill(255);
          textSize(18);
          text("JUST KIDDING YOU FOOL!", 250, 380);
          text("NOW YOU ARE STUCK IN THE ABYSS!", 250, 400);
        } else if (storyTimer > 800 && storyTimer < 1000)
        {
          fill(255);
          textSize(18);
          text("PEACE!!!!!!", 250, 380);
        } else if (storyTimer > 1000)
        {
          playerMoving = false;
          story = false;
          storyStage = 3;
          storyTimer = 0;
        }
      }
    }
  }
}

void characterMentor(float xx, float yy)
{
  if (story == true)
  {
    if (storyStage > 0)
    {
      if (globalMove == false && targetX == -1.)
      {
        mentorSize = 40;
        // Icon Backround
        fill(0, 50);
        rect(0, 264, 720, 240);

        // Character
        fill(#EB8072);
        rect(xx, yy - 20, 20, 40);

        // Icon
        fill(#EB8072);
        rect(40, 300, 180, 180);

        if (mentorBlink == false)
        {
          float ran = random(1, 100);

          if ((int) ran == 2)
          {
            mentorBlink = true;
            mentorBlinkUnit = 0;
          }

          fill(0, 90);
          ellipse(xx + 10, yy - 10, 10, 10);
          ellipse(130, 390, 120, 120);
        } else
        {
          mentorBlinkUnit ++;
          fill(0, 90);
          ellipse(xx + 10, yy - 10, 10, sin(mentorBlinkUnit * 0.05) * 10.);
          ellipse(130, 390, 120, sin(mentorBlinkUnit * 0.05) * 120.);
          if (mentorBlinkUnit > 10)
          {
            mentorBlink = false;
          }
        }
      }
    }
  } else
  {
    if (mentorSize > 0)
    {
      mentorSize -= 1.;

      // Icon Backround
      fill(0, 50);
      rect(0, 264, mentorSize * 18, mentorSize * 6);

      // Character
      fill(#EB8072);
      rect(xx, yy - 20, mentorSize / 2, mentorSize);

      // Icon
      fill(#EB8072);
      rect(40, 300, 9 * (mentorSize / 2), 9 * (mentorSize / 2));

      // Eyes
      fill(0, 90);
      ellipse(xx + 10, yy - 10, mentorSize / 4, mentorSize / 4);
      ellipse(130, 390, mentorSize * 4, mentorSize * 4);
    }
  }
}

void player()
{
  if (world > 0)
  {

    allMover = 0;

    if (targetX >= 0)
    {
      if (x < targetX)
      {
        x+= speed;
        if (x > targetX - 40)
        {
          speed = 3.;
        }
        if (x > targetX - 30)
        {
          speed = 2.;
        }
        if (x > targetX - 20)
        {
          speed = 1.;
        }
      } else if (x > targetX)
      {
        x-= speed;
        if (x < targetX + 40)
        {
          speed = 3.;
        }
        if (x < targetX + 30)
        {
          speed = 2.;
        }
        if (x < targetX + 20)
        {
          speed = 1.;
        }
      }

      if (x == targetX)
      {
        targetX = -1.;
        globalMove = true;
        speed = 40.;
        //playerMoving = false;
      }
    }

    if (globalMove == true)
    {
      if (x < center)
      {
        x+= speed;
        allMover = (speed);
        if (x > center - 40)
        {
          speed = 3.;
        }
        if (x > center - 30)
        {
          speed = 2.;
        }
        if (x > center - 20)
        {
          speed = 1.;
        }
      } else if (x > center)
      {
        x-= speed;
        allMover = (speed * -1);
        if (x < center + 40)
        {
          speed = 3.;
        }
        if (x < center + 30)
        {
          speed = 2.;
        }
        if (x < center + 20)
        {
          speed = 1.;
        }
      }

      if (x == center)
      {
        globalMove = false;
        playerMoving = false;
      }
    }

    if (door2 == true)
    {
      fill(255);
      ellipse(x + 10, y - 20, 10, 10);
    } else if (door5 == true)
    {
      fill(255);
      rect(x + 5, y - 30, 10, 10);
    }

    fill(#ABE8DB);
    rect(x + jump, y + jump, 20, 20);
    if (playerBlink == false)
    {
      float ran = random(1, 100);

      if ((int) ran == 2)
      {
        playerBlink = true;
        blinkUnit = 0;
      }

      fill(0, 90);
      ellipse(x + 10, y + 10, 10, 10);
    } else
    {
      blinkUnit ++;
      fill(0, 90);
      ellipse(x + 10, y + 10, 10, sin(blinkUnit * 0.05) * 10.);
      if (blinkUnit > 10)
      {
        playerBlink = false;
      }
    }
  }



  //jumpAction();
}

void jumpAction()
{
  if (jumping == true)
  {
    playerMoving = true;
    if (jumpStatus == true)
    {
      jump--;
    } else
    {
      jump++;
    }

    if (jump < -20)
    {
      jumpStatus = false;
    }

    if (jump > 0)
    {
      jump = 0;
      jumping = false;
    }
  }
}

// World -2 (PAUSE SCREEN) *******************************************************************************************************
void pause()
{
  if (world == -2)
  {
    if (sa < 1000)
    {
      sa+=40.;
      fill(0);
      ellipse(width / 2, height / 2, sa, sa);
    }
    if (sa > 900)
    {
      currentColor = color(0);
    }
    fill(0);
    ellipse(width / 2, height / 2, sa, sa);

    fill(255);
    textSize(32);
    text("paused", (width / 2) - 57, (height / 2) - 50);
    textSize(12);
    text("PRESS 'P' TO CONTINUE", (width / 2) - 68, height / 2);
  } else
  {
    if (sa < 0)
    {
      if (world != -2)
      {
        sa-=40;
        fill(0);
        ellipse(width / 2, height / 2, sa, sa);
      }
    }
  }
}

// World -1 (MENU SCREEN) *******************************************************************************************************
void menu()
{
  if (world == -1)
  {
    sa = 1000;
    fill(0);
    ellipse(width / 2, height / 2, sa, sa);

    fill(255);
    textSize(32);
    text("blinken", (width / 2) - 57, (height / 2) - 25);
    textSize(12);
    text("PRESS 'E' TO START", (width / 2) - 55, (height / 2));

    // Draw Character
    fill(#ABE8DB);
    rect(width/2 - 10, height/2 - 105, 20, 20);

    if (playerBlink == false)
    {
      float ran = random(1, 100);

      if ((int) ran == 2)
      {
        playerBlink = true;
        blinkUnit = 0;
      }

      fill(#739C93);
      ellipse(width/2 - 10 + 10, height/2 - 105 + 10, 10, 10);
    } else
    {
      blinkUnit ++;
      fill(#739C93);
      ellipse(width/2 - 10 + 10, height/2 - 105 + 10, 10, sin(blinkUnit * 0.05) * 10.);
      if (blinkUnit > 10)
      {
        playerBlink = false;
      }
    }
  } else
  {
    if (sa < 0)
    {
      if (world != 0)
      {
        sa-=40;
        fill(0);
        ellipse(width / 2, height / 2, sa, sa);
      }
    }
  }
}

// World 0 (DEAD SCREEN) *******************************************************************************************************
void dead()
{
  if (world == 0)
  {
    playerMoving = false;
    if (sa < 1000)
    {
      sa+=40.;
      fill(0);
      ellipse(width / 2, height / 2, sa, sa);
    }
    if (sa > 900)
    {
      currentColor = color(0);
    }

    fill(255);
    textSize(32);
    text("you died", (width / 2) - 57, (height / 2) - 50);
    textSize(12);
    text("PRESS 'E' TO RESPAWN", (width / 2) - 55, (height / 2));
  }
}

// World 1 *******************************************************************************************************

void mountains()
{
  if (world == 1 || world == 2 || world == 3 || world == 4)
  {
    fill(255, 20);

    triangle(mountX - 200 - (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05), mountX - (pmouseX * 0.01), mountY - 100 - (pmouseY * 0.05), mountX + 200 - (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05));

    triangle(mountX + 0 + (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05), mountX + 200 + (pmouseX * 0.01), mountY - 100 - (pmouseY * 0.05), mountX + 400 + (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05));

    triangle(mountX + 200 - (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05), mountX + 400 - (pmouseX * 0.01), mountY - 100 - (pmouseY * 0.05), mountX + 600 - (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05));

    triangle(mountX + 400 + (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05), mountX + 600 + (pmouseX * 0.01), mountY - 100 - (pmouseY * 0.05), mountX + 800 + (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05));

    triangle(mountX + 600 - (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05), mountX + 800 - (pmouseX * 0.01), mountY - 100 - (pmouseY * 0.05), mountX + 1000 - (pmouseX * 0.01), mountY + 300 - (pmouseY * 0.05));
  }
}

void watchPoint1_1()
{
  if (world==2)
  {
    if (playerMoving == false)
    {
      if (x > watchPoint1_1X - 20 && x < watchPoint1_1X + 40)
      {
        if (door2 == true)
        {
          door3 = true;
        }
        if (door3 == false && storyEvent1 == false)
        {
          storyEvent1 = true;
          story = true;
          storyStage = 3;
          storyTimer = 0;
        }
      }
    } else
    {
      if (watchPoint1_1DoorSize > 0)
      {
        watchPoint1_1DoorSize -= 10;
        fill(255);
        ellipse(watchPoint1_1X, watchPoint1_1Y - 25, watchPoint1_1DoorSize, watchPoint1_1DoorSize);
      }
    }

    if (door3 == true)
    {
      door2 = false;
      if (watchPoint1_1DoorSize < 500)
      {
        watchPoint1_1DoorSize += 5;
      }
      if (watchPoint1_1DoorSize < 475)
      {
        watchPoint1_1DoorSize += 5;
      }
      fill(255);
      ellipse(watchPoint1_1X, watchPoint1_1Y - 25, watchPoint1_1DoorSize + sin(frameCount * 0.1) *10., watchPoint1_1DoorSize + sin(frameCount * 0.1) *10.);
    }

    fill(255);
    rect(watchPoint1_1X, watchPoint1_1Y - 20, watchPoint1_1Size / 2, watchPoint1_1Size);
  }

  watchPoint1_1X += allMover;
}

void notifications()
{
  if (notifSwitch == true)
  {

    if (notifY > 420)
    {
      notifY -= 2;
    }

    notifTimer++;
    if (notifTimer == 250)
    {
      notifSwitch = false;
      notifTimer = 0;
    }

    if (notif == 1)
    {
      fill(255);
      textSize(18);
      text("Unlocked a Portalway!", (width / 2) - 135, notifY + 40);
    }

    if (notif == 2)
    {
      fill(255);
      textSize(18);
      text("A key has been found!", (width / 2) - 135, notifY + 40);
    }

    if (notif == 3)
    {
      fill(255);
      textSize(18);
      text("He needs food.", (width / 2) - 135, notifY + 40);
    }

    if (notif == 4)
    {
      fill(255);
      textSize(18);
      text("Found an apple!", (width / 2) - 135, notifY + 40);
    }

    if (notif == 5)
    {
      fill(255);
      textSize(18);
      text("Kill the boss!", (width / 2) - 135, notifY + 40);
    }

    if (notif == 6)
    {
      fill(255);
      textSize(18);
      text("Victorious!", (width / 2) - 135, notifY + 40);
    }

    fill(255, 50);
    rect((width / 2) - 200, notifY, 400, 60);
    fill(0, 50);
    ellipse(width / 2 - 170, notifY + 30, 40, 40);
    fill(255);
    textSize(32);
    text("!", (width / 2) - 175, notifY + 40);
  } else
  {
    if (notifY < 480)
    {
      notifY += 2;
      fill(255, 50);
      rect((width / 2) - 200, notifY, 400, 60);
      fill(0, 50);
      ellipse(width / 2 - 170, notifY + 30, 40, 40);
      fill(255);
      textSize(32);
      text("!", (width / 2) - 175, notifY + 40);
    }
  }
}

void box1()
{
  if (world == 1)
  {
    if (door1 == true)
    {
      if (box1Size < 50)
      {
        box1Size += 1;
        fill(255);
        rect(box1X + 15, box1Y - 50 + sin(frameCount * 0.1) * 10, 20 - (box1Size / 2.5), 20 - (box1Size / 2.5));
      }
      if (playerMoving == false)
      {
        if (x > box1X - 20 && x < box1X + 50)
        {
          doorContact = true;
          if (box1DoorSize < 150)
          {
            box1DoorSize += 5;
          }
          if (box1DoorSize < 200)
          {
            box1DoorSize += 5;
          }
          fill(world2Color);
          ellipse(box1X, box1Y - 25, box1DoorSize + sin(frameCount * 0.1) *10., box1DoorSize + sin(frameCount * 0.1) *10.);
          hoverColor = color(world2Color);
          if (fillr == true)
          {
            box1DoorSize += 20;
            if (box1DoorSize == 1000)
            {
              currentColor = hoverColor;
              fillr = false;
              box1DoorSize = 0;
              world = 2;
            }
          }
        }
      } else
      {
        doorContact = false;
        if (box1DoorSize > 0)
        {
          box1DoorSize -= 10;
          fill(world2Color);
          ellipse(box1X, box1Y - 25, box1DoorSize, box1DoorSize);
        }
      }

      fill(255);
      rect(box1X, box1Y - 30, box1Size, box1Size);
    } else
    {
      // Player Detection
      if (x <= box1X + 50 && x + 20 >= box1X)
      {
        // Unlock a door
        if (door1 == false)
        {
          door1 = true;
          story = true;
          storyTimer = 0;
        }
      }
      fill(255);
      rect(box1X + 15, box1Y - 50 + sin(frameCount * 0.1) * 10, 20, 20);
    }
  } else
  {
    if (box1Size > 0)
    {
      box1Size -= 5;
      fill(255);
      rect(box1X, box1Y - 30, box1Size, box1Size);
    }
  }

  box1X += allMover;
}

void spikeEngine()
{
  if (world == 1 || world == 2 || world == 3)
  {
    if (spikeDirection == true)
    {
      spike1Y-= spike1Acc;
      spike1Acc *= 1.5;
    } else
    {
      if (spike1Y > -35)
      {
        spikeCanDie = false;
      }

      if (spike1Y < 0)
      {
        spike1Y++;
      } else
      {
        float ran = random(0, 100);
        if ((int) ran == 2)
        {
          spikeDirection = true;
        }
      }
    }

    if (spike1Y < -40)
    {
      spikeCanDie = true;
      spikeDirection = false;
      spike1Acc = 1;
    }
  }
  spike1X += allMover;
}

void spike1(float spikeXMulti)
{
  if (world == 1)
  {
    fill(255);
    triangle(spikeXMulti - 10, 260, spikeXMulti, 260 + spike1Y, spikeXMulti + 10, 260);

    if (spikeCanDie == true)
    {
      if (spikeXMulti - 10 <= x + 20 && spikeXMulti + 10 >= x)
      {
        world = 0;
      }
    }
  }
}

void spike2(float spikeXMulti)
{
  if (world == 2)
  {
    fill(255);
    triangle(spikeXMulti - 10, 260, spikeXMulti, 260 + spike1Y, spikeXMulti + 10, 260);

    if (spikeCanDie == true)
    {
      if (spikeXMulti - 10 <= x + 20 && spikeXMulti + 10 >= x)
      {
        world = 0;
      }
    }
  }
}

void evilBallEngine()
{
  if (world == 1 || world == 2 || world == 3)
  {
    if (eb1JumpDir == false)
    {
      eb1YV*= 1.1;
      eb1Y+= eb1YV;
      if (eb1Y >= 245)
      {
        eb1JumpDir = true;
      }
    } else if (eb1JumpDir == true)
    {
      eb1YV /= 1.1;
      if (eb1YV <= 1)
      {
        eb1YV = 1.;
      }
      eb1Y -= eb1YV;
      if (eb1Y <= 100)
      {
        eb1JumpDir = false;
      }
    }

    if (eb1Size < 30)
    {
      eb1Size += 5;
    }

    if (world == 1)
    {
      if (eb1Size < 30)
      {
        eb1Size+=5;
      }
    } else if (world == 2)
    {
      if (eb2Size < 30)
      {
        eb2Size+=5;
      }
    } else if (world == 3)
    {
      if (eb3Size < 30)
      {
        eb3Size+=5;
      }
    }
  }
  eb1X += allMover;
}

void evilBall1(float ebxMulti)
{

  if (world == 1)
  {
    fill(255);
    ellipse(ebxMulti, eb1Y, eb1Size, eb1Size);

    if (x > ebxMulti - 40 && x < ebxMulti + 20)
    {
      if (eb1Y >= y)
      {
        sa = 1;
        world = 0;
      }
    }
  } else
  {
    if (eb1Size > 0)
    {
      eb1Size-=5;
      fill(255);
      ellipse(ebxMulti, eb1Y, eb1Size, eb1Size);
    }
  }
}

void evilBall3(float ebxMulti)
{

  if (world == 3)
  {
    fill(255);
    ellipse(ebxMulti, eb1Y, eb3Size, eb3Size);

    if (x > ebxMulti - 40 && x < ebxMulti + 20)
    {
      if (eb1Y >= y)
      {
        sa = 1;
        world = 0;
      }
    }
  } else
  {
    if (eb3Size > 0)
    {
      eb3Size-=5;
      fill(255);
      ellipse(ebxMulti, eb1Y, eb3Size, eb3Size);
    }
  }
}

void stalker1()
{
  if (world == 2)
  {
    fill(255);
    rect(stalkerX, stalkerY - 80, stalkerSize / 2, stalkerSize);
    rect(stalkerX - 30, stalkerY - 60 + (sin(frameCount * 0.05) * 5), stalkerSize / 2, stalkerSize / 2);
    rect(stalkerX + 5, stalkerY - 20, stalkerSize / 16, stalkerSize / 2);
    rect(stalkerX + 30, stalkerY - 20, stalkerSize / 16, stalkerSize / 2);

    if (stalkerBlink == false)
    {
      float ran = random(1, 100);

      if ((int) ran == 2)
      {
        stalkerBlink = true;
        stalkerBlinkUnit = 0;
      }

      fill(0, 90);
      ellipse(stalkerX - 20, stalkerY - 30 + (sin(frameCount * 0.05) * 5), 10, 10);
    } else
    {
      stalkerBlinkUnit ++;
      fill(0, 90);
      ellipse(stalkerX - 20, stalkerY - 30 + (sin(frameCount * 0.05) * 5), 10, sin(stalkerBlinkUnit * 0.05) * 10.);
      if (stalkerBlinkUnit > 10)
      {
        stalkerBlink = false;
      }
    }
  }
  stalkerX += allMover;
}

void build1_1()
{
  if (world == 2) // WORLD 1 ++++++++++++++++++++++++++++++++++++++++++++++
  {
    if (build1_1Size < 80)
    {
      build1_1Size += 5;
    }

    if (playerMoving == false)
    {
      if (x > build1_1X - 20 && x < build1_1X + 80) 
      {
        doorContact = true;
        if (build1_1DoorSize < 200)
        {
          build1_1DoorSize += 5;
        }
        if (build1_1DoorSize < 220)
        {
          build1_1DoorSize += 5;
        }
        fill(0, 50);
        rectMode(CENTER);
        rect(build1_1X + (build1_1Size / 2), build1_1Y - 4, build1_1DoorSize + (sin(frameCount * 0.1) *20.), 48);
        rectMode(CORNER);
        hoverColor = color(0, 50);
        if (fillr == true)
        {
          build1_1DoorSize += 20;
          if (build1_1DoorSize  == 1000)
          {
            build1_1DoorSize = 1000;
            fillr = false;
            world = 2.1;
          }
        }
      }
    } else
    {
      doorContact = false;
      if (build1_1DoorSize > 0)
      {
        build1_1DoorSize -= 20;
        fill(0, 50);
        rectMode(CENTER);
        rect(build1_1X + (build1_1Size / 2), build1_1Y - 4, build1_1DoorSize, 48);
        rectMode(CORNER);
      }
    }

    if (fillr == false)
    {
      if (build1_1DoorSize > 220)
      {
        build1_1DoorSize -= 20;
      }
    }


    fill(255);
    rect(build1_1X, build1_1Y - 140, (build1_1Size), build1_1Size * 2);
    rect(build1_1X + 20, (build1_1Y - 230) + (sin(frameCount * 0.05) * 5.), (build1_1Size / 2), build1_1Size);
  } else if (world == 2.1) // WORLD 1.1 ++++++++++++++++++++++++++++++++++++++++++++++
  { 
    // Get a Key
    if (door2 == false)
    {
      door2 = true;
      notif = 2;
      notifSwitch = true;
    }

    fill(0, 50);
    rectMode(CENTER);
    rect(build1_1X + (build1_1Size / 2), build1_1Y - 4, build1_1DoorSize, 48);
    rectMode(CORNER);

    if (build1_1Size > 0)
    {
      build1_1Size -= 5;
      fill(255);
      rect(build1_1X, build1_1Y - 140, (build1_1Size), build1_1Size * 2);
      rect(build1_1X + 20, (build1_1Y - 230), (build1_1Size / 2), build1_1Size);
    }
  } else
  {
    if (build1_1Size > 0)
    {
      build1_1Size -= 20;
      fill(255);
      rect(build1_1X, build1_1Y - 140, (build1_1Size), build1_1Size * 2);
      rect(build1_1X + 20, (build1_1Y - 230), (build1_1Size / 2), build1_1Size);
    }
  }

  build1_1X += allMover;
}

// World 2 *******************************************************************************************************

//A52445
//F3921E //B36C16
//CD4544
//470B37
//05C096
//8D7D4A //048D6E //024032

void box3()
{
  if (world == 2 && door3 == true)
  {
    box3Size = 50;
    if (playerMoving == false)
    {
      if (x > box3X - 20 && x < box3X + 50)
      {
        doorContact = true;
        if (box3DoorSize < 150)
        {
          box3DoorSize += 5;
        }
        if (box3DoorSize < 200)
        {
          box3DoorSize += 5;
        }
        fill(#05C096);
        ellipse(box3X, box3Y - 25, box3DoorSize + sin(frameCount * 0.1) *10., box3DoorSize + sin(frameCount * 0.1) *10.);
        hoverColor = color(#05C096);
        if (fillr == true)
        {
          box3DoorSize += 20;
          if (box3DoorSize == 1000)
          {
            currentColor = hoverColor;
            fillr = false;
            box3DoorSize = 0;
            world = 3;
            notifSwitch = true;
            notif = 5;
            notifTimer = 0;
          }
        }
      }
    } else
    {
      doorContact = false;
      if (box3DoorSize > 0)
      {
        box3DoorSize -= 10;
        fill(#05C096);
        ellipse(box3X, box3Y - 25, box3DoorSize, box3DoorSize);
      }
    }

    fill(world2Color);
    rect(box3X, box3Y - 30, box3Size, box3Size);
  } else
  {
    if (box3Size > 0)
    {
      box3Size -= 5;
      fill(world2Color);
      rect(box3X, box3Y - 30, box3Size, box3Size);
    }
  }

  box3X += allMover;
}

void box2()
{
  if (world == 2)
  {
    if (door4 == true)
    {
      if (box2Size < 50)
      {
        box2Size += 1;
        fill(255);
        rect(box2X + 15, box2Y - 50 + sin(frameCount * 0.1) * 10., 20 - (box2Size / 2.5), 20 - (box2Size / 2.5));
      }
      if (playerMoving == false)
      {
        if (x > box2X - 20 && x < box2X + 50)
        {
          doorContact = true;
          if (box2DoorSize < 150)
          {
            box2DoorSize += 5;
          }
          if (box2DoorSize < 200)
          {
            box2DoorSize += 5;
          }
          fill(world1Color);
          ellipse(box2X, box2Y - 25, box2DoorSize + sin(frameCount * 0.1) *10., box2DoorSize + sin(frameCount * 0.1) *10.);
          hoverColor = color(world1Color);
          if (fillr == true)
          {
            box2DoorSize += 20;
            if (box2DoorSize == 1000)
            {
              currentColor = hoverColor;
              fillr = false;
              box2DoorSize = 0;
              world = 1;
            }
          }
        }
      } else
      {
        doorContact = false;
        if (box2DoorSize > 0)
        {
          box2DoorSize -= 10;
          fill(world1Color);
          ellipse(box2X, box2Y - 25, box2DoorSize, box2DoorSize);
        }
      }

      fill(255);
      rect(box2X, box2Y - 30, box2Size, box2Size);
    } else
    {
      // Player Detection
      if (x <= box2X + 50 && x + 20 >= box2X)
      {
        // Unlock a door
        if (door4 == false)
        {
          door4 = true;
          notifSwitch = true;
          notif = 1;
        }
      }
      fill(255);
      rect(box2X + 15, box2Y - 50 + sin(frameCount * 0.1) * 10., 20, 20);
    }
  } else
  {
    if (box2Size > 0)
    {
      box2Size -= 5;
      fill(255);
      rect(box2X, box2Y - 30, box2Size, box2Size);
    }
  }

  box2X += allMover;
}

void apple1()
{
  if (world == 2)
  {
    if (stalkerApple == false)
    {
      if (x < apple1X + 10)
      {
        notifSwitch = true;
        notif = 4;
        notifTimer = 0;
        stalkerApple = true;
        door5 = true;
      }
      rect(apple1X, apple1Y, 10, 10);
    }
  }
  apple1X += allMover;
}

// World 3 *******************************************************************************************************

void boss()
{
  if (world == 3)
  {
    fill(0, 30);
    ellipse(width / 2, height / 2 - 110, 200 + (sin(frameCount * 0.05)*50.), 200 + (sin(frameCount * 0.05)*50.));

    fill(#048D6E);
    rect(width / 2 - 100, height / 2 - 180, bossSize, bossSize);

    //Eyes
    if (bossBlink == false)
    {
      float ran = random(1, 100);

      if ((int) ran == 2)
      {
        bossBlink = true;
        bossBlinkUnit = 0;
      }

      fill(0, 90);
      if (bossHealth > 2)
      {
        ellipse(bossX + 35, bossY + 170, 50, 50);
      }
      if (bossHealth > 1)
      {
        ellipse(bossX + 165, bossY + 170, 50, 50);
      }
      if (bossHealth > 0)
      {
        ellipse(bossX + 100, bossY + 120, 50, 50);
      }
    } else
    {
      bossBlinkUnit++;
      fill(0, 90);
      if (bossHealth > 2)
      {
        ellipse(bossX + 35, bossY + 170, 50, sin(bossBlinkUnit * 0.05) * 50.);
      }
      if (bossHealth > 1)
      {
        ellipse(bossX + 165, bossY + 170, 50, sin(bossBlinkUnit * 0.05) * 50.);
      }
      if (bossHealth > 0)
      {
        ellipse(bossX + 100, bossY + 120, 50, sin(bossBlinkUnit * 0.05) * 50.);
      }
      if (bossBlinkUnit > 10)
      {
        bossBlink = false;
      }
    }

    if (bossHealth > 0)
    {

      // Fist
      if (fistSmash == false)
      {
        if (fistY > 40)
        {
          fistY-=4;
        } else
        {
          float ran = random(0, 100);
          if ((int) ran == 2)
          {
            fistSmash = true;
            fistAcc = 1;
          }
          bossSwitchTriggered = false;
        }
        if (x - 20 > fistX)
        {
          fistX += 4.;
        } else if (x - 10 < fistX)
        {
          fistX -= 4.;
        }
      } else
      {
        if (fistY >= height/2 - 30)
        {
          fistSmash = false;
        } else
        {
          fistY+=1;
          fistY+=fistAcc;
        }
        fistAcc *= 1.1;

        // Collision
        if (x <= fistX + 50 && x + 20 >= fistX)
        {
          if (y <= fistY + 50 && y  >= fistY)
          {
            fistSmash = false;
            world = 0;
          }
        }

        if (bossSwitchX <= fistX + 50 && bossSwitchX + 50 >= fistX)
        {
          if (bossSwitchTriggered == false)
          {
            if (fistY >= height/2 - 30)
            {
              bossHealth--;
              bossSwitchTriggered = true;
              if (bossHealth == 0)
              {
                //world = 4;
              }
            }
          }
        }
      }
    }

    fill(#024032);
    rect(fistX, fistY, 50, 50);
    rect(fistX - 10, fistY + 10, 30, 30);
  }
}

void bossSwitch()
{
  if (world == 3 && bossHealth > 0)
  {
    if (bossSwitchDir == false)
    {
      if (bossSwitchX > 150)
      {
        if (bossSwitchSize > 0)
        {
          bossSwitchSize--;
          if (bossSwitchTriggered == true)
          {
            fill(#F3921E);
          } else
          {
            fill(#048D6E);
          }
          rect(bossSwitchX, 240, 50, bossSwitchSize);
        } else
        {
          bossSwitchX = 150;
        }
      } else
      {
        if (bossSwitchSize < 20)
        {
          bossSwitchSize++;
        } else
        {
          float ran = random(0, 200);
          if ((int) ran == 4)
          {
            bossSwitchDir = true;
          }
        }

        if (bossSwitchTriggered == true)
        {
          fill(#F3921E);
        } else
        {
          fill(#048D6E);
        }
        rect(bossSwitchX, 240 - (sin(frameCount * 0.1) * 5.), 50, bossSwitchSize + (sin(frameCount * 0.1) * 5.));
      }
    } else if (bossSwitchDir == true)
    {
      if (bossSwitchX < 520)
      {
        if (bossSwitchSize > 0)
        {
          bossSwitchSize--;
          if (bossSwitchTriggered == true)
          {
            fill(#F3921E);
          } else
          {
            fill(#048D6E);
          }
          rect(bossSwitchX, 240, 50, bossSwitchSize);
        } else
        {
          bossSwitchX = 520;
        }
      } else
      {
        if (bossSwitchSize < 20)
        {
          bossSwitchSize++;
        } else
        {
          float ran = random(0, 200);
          if ((int) ran == 4)
          {
            bossSwitchDir = false;
          }
        }
        if (bossSwitchTriggered == true)
        {
          fill(#F3921E);
        } else
        {
          fill(#048D6E);
        }
        rect(bossSwitchX, 240 - (sin(frameCount * 0.1) * 5.), 50, bossSwitchSize + (sin(frameCount * 0.1) * 5.));
      }
    }
  }
}

void bossExplosion()
{
  if (world == 3)
  {
    if (bossHealth <= 0)
    {
      notifSwitch = true;
      notif = 6;
      notifTimer = 0;
      if (explosionStage > 7)
      {
        explosionSize += 10;
        if (explosionSize > 1000)
        {
          world = 4;
          story = true;
          storyStage = 4;
          storyTimer = 0;
          sa = 1000;
        }
      }
      if (explosionStage > 6)
      {
        fill(world2Color);
        ellipse(width/2, height/2, explosionSize * 4.5, explosionSize * 4.5);
      }
      if (explosionStage > 5)
      {
        fill(#B36C16);
        ellipse(width/2, height/2, explosionSize * 4, explosionSize * 4);
      }
      if (explosionStage > 4)
      {
        fill(world2Color);
        ellipse(width/2, height/2, explosionSize * 3.5, explosionSize * 3.5);
      }
      if (explosionStage > 3)
      {
        fill(#B36C16);
        ellipse(width/2, height/2, explosionSize * 3, explosionSize * 3);
      }
      if (explosionStage > 2)
      {
        fill(world2Color);
        ellipse(width/2, height/2, explosionSize * 2.5, explosionSize * 2.5);
      }
      if (explosionStage > 1)
      {
        fill(#B36C16);
        ellipse(width/2, height/2, explosionSize * 2, explosionSize * 2);
      }
      if (explosionStage > 0)
      {
        fill(world2Color);
        ellipse(width/2, height/2, explosionSize * 1.5, explosionSize * 1.5);
      }
      if (explosionStage > -1)
      {
        fill(0);
        ellipse(width/2, height/2, explosionSize, explosionSize);
      }

      explosionTimer++;

      if (explosionTimer > 25)
      {
        explosionStage = 1;
      }
      if (explosionTimer > 50)
      {
        explosionStage = 2;
      }
      if (explosionTimer > 75)
      {
        explosionStage = 3;
      }
      if (explosionTimer > 100)
      {
        explosionStage = 4;
      }
      if (explosionTimer > 125)
      {
        explosionStage = 5;
      }
      if (explosionTimer > 150)
      {
        explosionStage = 6;
      }
      if (explosionTimer > 175)
      {
        explosionStage = 7;
      }
      if (explosionTimer > 225)
      {
        explosionStage = 8;
      }
    }
  }
}

// World 4 *******************************************************************************************************
void world4()
{
  if (world == 4)
  {
    if (sa > 0)
    {
      sa-=40.;
      fill(0);
      ellipse(width / 2, height / 2, sa, sa);
    }
  }
}

void mousePressed()
{
  if (world == 1 || world == 2 || world == 3 || world == 4)
  {
    if (playerMoving == false)
    {
      targetX = mouseX;
      playerMoving = true;
      speed = 5;
      if (mouseY < 100)
      {
        jumping = true;
        jumpStatus = true;
      }
    }
  }
}

void keyPressed()
{
  if (key == 'e' || key == 'E')
  {
    if (playerMoving == false)
    {
      if (world == 0)
      {
        sa = 0;
        world = 1;
        currentColor = world1Color;
        reset();
      }
      if (world == -1)
      {
        sa = 1000;
        world = 1;
        currentColor = world1Color;
        //story = true;
        //storyStage = 1;
      }
      if (world == 2.1)
      {
        fillr = false;
        world = 2;
        doorContact = false;
      }
      if (doorContact == true)
      {
        fillr = true;
        doorContact = false;
      }
    } else if (key == 'p' || key == 'P' )
    {
      if (world > 0)
      {
        worldSave = world;
        world = -2;
        sa = 0;
      } else if (world == -2)
      {
        sa = 0;
        world = worldSave;
      }
    }
  }
}