Team:TU Eindhoven/the game

From 2014.igem.org

(Difference between revisions)
Line 36: Line 36:
  <p class="ref-notice">&nbsp;</p>
  <p class="ref-notice">&nbsp;</p>
-
<img src="https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg" alt="">
+
 
<div class="example"><script type="application/processing">
<div class="example"><script type="application/processing">
 +
// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="https://static.igem.org/mediawiki/2014/9/98/Jasper_TU_Eindhoven.jpg, https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg"; */
/* @pjs preload="https://static.igem.org/mediawiki/2014/9/98/Jasper_TU_Eindhoven.jpg, https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg"; */
-
/*
 
-
Programe of iGEM team Eindhoven 2014.
+
PImage img;  // Declare variable "a" of type PImage
-
Head-Programer: Tom Nijhof
+
-
Instructions:
+
void setup() {
-
In order to add new DNA or Levels you only need to add code to this piece (here, making of object), the void Setup() (just below) and the void Loading_images.
+
   size(640, 360);
-
*/
+
   // The image file must be in the data folder of the current sketch
-
int numberOfDNA;
+
   // to load successfully
-
DNAPiece[] dna;
+
   img = loadImage("https://static.igem.org/mediawiki/2014/9/98/Jasper_TU_Eindhoven.jpg");  // Load the image into the program
-
 
+
   img2 = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");   
-
//DNAPiece's
+
-
/*
+
-
To add a new DNA piece you need to make a DNA piece you need to make a new image (PImage)
+
-
and a new name (String). All name's start with name_ and als image's with img_ to make sure there a no conflicts.
+
-
It is possible to give two piece's the same name, in that case the programme will threat them the same and you can use both to complete a level.
+
-
*/
+
-
 
+
-
/***************************************************************
+
-
***********************Making of Object*************************
+
-
***************************************************************/
+
-
PImage img_gfp;
+
-
String name_gfp = "Green Flueredics Protien";
+
-
 
+
-
PImage img_t7;
+
-
String name_t7 = "promotor T7";
+
-
 
+
-
PImage img_terminator;
+
-
String name_terminator = "Terminator";
+
-
 
+
-
PImage img_antibiores;
+
-
String name_antibiores = "Antibiotic resistant";
+
-
 
+
-
PImage img_tntP;
+
-
String name_tntP = "promotor TNT";
+
-
 
+
-
PImage img_o2;
+
-
String name_o2 = "Oxygen Promotor";
+
-
 
+
-
PImage img_display;
+
-
String name_display = "Display Protein";
+
-
 
+
-
PImage img_linker;
+
-
String name_linker = "Linker";
+
-
 
+
-
PImage img_mri;
+
-
String name_mri = "MRI-protein";
+
-
 
+
-
PImage img_keke;
+
-
String name_keke = "Zwitter ion";
+
-
 
+
-
PImage img_inhi;
+
-
String name_inhi = "Inhibitor";
+
-
 
+
-
//down here two more image's are made whith are the same every time
+
-
PImage handInDNA;
+
-
PImage info;
+
-
//this integer (pieceOfDNAForUse) is set on two. That means the first two DNA piece are available right from the start.
+
-
int pieceOfDNAForUse = 2;
+
-
 
+
-
//image's for levels
+
-
/*
+
-
Down here we make the image's for the levels. The level1_2 image contains the description of the second level of the first block (this is 920X800).
+
-
Logo2_1 contains the small logo that is show on the right to start the level (this is 60X60).
+
-
The wellDone2_2 is shown when level 2.2 is past.
+
-
The toBad1_1 is shown when level 1.1 is handed in but not correct.
+
-
When someone completes all the levels of one the logo will change in logo1_max.
+
-
*/
+
-
PImage wellDone;
+
-
PImage toBad;
+
-
//LEVEL 1
+
-
PImage level1_1;
+
-
PImage logo1_1;
+
-
//PImage wellDone1_1;
+
-
//PImage toBad1_1;
+
-
 
+
-
PImage level1_2;
+
-
PImage logo1_2;
+
-
//PImage wellDone1_2;
+
-
//PImage toBad1_2;
+
-
 
+
-
PImage level1_3;
+
-
PImage logo1_3;
+
-
//PImage wellDone1_2;
+
-
//PImage toBad1_2;
+
-
 
+
-
PImage logo1_max;
+
-
 
+
-
//LEVEL 2
+
-
PImage level2_1;
+
-
PImage logo2_1;
+
-
//PImage wellDone2_1;
+
-
//PImage toBad2_1;
+
-
 
+
-
PImage level2_2;
+
-
PImage logo2_2;
+
-
//PImage wellDone2_2;
+
-
//PImage toBad2_2;
+
-
 
+
-
PImage logo2_max;
+
-
 
+
-
PImage background;
+
-
 
+
-
 
