Catch One Direction

welcome

For my final project, I went further with the One Direction game I have been working on for the past few weeks! It now has four levels, a start screen, and end screen. The game can also be restarted by pressing ‘r’ and if the user chooses to leave the game before they reach the end, they can press ‘q’ and it will bring them to the quit screen (different from the winning end screen). For music, I made a mashup of a handful of their songs. The user doesn’t have to just listen to one song! I was going to add some sort of sound effect for when the crazy fan catches one of the boys… but as the number of them grew.. I could feel my brain wanted to explode from that number of repetitive sounds.

Also, if you are curious about which songs I used for the background track:
“One Way or Another (Teenage Kicks)”
What Makes You Beautiful
Kiss You
Live While We’re Young
Best Song Ever
Happily (one of my personal favorites)

Level One:
Catch1D_L1
This is the slowest level with only one of each member. I also decided to put the instructions on this page with a transparent background with mildly opaque instructions (made in Photoshop).

Level Two:
Catch1D_L2

Level Three:
Catch1D_L3

Level Four // Bonus Level:
Catch1D_L4

Quit Screen (in case you don’t have the patience to get to the end!):

quit

 

End Screen:
end

 

 

————CODE ————

import ddf.minim.*;
import processing.serial.*;

Minim minim;
AudioPlayer player;
Serial myPort;

PImage welcomePic;
PImage endPic;
PImage logo;
PImage quit;
PImage instructions;

Member [] oneDirection = new Member[5];
Member [] levelTwo = new Member[10];
Member [] levelThree = new Member[25];
Member [] bonusLevel = new Member[50];

float xPos, yPos;
float xSpeed, ySpeed;
PImage harry, liam, louis, niall, zayn; 
PImage [] boy = {harry, liam, louis, niall, zayn };
boolean overBoy;

CrazyFan fan;
PImage crazyFan;
float fanXpos, fanYpos;
float fanXspeed, fanYSpeed;

boolean start, level_One,level_Two, level_Three, bonus_Level, endGame;
boolean quitGame;

void setup(){
  size(800,600); 

  welcomePic = loadImage("welcome.png");
  endPic = loadImage("end.png");
  logo = loadImage("logo.png");
  quit = loadImage("quit.png");
  instructions = loadImage("instructions.png");

  start=false;

  level_One=true;
  level_Two=true;
  level_Three=true;
  bonus_Level=true;

  endGame=false;
  quitGame=false;

  crazyFan = loadImage("crazyFan.png");
  harry = loadImage("Harry_Styles.png");
  liam = loadImage("Liam_Payne.png");
  louis = loadImage("Louis_Tomlinson.png");
  niall = loadImage("Niall_Horan.png");
  zayn = loadImage("Zayn_Malik.png");

  fan = new CrazyFan(crazyFan, fanXpos, fanYpos);
  oneDirection[0] = new Member(harry, xPos, yPos);
  oneDirection[1] = new Member(liam, xPos, yPos);
  oneDirection[2] = new Member(louis, xPos, yPos);
  oneDirection[3] = new Member(niall, xPos, yPos);
  oneDirection[4] = new Member(zayn, xPos, yPos);

 minim = new Minim(this);
 player = minim.loadFile("mashup.mp3");
 player.play();

  //fill levelTwo
  for(int i=0; i<2; i++){
      levelTwo[5*i] = new Member(harry, xPos, yPos);
      levelTwo[5*i+1] = new Member(liam, xPos, yPos);
      levelTwo[5*i+2] = new Member(louis, xPos, yPos);
      levelTwo[5*i+3] = new Member(niall, xPos, yPos);
      levelTwo[5*i+4] = new Member(zayn, xPos, yPos);
    }

   //fill levelThree   
   for(int i=0; i<5; i++){
      levelThree[5*i] = new Member(harry, xPos, yPos);
      levelThree[5*i+1] = new Member(liam, xPos, yPos);
      levelThree[5*i+2] = new Member(louis, xPos, yPos);
      levelThree[5*i+3] = new Member(niall, xPos, yPos);
      levelThree[5*i+4] = new Member(zayn, xPos, yPos);
    }

   //fill bonusLevel  
   for(int i=0; i<10; i++){
      bonusLevel[5*i] = new Member(harry, xPos, yPos);
      bonusLevel[5*i+1] = new Member(liam, xPos, yPos);
      bonusLevel[5*i+2] = new Member(louis, xPos, yPos);
      bonusLevel[5*i+3] = new Member(niall, xPos, yPos);
      bonusLevel[5*i+4] = new Member(zayn, xPos, yPos);
    }

}