+
-
//levels
+
-
/*
+
-
If you want a new set of level you just have to add SubLevel[] levelX to the code.
+
-
*/
+
-
MasterLevel[] theRealLevels;
+
-
SubLevel[] level1;
+
-
SubLevel[] level2;
+
-
 
+
-
//every level has a strain whith it want to pass. You add them over here (use the name_ String so you can change the name of DNA piece at one point in the code)
+
-
String[] eis1_1 = {name_gfp, name_terminator};
+
-
String[] eis1_2 = {name_t7, name_gfp, name_terminator};
+
-
String[] eis1_3 = {name_t7, name_gfp, name_terminator, name_antibiores};
+
-
String[] eis2_1 = {name_tntP, name_gfp, name_terminator, name_antibiores};
+
-
String[] eis2_2 = {name_o2, name_gfp, name_terminator, name_antibiores};
+
-
String[] eis3_1 = {name_t7, name_gfp, name_terminator, name_antibiores};
+
-
String[] eis3_2a = {name_o2, name_inhi, name_terminator, name_antibiores};
+
-
String[] eis3_2b = {name_t7, name_mri, name_terminator, name_antibiores};
+
-
String[] eis3_3 = {name_t7, name_display, name_linker, name_keke, name_terminator, name_antibiores};
+
-
String[] empty = {};
+
-
 
+
-
//making of the items you can pick up with you mouse
+
-
Plasmide plasmide1;
+
-
Plasmide plasmide2;
+
-
boolean secondPlas = false;
+
-
 
+
-
//Image's of infoBoards
+
-
PImage infoBoard[];
+
-
 
+
-
//left side
+
-
int stripLeft = 160;
+
-
 
+
-
//right side
+
-
int stripRight = 80;
+
-
PImage binOn;
+
-
PImage binOff;
+
-
Button bin;
+
-
 
+
-
PImage helpOn;
+
-
PImage helpOff;
+
-
Button helpButton;
+
-
int currentHelpScreen = 1;
+
-
int maxNumberOfHelpScreens = 3;
+
-
PImage[] helpScreen;
+
-
 
+
-
 
+
-
//remaining
+
-
int itemOnMouse;
+
-
boolean somethingOnMouse;
+
-
int infoNumber =0;
+
-
int level = 0;
+
-
boolean thereIsInfoToShow = true;
+
-
 
+
-
/***************************************************************
+
-
***********************VOID SETUP()*****************************
+
-
***************************************************************/
+
-
void setup(){
+
-
   size(1000, 800);
+
-
  textAlign(CENTER);
+
-
   //image's
+
-
  /*
+
-
  Up there will be a tab named Loading_Image_s. Go there to load the Image's whith you made above!
+
-
  */
+
-
  /*
+
-
  To load a image from your computer use level1_1  = loadImage("desc1_1.png");
+
-
  With level1_1 made before as a PImage and desc1_1.png avalible in the map data.
+
-
   */
+
-
  level1_1  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
   level1_2  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  level1_3 = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpgg");
+
-
   level2_1  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  level2_2 = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  wellDone  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  toBad  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  logo1_1  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  logo1_2  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  logo1_3  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  logo2_1  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  logo2_2  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  logo1_max  = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  logo2_max  = loadImage("level2_max.png");
+
-
 
+
-
  helpOn = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  helpOff = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
 
+
-
  handInDNA = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  info = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  background = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
 
+
-
  img_gfp = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_t7 = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_terminator = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_antibiores = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_tntP = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_o2 = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_display = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_linker = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_mri = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_keke = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  img_inhi = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  binOn = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
  binOff = loadImage("https://static.igem.org/mediawiki/2014/7/70/Bas_TU_Eindhoven.jpg");
+
-
 
+
-
  /*
+
-
  every piece of DNA has a infonumber (the first has number 1, the second number 2 ect.).
+
-
  You only have to make sure there is a image infoBoard1.png in the data map for DNA number 1, infoBoard42.png for DNA number 42 ect.
+
-
  */
+
-
  numberOfDNA = 11;
+
-
  infoBoard = new PImage[numberOfDNA + 1];
+
-
  for(int i = 1; i < numberOfDNA+1; i++){
+
-
    infoBoard[i] = loadImage("infoBoard"+str(i)+".png");
+
-
  }
+
-
 
+
-
  helpScreen = new PImage[maxNumberOfHelpScreens];
+
-
  for(int i = 0; i < maxNumberOfHelpScreens; i++){
+
-
    helpScreen[i] = loadImage("helpScreen"+str(i+1)+".png");
+
-
  }
+
-
 
+
-
  //grapping items
+
-
  /*
+
-
  If you want to add a new piece of DNA (and add the image's already) you can finish them up here.
+
-
  dna[0] = new DNAPiece(the X position of the logo, the Y position, img_(of your new DNA), name_(of your new DNA), your infoNumber, color(0, 255, 0));
+
-
  */
+
-
 
+
-
  dna = new DNAPiece[numberOfDNA + 1];
+
-
  dna[0] = new DNAPiece(10, 10, img_gfp, name_gfp, 1, color(0, 255, 0));
+
-
  dna[1] = new DNAPiece(10, 80, img_terminator, name_terminator, 2, color(200,200,200));
+
-
  dna[2] = new DNAPiece(10, 150, img_t7, name_t7, 3, color(255,0,100));
+
-
  dna[3] = new DNAPiece(10, 220, img_antibiores, name_antibiores, 4, color(255,255,255));
+
-
  dna[4] = new DNAPiece(10, 290, img_tntP, name_tntP, 5, color(255,100,0));
+
-
  dna[5] = new DNAPiece(10, 360, img_o2, name_o2, 6, color(255, 0, 0));
+
-
  dna[6] = new DNAPiece(10, 430, img_display, name_display, 7, color(100,51,102));
+
-
  dna[7] = new DNAPiece(10, 500, img_linker, name_linker, 8, color(0,105,106));
+
-
  dna[8] = new DNAPiece(10, 570, img_mri, name_mri, 9, color(255,125,255));
+
-
  dna[9] = new DNAPiece(10, 640, img_keke, name_keke, 10, color(255,0,255));
+
-
  dna[10] = new DNAPiece(10, 710, img_inhi, name_inhi, 11, color(100,100,255));
+
-
  plasmide1 = new Plasmide(250, 100, 500, 450, 2);
+
-
  plasmide2 = new Plasmide(350, 425, 350, 300, 2);
+
-
 
+
-
  //buttons right
+
-
  bin = new Button((width-stripRight)+10, 20, binOn, binOff);
+
-
  helpButton = new Button((width-stripRight)+10, 700, helpOn, helpOff);
+
-
  helpButton.isItOn = true;
+
-
 
+
-
  //levels
+
-
  /*
+
-
  if you want to add a SubLevel to level1 (whith has X levels) you change level1 = new SubLevel[X]; to level1 = new SubLevel[X+1];
+
-
  and you add a line of code:
+
-
  level1[X+1] = new SubLevel(eisX+1_X+1, logoX+1_X+1, levelX+1_X+1, wellDoneX+1_X+1, masterlevel, sublevel);
+
-
  */
+
-
  level1 = new SubLevel[3];
+
-
  level2 = new SubLevel[1];
+
-
  level1[0] = new SubLevel(eis1_1,empty, logo1_1, level1_1, wellDone, 1, 1);
+
-
  level1[1] = new SubLevel(eis1_2,empty, logo1_2, level1_2, wellDone, 1, 2);
+
-
  level1[2] = new SubLevel(eis1_3,empty, logo1_3, level1_3, wellDone, 1, 2);
+
-
  level2[0] = new SubLevel(eis2_1,empty, logo2_1, level2_1, wellDone, 2, 1);
+
-
  //level2[1] = new SubLevel(eis2_2,empty, logo2_2, level2_2, wellDone, 2, 2);
+
-
 
+
-
  /*
+
-
  if you want to add a new master level
+
-
  */
+
-
  theRealLevels = new MasterLevel[2];
+
-
  theRealLevels[0] = new MasterLevel(level1, toBad, logo1_max, (width-stripRight)+10, 100);
+
-
  theRealLevels[1] = new MasterLevel(level2, toBad, logo2_max, (width-stripRight)+10, 180);
+
-
 
+
-
 
+
-
 
+
}
}
-
/***************************************************************
 
-
***********************VOID DRAW()*****************************
 
-
***************************************************************/
 
-
void draw(){
 
-
  image(background, 0,0, width, height);
 
-
  //background(0);
 
-
  fill(200, 50, 50, 200);
 
-
  rect(0,0, stripLeft, height);
 
-
  rect(width-stripRight,0, stripRight, height);
 
-
 
 
-
  if(infoNumber != 0){
 
-
    showInfoBoard(infoNumber);
 
-
  } else if(currentHelpScreen != 0){
 
-
    image(helpScreen[currentHelpScreen-1], 0,0, 920, 800);
 
-
    helpButton.drawing();
 
-
    bin.drawing();
 
-
    for(int i = 0; i < theRealLevels.length; i++){
 
-
      theRealLevels[i].drawing();
 
-
    }
 
-
  } else {
 
-
    plasmide1.drawing();
 
-
    if(secondPlas) plasmide2.drawing();
 
-
    bin.drawing();
 
-
    helpButton.drawing();
 
-
    for(int i = 0; i < pieceOfDNAForUse; i++){
 
-
      dna[i].drawing();
 
-
    }
 
-
 
 
-
 
 
-
    for(int i = 0; i < theRealLevels.length; i++){
 
-
      theRealLevels[i].drawing();
 
-
    }
 
-
  }
 
-
 
-
}
 
-
 