void draw(){ 

  if(endGame==false){
     background(255);
      if(start==false){
            image(welcomePic,0,0);
          }
     image(logo,0,0);
  }  

  levelUp();

  if (endGame==true){
    background(255);
    image(endPic,0,0);
    if (quitGame==true){
      image(quit,0,0);
    }
  }

}  

//----------------LEVEL ONE----------------
void levelOneFreeze(){
  for (int i = 0; i < 5; i ++){
     if (dist(oneDirection[i].xPos, oneDirection[i].yPos, fan.fanXpos, fan.fanYpos)<= 75){
       oneDirection[i].overBoy=true;
       oneDirection[i].freezeBoy();
      }//dist
   }
}
void levelOne(){
  for (int i = 0; i < 5; i ++){
      oneDirection[i].positionChange();
      oneDirection[i].levelOneDrawLad();
  }
  fan.positionChange();
  fan.levelOneDrawFan();
}

//----------------LEVEL TWO----------------
void levelTwoFreeze(){
  for (int i = 0; i < 10; i ++){
     if (dist(levelTwo[i].xPos, levelTwo[i].yPos, fan.fanXpos, fan.fanYpos)<= 50){
       levelTwo[i].overBoy=true;
       levelTwo[i].freezeBoyTwo();
      }//dist
   }
}
void levelTwo(){
  for (int i = 0; i < 10; i ++){
      levelTwo[i].positionChangeTwo();
      levelTwo[i].levelTwoDrawLad();
  }
  fan.positionChange();
  fan.levelTwoDrawFan();
}

//----------------LEVEL THREE----------------
void levelThreeFreeze(){
  for (int i = 0; i < 25; i ++){
     if (dist(levelThree[i].xPos, levelThree[i].yPos, fan.fanXpos, fan.fanYpos)<= 40){
       levelThree[i].overBoy=true;
       levelThree[i].freezeBoyThree();
      }//dist
   }
}
void levelThree(){
  for (int i = 0; i < 25; i ++){
      levelThree[i].positionChange();
      levelThree[i].levelThreeDrawLad();
  }
  fan.positionChange();
  fan.levelThreeDrawFan();
}

//----------------BONUS LEVEL----------------
void bonusLevelFreeze(){
  for (int i = 0; i < 50; i ++){
     if (dist(bonusLevel[i].xPos, bonusLevel[i].yPos, fan.fanXpos, fan.fanYpos)<= 40){
       bonusLevel[i].overBoy=true;
       bonusLevel[i].freezeBoyBonus();
      }//dist
   }
}
void bonusLevel(){
  for (int i = 0; i < 50; i ++){
      bonusLevel[i].positionChangeBonus();
      bonusLevel[i].bonusLevelDrawLad();
  }
  fan.positionChange();
  fan.bonusLevelDrawFan();
}

//--------------------------------------------