-
void mouseClicked(){
 
-
 
-
  if(thereIsInfoToShow == false){
 
-
    for(int i = 0; i < theRealLevels.length; i++){
 
-
      theRealLevels[i].allFalse();
 
-
    }
 
-
   
 
-
    if((mouseX > (width - stripRight)) || (mouseX < stripLeft)){
 
-
      pickingUp();
 
-
    } else {
 
-
      dropIt();
 
-
      handItInBitch();
 
-
    }
 
-
  }else{
 
-
    thereIsInfoToShow = false;
 
-
    infoNumber = 0;
 
-
    helpDrawing();
 
-
    for(int i = 0; i < theRealLevels.length; i++){
 
-
      theRealLevels[i].allFalse();
 
-
    }
 
-
  }
 
-
}
 
-
void helpDrawing(){
 
-
  if(helpButton.checkIfClicked()){
 
-
    currentHelpScreen=(currentHelpScreen + 1)%(maxNumberOfHelpScreens+1);
 
-
    thereIsInfoToShow = true;
 
-
    if(currentHelpScreen == 0){
 
-
      helpButton.isItOn = false;
 
-
    }else{
 
-
      helpButton.isItOn = true;
 
-
    }
 
-
  }
 
-
}
 
-
 
-
void pickingUp(){
 
-
  somethingOnMouse = false;
 
-
  bin.check(false);
 
-
 
 
-
  for(int i = 0; i < theRealLevels.length; i++){
 
-
    if(mouseX >(width - stripRight)) theRealLevels[i].checkButton();
 
-
  }
 
-
  for(int i = 0; i < pieceOfDNAForUse; i++){
 
-
    if(dna[i].check(mouseX, mouseY)){
 
-
      itemOnMouse = i;
 
-
      somethingOnMouse = true;
 
-
    }
 
-
  }
 
-
}
 
-
 
-
void dropIt(){
 
-
  if(somethingOnMouse){
 
-
    plasmide1.check(dna[itemOnMouse].name, dna[itemOnMouse].colour);
 
-
    if(secondPlas)  plasmide2.check(dna[itemOnMouse].name, dna[itemOnMouse].colour);
 
-
  }else if(bin.isItOn){
 
-
    plasmide1.removePiece();
 
-
    if(secondPlas) plasmide2.removePiece();
 
-
  }
 
-
}
 
-
 
-
void showInfoBoard(int i){
 
-
  image(infoBoard[i], 0,0);
 
-
}
 
-
 
-
void handItInBitch(){
 
-
  for(int i = 0; i < theRealLevels.length; i++){
 
-
    theRealLevels[i].checkHandIn();
 
-
  }
 
-
}
 
-
 
-
class DNAPiece{
 
-
  int posX;
 
-
  int posY;
 
-
  int sizeX = 60;
 
-
  int sizeY = 60;
 
-
  int sizeXinfo = 60;
 
-
  int sizeYinfo = 60;
 
-
  int posXinfo = 72;
 
-
  int posYinfo = posY;
 
-
  int infonumber;
 
-
  String name;
 
-
  boolean mouseHold = false;
 
-
  PImage img;
 
-
  color colour;
 
-
 
 
-
  DNAPiece(int posXQ,int posYQ, PImage imgQ, String nameQ, int infonumberQ, color colourQ){
 
-
    posX = posXQ;
 
-
    posY = posYQ;
 
-
    posYinfo = posY;
 
-
    posXinfo = int(posX+sizeX*1.2);
 
-
    img = imgQ;
 
-
    name = nameQ;
 
-
    infonumber = infonumberQ;
 
-
    colour = colourQ;
 
-
  }
 
-
 
 
-
  void drawing(){
 
-
    fill(colour);
 
-
    if(mouseHold){
 
-
      image(img, mouseX-sizeX/2, mouseY-sizeY/2, sizeX, sizeY);
 
-
      text(name, width/2, height/20);
 
-
    }else{
 
-
      image(img, posX, posY, sizeX, sizeY);
 
-
    }
 
-
    image(info, posXinfo, posY, sizeX, sizeY);
 
-
  }
 
-
 
 
-
  boolean check(int XQ, int YQ){
 
-
    if((XQ <= (posX + sizeX)) && (XQ > posX) && (YQ <= (posY + sizeY)) && (YQ > posY) && (mouseHold == false)){
 
-
        mouseHold = true;
 
-
        return true;
 
-
    } else {
 
-
      if((XQ <= (posXinfo + sizeXinfo)) && (XQ > posXinfo) && (YQ <= (posYinfo + sizeYinfo)) && (YQ > posYinfo) && (infoNumber == 0)) infoNumber = infonumber; thereIsInfoToShow = true;//do you click the infobutton?
 
-
      mouseHold = false;
 
-
      return false;
 
-
    }
 
-
  }
 
-
}
 
-
 
-
class Button{
 
-
  PImage buttonOn;
 
-
  PImage buttonOff;
 
-
  boolean isItOn = false;
 
-
  int posX;
 
-
  int posY;
 
-
  int sizeX = 60;
 
-
  int sizeY = 60;
 
-
 
 
-
  Button(int posXQ, int posYQ, PImage buttonOnQ, PImage buttonOffQ){
 
-
    posX = posXQ;
 
-
    posY = posYQ;
 
-
    buttonOn = buttonOnQ;
 
-
    buttonOff = buttonOffQ;
 
-
  }
 
-
 
 
-
  Button(int posXQ, int posYQ, int sizeXQ, int sizeYQ, PImage buttonOnQ, PImage buttonOffQ){
 
-
    posX = posXQ;
 
-
    posY = posYQ;
 
-
    sizeX=sizeXQ;
 
-
    sizeY=sizeYQ;
 
-
    buttonOn = buttonOnQ;
 
-
    buttonOff = buttonOffQ;
 
-
  }
 
-
 
 
-
  void drawing(){
 
-
    if(isItOn){
 
-
      image(buttonOn, posX, posY, sizeX, sizeY);
 
-
    }else{
 
-
      image(buttonOff, posX, posY, sizeX, sizeY);
 
-
    }
 
-
  }
 
-
 
 
-
  void check(boolean infoQ){
 
-
   
 
-
    if((mouseX <= (posX + sizeX)) && (mouseX > posX) && (mouseY <= (posY + sizeY)) && (mouseY > posY) && (isItOn == false)){
 
-
      isItOn = true;
 
-
    } else {
 
-
      isItOn = false;
 
-
    }
 
-
    if(infoQ) thereIsInfoToShow = true;
 
-
  }
 
-
 
 
-
  boolean checkIfClicked(){
 
-
    if((mouseX <= (posX + sizeX)) && (mouseX > posX) && (mouseY <= (posY + sizeY)) && (mouseY > posY)){
 
-
      return true;
 
-
    } else {
 
-
      return false;
 
-
    }
 
-
  }
 
-
}
 
-
 
-
class MasterLevel{
 
-
  SubLevel theLevels[];
 
-
  int currentLevel = 0;
 
-
  int reward;
 
-
  PImage toBad;
 
-
  PImage maxLevel;
 
-
  boolean showInfo = false;
 
-
  boolean endLevel = false;
 
-
  boolean doneWell;
 
-
  Button handingIn;
 
-
  //drawing the image's
 
-
  int posX;
 
-
  int posY;
 
-
  int sizeX = 60;
 
-
  int sizeY = 60;
 
-
  int sizeXd = 920;
 
-
  int sizeYd = 800;
 
-
 
 
-
  MasterLevel(SubLevel[] theLevelsQ, PImage toBadQ, PImage maxLevelQ, int posXQ, int posYQ){
 
-
    theLevels = theLevelsQ;
 
-
    maxLevel = maxLevelQ;
 
-
    toBad = toBadQ;
 
-
    posX = posXQ;
 
-
    posY = posYQ;
 
-
    handingIn = new Button(600, 650, 240, 60, handInDNA, handInDNA);
 
-
  }
 
-
 
 
-
  void drawing(){
 
-
    if(currentLevel < theLevels.length){
 
-
      fill(255,255,0);
 
-
      if(showInfo) rect(posX-5,posY-5,sizeX+10,sizeY+10);
 
-
      image(theLevels[currentLevel].logo, posX, posY, sizeX, sizeY);
 
-
    } else{
 
-
      image(maxLevel, posX, posY, sizeX, sizeY);
 
-
    }
 
-
    if(showInfo){
 
-
      if(endLevel){
 
-
        if(doneWell){
 
-
          image(theLevels[currentLevel-1].wellDone, 0,0, sizeXd, sizeYd);
 
-
        }else{
 
-
          image(toBad, 0,0, sizeXd, sizeYd);
 
-
        }
 
-
      }else{
 
-
        image(theLevels[currentLevel].description, 0,0, sizeXd, sizeYd);
 
-
        handingIn.drawing();
 
-
      }
 
-
     
 
-
    }
 
-
  }
 
-
 
 
-
  void checkButton(){
 
-
    if((mouseX <= (posX + sizeX)) && (mouseX > posX) && (mouseY <= (posY + sizeY)) && (mouseY > posY) && (showInfo == false) && (currentLevel < theLevels.length)){
 
-
      showInfo = true;
 
-
      thereIsInfoToShow = true;
 
-
    } else {
 
-
      showInfo = false;
 
-
      endLevel = false;
 
-
    }
 
-
  }
 
-
  void checkHandIn(){
 
-
    if((showInfo) && (handingIn.checkIfClicked()) && (endLevel == false)){
 
-
      if((theLevels[currentLevel].check(plasmide1.hold) && theLevels[currentLevel].check2(plasmide2.hold))||(theLevels[currentLevel].check2(plasmide1.hold) && theLevels[currentLevel].check(plasmide2.hold))){
 
-
        endLevel = true;
 
-
        doneWell = true;
 
-
        theLevels[currentLevel].rewardThatShit();
 
-
        currentLevel++;
 
-
      }else{
 
-
        endLevel = true;
 
-
        doneWell = false;
 
-
      }
 
-
    }
 
-
  }
 
-
 
 
-
  void allFalse(){
 
-
    if(!handingIn.checkIfClicked()){
 
-
      showInfo = false;
 
-
      endLevel = false;
 
-
    }
 
-
  }
 
-
}
 