void levelUp(){
  if(start==true){
    if (level_One){
      levelOne();
      image(instructions,0,0);
      if (oneDirection[0].overBoy==true && oneDirection[1].overBoy==true && oneDirection[2].overBoy==true && oneDirection[3].overBoy==true && oneDirection[4].overBoy==true){
        level_One = false;
      }
    }
    else if(level_Two){
      levelTwo();
      if (levelTwo[0].overBoy==true && levelTwo[1].overBoy==true && levelTwo[2].overBoy==true && levelTwo[3].overBoy==true && levelTwo[4].overBoy==true && levelTwo[5].overBoy==true && levelTwo[6].overBoy==true && levelTwo[7].overBoy==true && levelTwo[8].overBoy==true && levelTwo[9].overBoy==true){
            level_Two = false;
          }
       }
    else if(level_Three){  
       levelThree();
       if (levelThree[0].overBoy==true && levelThree[1].overBoy==true && levelThree[2].overBoy==true && levelThree[3].overBoy==true && levelThree[4].overBoy==true && levelThree[5].overBoy==true && levelThree[6].overBoy==true && levelThree[7].overBoy==true && levelThree[8].overBoy==true && levelThree[9].overBoy==true && levelThree[10].overBoy==true && levelThree[11].overBoy==true && levelThree[12].overBoy==true && levelThree[13].overBoy==true && levelThree[14].overBoy==true && levelThree[15].overBoy==true && levelThree[16].overBoy==true && levelThree[17].overBoy==true && levelThree[18].overBoy==true && levelThree[19].overBoy==true && levelThree[20].overBoy==true && levelThree[21].overBoy==true && levelThree[22].overBoy==true && levelThree[23].overBoy==true && levelThree[24].overBoy==true){
           level_Three = false;
        }
    }
   else if(bonus_Level){
      bonusLevel();
       if (bonusLevel[0].overBoy==true && bonusLevel[1].overBoy==true && bonusLevel[2].overBoy==true && bonusLevel[3].overBoy==true && bonusLevel[4].overBoy==true && bonusLevel[5].overBoy==true && bonusLevel[6].overBoy==true && bonusLevel[7].overBoy==true && bonusLevel[8].overBoy==true && bonusLevel[9].overBoy==true && bonusLevel[10].overBoy==true && bonusLevel[11].overBoy==true && bonusLevel[12].overBoy==true && bonusLevel[13].overBoy==true && bonusLevel[14].overBoy==true && bonusLevel[15].overBoy==true && bonusLevel[16].overBoy==true && bonusLevel[17].overBoy==true && bonusLevel[18].overBoy==true && bonusLevel[19].overBoy==true && bonusLevel[20].overBoy==true && bonusLevel[21].overBoy==true && bonusLevel[22].overBoy==true && bonusLevel[23].overBoy==true && bonusLevel[24].overBoy==true && bonusLevel[25].overBoy==true && bonusLevel[26].overBoy==true && bonusLevel[27].overBoy==true && bonusLevel[28].overBoy==true && bonusLevel[29].overBoy==true && bonusLevel[30].overBoy==true && bonusLevel[31].overBoy==true && bonusLevel[32].overBoy==true && bonusLevel[33].overBoy==true && bonusLevel[34].overBoy==true && bonusLevel[35].overBoy==true && bonusLevel[36].overBoy==true && bonusLevel[37].overBoy==true && bonusLevel[38].overBoy==true && bonusLevel[39].overBoy==true && bonusLevel[40].overBoy==true && bonusLevel[41].overBoy==true && bonusLevel[42].overBoy==true && bonusLevel[43].overBoy==true && bonusLevel[44].overBoy==true && bonusLevel[45].overBoy==true && bonusLevel[46].overBoy==true && bonusLevel[47].overBoy==true && bonusLevel[48].overBoy==true && bonusLevel[49].overBoy==true){
          bonus_Level = false;
          endGame = true; 
      }
    }
  }
}//end levelUp

void keyPressed(){
  if (key == 'c'){
    levelOneFreeze();
    if(level_One==false && level_Two==true && level_Three==true && bonus_Level==true){
      levelTwoFreeze();
    }
    if(level_One==false && level_Two==false && level_Three==true && bonus_Level==true){
      levelThreeFreeze();
    }
    if(level_One==false && level_Two==false && level_Three==false && bonus_Level==true){
      bonusLevelFreeze();
    }

  }
  //back to the beginning
  if (key == 'r'){   
    start=false;
    level_One=true;
    level_Two=true;
    level_Three=true;
    bonus_Level=true;
    endGame=false;
    quitGame=false;
  }
  //skip to levelTwo
  if (key == 'd'){ 
    start = true;
    level_One=false;
    level_Two=true;
    level_Three=true;
    bonus_Level=true;
    endGame=false;
  }
  //skip to levelThree
  if (key == 'f'){ 
    start = true;
    level_One=false;
    level_Two=false;
    level_Three=true;
    bonus_Level=true;
    endGame=false;
  }
  //skip to bonusLevel
  if (key == 'g'){ 
    start = true;
    level_One=false;
    level_Two=false;
    level_Three=false;
    bonus_Level=true;
    endGame=false;
  }
  if (key == 'm'){
    start = true;
  }
  if (key == 'q'){
    level_One=false;
    level_Two=false;
    level_Three=false;
    bonus_Level=false;
    endGame=true;
    quitGame=true;
  }
}

Member Class:

class Member{
    float xPos = random(0,width-75);
    float yPos = random(0,height-150);
    float xSpeed, ySpeed;
    PImage [] boy = {harry, liam, louis, niall, zayn };
    PImage lad, _lad;
    boolean overBoy;
    float _xSpeed, _ySpeed;