-
 
 
-
class Plasmide{
 
-
  String hold[];
 
-
  color colour[];
 
-
  color emptyColour = color(125, 125, 125);
 
-
  int posX;
 
-
  int posY;
 
-
  int sizeR;
 
-
  int sizeR2;
 
-
  int sizeR3;
 
-
  int maxLength;
 
-
  float sizeRone;
 
-
  long lastRemove;
 
-
 
 
-
  Plasmide(int posXQ,int posYQ,int sizeRQ, int sizeR2Q, int maxLengthQ){
 
-
    posX = posXQ;
 
-
    posY = posYQ;
 
-
    sizeR = sizeRQ;
 
-
    sizeR2 = sizeR2Q;
 
-
    sizeR3 = sizeR + 50;
 
-
    maxLength = maxLengthQ;
 
-
    sizeRone = (sizeR/maxLength);
 
-
    hold = new String[0];
 
-
    colour = new color[0];
 
-
  }
 
-
 
 
-
  void drawing(){
 
-
    fill(255, 100);
 
-
    rect(posX, posY, sizeR, sizeR);
 
-
    pushMatrix();
 
-
      float step = 0.1;
 
-
      int lengthOfHold = hold.length;
 
-
      translate(posX+sizeR/2, posY+sizeR/2);
 
-
      fill(0);
 
-
      text(maxLength,0,0);
 
-
      noStroke();
 
-
 
-
        for(int i = 0; i < lengthOfHold; i++){
 
-
          beginShape();
 
-
          fill(colour[i]);
 
-
          for(float u = i*TWO_PI/maxLength; u <= (i+1)*TWO_PI/maxLength; u += step){
 
-
            vertex(cos(u)*sizeR/2, sin(u)*sizeR/2);
 
-
          }
 
-
          vertex(cos((i+1)*TWO_PI/maxLength)*sizeR/2, sizeR/2*sin((i+1)*TWO_PI/maxLength));
 
-
          for(float u = (i+1)*TWO_PI/maxLength; u >= (i)*TWO_PI/maxLength; u -= step){
 
-
            vertex(cos(u)*sizeR2/2, sizeR2/2*sin(u));
 
-
          }
 
-
          vertex(cos((i)*TWO_PI/maxLength)*sizeR2/2, sizeR2/2*sin((i)*TWO_PI/maxLength));
 
-
          endShape();
 
-
          fill(0);
 
-
          text(hold[i], cos((i+0.5)*TWO_PI/maxLength)*sizeR2/2, sizeR2/2*sin((i+0.5)*TWO_PI/maxLength));
 
-
        }
 
-
       
 
-
      fill(emptyColour);
 
-
      noStroke();
 
-
      beginShape();
 
-
        for(float u = 0; u >= -(maxLength-lengthOfHold)*TWO_PI/maxLength; u -= step){
 
-
          vertex(cos(u)*sizeR/2, sin(u)*sizeR/2);
 
-
        }
 
-
        vertex(cos(-(maxLength-lengthOfHold)*TWO_PI/maxLength)*sizeR/2, sizeR/2*sin(-(maxLength-lengthOfHold)*TWO_PI/maxLength));
 
-
        for(float u = -(maxLength-lengthOfHold)*TWO_PI/maxLength; u <= 0; u += step){
 
-
          vertex(cos(u)*sizeR2/2, sin(u)*sizeR2/2);
 
-
        }
 
-
        vertex(sizeR2/2, 0);
 
-
      endShape();
 
-
    popMatrix();
 
-
  }
 
-
 
 
-
  void check(String holdQ, color colourQ){
 
-
    /*
 
-
    if((mouseX <= (posX + sizeR)) && (mouseX > posX) && (mouseY <= (posY + sizeR)) && (mouseY > posY) && (hold.length < maxLength)){
 
-
      hold=append(hold, holdQ);
 
-
      colour=append(colour, colourQ);
 
-
    }
 
-
    */
 
-
    float angle = atan2((mouseY-posY-sizeR/2),( mouseX-posX-sizeR/2));
 
-
      if(angle < 0){
 
-
        angle = TWO_PI + angle;
 
-
      }
 
-
    int clickPiece = floor(angle/TWO_PI * maxLength);
 
-
    if((mouseX <= (posX + sizeR)) && (mouseX > posX) && (mouseY <= (posY + sizeR)) && (mouseY > posY) && (hold.length < maxLength)){
 
-
      if((hold.length < maxLength) && (hold.length < clickPiece)){
 
-
        hold=append(hold, holdQ);
 
-
        colour=append(colour, colourQ);
 
-
      } else {
 
-
       
 
-
        if((hold.length >= clickPiece) && (millis()-lastRemove > 100)){
 
-
          String[] holdQQ = subset(hold, clickPiece);
 
-
          color[] colourQQ = subset(colour, clickPiece);
 
-
          hold = append(subset(hold, 0, clickPiece), holdQ);
 
-
          colour = append(subset(colour, 0, clickPiece), colourQ);
 
-
         
 
-
          for(int i = 0; i < holdQQ.length; i++){
 
-
            hold=append(hold, holdQQ[i]);
 
-
            colour=append(colour, colourQQ[i]);
 
-
          }
 
-
          lastRemove = millis();
 
-
        }
 
-
      }
 
-
    }
 
-
  }
 
-
  boolean removePiece(){
 
-
    float angle = atan2((mouseY-posY-sizeR/2),( mouseX-posX-sizeR/2));
 
-
    if(angle < 0){
 
-
      angle = TWO_PI + angle;
 
-
    }
 
-
    int clickPiece = floor(angle/TWO_PI * maxLength);
 
-
    if((mouseX <= (posX + sizeR)) && (mouseX > posX) && (mouseY <= (posY + sizeR)) && (mouseY > posY) && (hold.length >= clickPiece) && (millis()-lastRemove > 100)){
 
-
      String[] holdQ = subset(hold, clickPiece);
 
-
      color[] colourQ = subset(colour, clickPiece);
 
-
      hold = subset(hold, 0, clickPiece);
 
-
      colour = subset(colour, 0, clickPiece);
 
-
      for(int i = 1; i < holdQ.length; i++){
 
-
        hold=append(hold, holdQ[i]);
 
-
        colour=append(colour, colourQ[i]);
 
-
      }
 
-
      lastRemove = millis();
 
-
      return true;
 
-
    } else{
 
-
      return false;
 
-
    }
 
-
  }
 
-
}
 
-
 
-
class SubLevel{
 
-
  String demands[];
 
-
  String demands2[];
 
-
  PImage logo;
 
-
  PImage description;
 
-
  PImage wellDone;
 
-
  boolean past = false;
 
-
  boolean locked = true;
 
-
  int masterPos;
 
-
  int subPose;
 
-
 
 
-
  SubLevel(String[] demandsQ, String[] demands2Q, PImage logoQ, PImage descQ, PImage wellDoneQ, int masterPosQ, int subPoseQ){
 
-
    demands = demandsQ;
 
-
    demands2 = demands2Q;
 
-
    logo = logoQ;
 
-
    description = descQ;
 
-
    wellDone = wellDoneQ;
 
-
    masterPos = masterPosQ;
 
-
    subPose = subPoseQ;
 
-
  }
 
-
 
 
-
 
 
-
 
 
-
  boolean check(String[] currentPlasQ){
 
-
//    past = true;
 
-
//   
 
-
//    if(currentPlasQ.length==demands.length){
 
-
//      for(int i = 0; i < demands.length; i++){
 
-
//        if(currentPlasQ[i] != demands[i]){
 
-
//          past = false;
 
-
//          break;
 
-
//        }
 
-
//      }
 
-
//    }else{
 
-
//      past = false;
 
-
//    }
 
-
//   
 
-
//    return past;
 
-
    past = true;
 
-
    boolean firstCorrect = false;
 
-
    int firstDNAPiece = 0;
 
-
    String[] stringLine1;
 
-
    String[] stringLine2;
 
-
    if(demands.length!=0){
 
-
    for(int i = 0; i < currentPlasQ.length; i++){
 
-
      if(currentPlasQ[i] == demands[0]){
 
-
        firstCorrect = true;
 
-
        firstDNAPiece = i;
 
-
        break;
 
-
      }
 
-
    }
 
-
   
 
-
    stringLine1 = subset(currentPlasQ, firstDNAPiece, currentPlasQ.length-firstDNAPiece);
 
-
    stringLine2 = subset(currentPlasQ, 0, firstDNAPiece);
 
-
 
-
    for(int u = 0; u < stringLine2.length; u++){
 
-
      stringLine1 = append(stringLine1, stringLine2[u]);
 
-
    }
 
-
   
 
-
    currentPlasQ = stringLine1;
 
-
   
 
-
   
 
-
    if((currentPlasQ.length==demands.length) && (firstCorrect)){
 
-
      for(int i = 0; i < demands.length; i++){
 
-
        if(currentPlasQ[i] != demands[i]){
 
-
          past = false;
 
-
          break;
 
-
        }
 
-
      }
 
-
    }else{
 
-
      past = false;
 
-
    }
 
-
    }else{
 
-
      if(currentPlasQ.length==0){ past = true; }else{ past = false; }
 
-
    }
 
-
    return past;
 
-
  }
 
-
 
 
-
  boolean check2(String[] currentPlasQ){
 
-
    past = true;
 
-
    boolean firstCorrect = false;
 
-
    int firstDNAPiece = 0;
 
-
    String[] stringLine1;
 
-
    String[] stringLine2;
 
-
    if(demands2.length!=0){
 
-
      for(int i = 0; i < currentPlasQ.length; i++){
 
-
        if(currentPlasQ[i] == demands2[0]){
 
-
          firstCorrect = true;
 
-
          firstDNAPiece = i;
 
-
          break;
 
-
        }
 
-
      }
 
-
   
 
-
    stringLine1 = subset(currentPlasQ, firstDNAPiece, currentPlasQ.length-firstDNAPiece);
 
-
    stringLine2 = subset(currentPlasQ, 0, firstDNAPiece);
 
-
 
-
    for(int u = 0; u < stringLine2.length; u++){
 
-
      stringLine1 = append(stringLine1, stringLine2[u]);
 
-
    }
 
-
   
 
-
    currentPlasQ = stringLine1;
 
-
   
 
-
   
 
-
    if((currentPlasQ.length==demands2.length) && (firstCorrect)){
 
-
      for(int i = 0; i < demands2.length; i++){
 
-
        if(currentPlasQ[i] != demands2[i]){
 
-
          past = false;
 
-
          break;
 
-
        }
 
-
      }
 
-
    }else{
 
-
      past = false;
 
-
    }
 
-
    }else{
 
-
      if(currentPlasQ.length==0){ past = true; }else{ past = false; }
 
-
    }
 
-
    return past;
 
-
  }
 
-
 
 
-
  void rewardThatShit(){
 
-
    reward(masterPos, subPose);
 
-
  }
 
-
}
 