    //Constructor
    Member(PImage lad, float xPos, float yPos){
       xSpeed = random (3.0, 5.0);
       ySpeed = random (3.0, 5.0);
       _lad = lad;
       overBoy = false;
    }//constructor  

//----------------LEVEL ONE----------------    
    void positionChange(){
      if(xPos >= width - 75|| xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 150 || yPos<0){
        ySpeed *= -1;
      } 
      xPos += xSpeed;
      yPos += ySpeed;
    }
    void levelOneDrawLad(){
        xPos += xSpeed;
        yPos += ySpeed; 
        _lad.resize(0,150);
        image(_lad, xPos, yPos);
    }//draw the boys
    void freezeBoy(){
      if (overBoy){
         xSpeed = 0;
         ySpeed = 0; 
       }
     }//freezeBoy

//----------------LEVEL TWO----------------    
   void positionChangeTwo(){
      if(xPos >= width - 75|| xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 100 || yPos<0){
        ySpeed *= -1;
      } 
      xPos += xSpeed;
      yPos += ySpeed;
    }
    void freezeBoyTwo(){
      if (overBoy){
         xSpeed = 0;
         ySpeed = 0; 
       }
     }//freezeBoy
    void levelTwoDrawLad(){
        xPos += 1.25*xSpeed;
        yPos += 1.25*ySpeed; 
        _lad.resize(0,120);
        image(_lad, xPos, yPos);
    }//draw the boys

//----------------LEVEL THREE----------------
   void positionChangeThree(){
      if(xPos >= width - 50|| xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 25 || yPos<0){
        ySpeed *= -1;
      } 
      xPos += xSpeed;
      yPos += ySpeed;
    } 
    void freezeBoyThree(){
      if (overBoy){
         xSpeed = 0;
         ySpeed = 0; 
       }
     }//freezeBoy
    void levelThreeDrawLad(){
        xPos += 1.5*xSpeed;
        yPos += 1.5*ySpeed; 
        _lad.resize(0,100);
        image(_lad, xPos, yPos);
    }//draw the boys

//----------------BONUS LEVEL----------------

   void positionChangeBonus(){
      if(xPos >= width - 45 || xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 30 || yPos<0){
        ySpeed *= -1;
      } 
      xPos += 1.75*xSpeed;
      yPos += 1.75*ySpeed;
    }
    void freezeBoyBonus(){
      if (overBoy){
         xSpeed = 0;
         ySpeed = 0; 
       }
     }//freezeBoy
   void bonusLevelDrawLad(){
        xPos += _xSpeed;
        yPos += _ySpeed; 
        _lad.resize(0,75);
        image(_lad, xPos, yPos);
    }//draw the boys

}//member

CrazyFan Class:

class CrazyFan{
    PImage crazyFan, _crazyFan;
    float fanXpos = random(0,width-75);
    float fanYpos = random(0,height-150);
    float fanXspeed = random(3.0, 5.0);
    float fanYspeed = random(3.0, 5.0); 

//Constructor
    CrazyFan(PImage crazyFan, float fanXpos, float fanYpos){
       _crazyFan = crazyFan;
    }//constructor  

   void positionChange(){
        if(fanXpos >= width - 75|| fanXpos<0){
          fanXspeed *= -1;
        }
        if(fanYpos >= height - 140 || fanYpos<0){
          fanYspeed *= -1;
        } 

        fanXpos += fanXspeed;
        fanYpos += fanYspeed;
     }

//----------------LEVEL ONE----------------  

     void levelOneDrawFan(){
      fanXpos += xSpeed;
      fanYpos += ySpeed; 
      _crazyFan.resize(0,150);
      image(_crazyFan, fanXpos, fanYpos);
    }//draw the fan

//----------------LEVEL TWO----------------     

    void levelTwoDrawFan(){
      fanXpos += xSpeed;
      fanYpos += ySpeed; 
      _crazyFan.resize(0,140);
      image(_crazyFan, fanXpos, fanYpos);
    }//draw the fan

//----------------LEVEL TWO----------------     

    void levelThreeDrawFan(){
      fanXpos += xSpeed;
      fanYpos += ySpeed; 
      _crazyFan.resize(0,130);
      image(_crazyFan, fanXpos, fanYpos);
    }//draw the fan

//----------------LEVEL TWO----------------     

    void bonusLevelDrawFan(){
      fanXpos += xSpeed;
      fanYpos += ySpeed; 
      _crazyFan.resize(0,130);
      image(_crazyFan, fanXpos, fanYpos);
    }//draw the fan 

}

 

Leave a Reply