-
 
-
void reward(int master, int sub){
 
-
  switch(master){
 
-
   
 
-
    case 1:
 
-
      rewardSub1(sub);
 
-
      break;
 
-
    case 2:
 
-
      rewardSub2(sub);
 
-
      break;
 
-
    case 3:
 
-
      rewardSub3(sub);
 
-
      break;
 
-
    case 4:
 
-
      rewardSub4(sub);
 
-
      break;
 
-
  }
 
-
}
 
-
//pieceOfDNAForUse
 
-
//plasmide1.maxLength
 
-
 
-
/*
 
-
gaining a new plasmide:
 
-
plasmide1.posX= 350;
 
-
plasmide1.posY = 25;
 
-
secondPlas = true;
 
-
plasmide.sizeR = 350;
 
-
plasmide1.sizeR2 = 300;
 
-
*/
 
-
 
-
 
-
 
-
void rewardSub1(int sub){
 
-
 
 
-
  switch(sub){
 
-
    case 1:
 
-
      pieceOfDNAForUse += 1;
 
-
      plasmide1.maxLength++;
 
-
      break;
 
-
    case 2:
 
-
      pieceOfDNAForUse++;
 
-
      plasmide1.maxLength++;
 
-
      break;
 
-
    case 3:
 
-
      pieceOfDNAForUse++;
 
-
      plasmide1.maxLength+=2;
 
-
      break;
 
-
    case 4:
 
-
 
-
      break;
 
-
  }
 
-
}
 
-
 
-
void rewardSub2(int sub){
 
-
  switch(sub){
 
-
    case 1:
 
-
   
 
-
      break;
 
-
     
 
-
    case 2:
 
-
   
 
-
      break;
 
-
    case 3:
 
-
   
 
-
      break;
 
-
    case 4:
 
-
 
-
      break;
 
-
  }
 
-
}
 
-
 
-
void rewardSub3(int sub){
 
-
  switch(sub){
 
-
    case 1:
 
-
   
 
-
      break;
 
-
     
 
-
    case 2:
 
-
   
 
-
      break;
 
-
    case 3:
 
-
   
 
-
      break;
 
-
    case 4:
 
-
 
-
      break;
 
-
  }
 
-
}
 
-
 
-
void rewardSub4(int sub){
 
-
  switch(sub){
 
-
    case 1:
 
-
   
 
-
      break;
 
-
     
 
-
    case 2:
 
-
   
 
-
      break;
 
-
    case 3:
 
-
   
 
-
      break;
 
-
    case 4:
 
-
      break;
+
void draw() {
-
   }
+
  // Displays the image at its actual size at point (0,0)
 +
  image(img, 100, 0, 100, 100);
 +
   fill(255,0,0);
 +
  rect(0,0,100,100);
 +
  // Displays the image at point (0, height/2) at half of its size
 +
  image(img2, 0, height/2, img.width/2, img.height/2);
}
}
</script><canvas width="640" height="360" tabindex="0" id="__processing0" style="image-rendering: -webkit-optimize-contrast !important;"></canvas>
</script><canvas width="640" height="360" tabindex="0" id="__processing0" style="image-rendering: -webkit-optimize-contrast !important;"></canvas>

Revision as of 11:16, 17 July 2014

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Clock \ Examples \ Processing.org

 

AAAAAAAA