How can i pick up objects in an alien abduction game?

Hello, i'm making a game that has to do with alien abduction. My idea is to create a game in wich an UFO can pick up lost sheeps and bring them back to where they belong. I've made a code where the ufo can be moved with the arrow keys. The only thing i need to know is how to pick up the sheeps. My idea is to drag the sheeps with the lightbeam when the light beam of the ufo hits the x en y position of a sheep. Please can anyone help me? I'll put the code here below.

int radius = 10, directionX = 1, directionY=0; float p=20, o=20, speed=1;

int x=200; int y=515; int l=20; int h=10;

int wolkX=200; int wolkY=200; int wolkL=200; int wolkH=50; int xpos[]= new int[5]; int ypos[]= new int[5]; int kleur = 200;

// --------------------------------------------------------------- //int startX=1000;

void setup () { size(1700,620); //copyright luke en Lennaaaard }

void draw() { //achetrgrond+maan background(81,107,150); p=p+speeddirectionX; o=o+speeddirectionY; // check boundaries if ((p>width-radius) || (p<radius)) {
directionX=-directionX; } if ((o>height-radius) || (o<radius)) {
directionY=-directionY; }

stroke(0,0,0,0); fill(25,75,35); rect(0,510,2000,150); //maan fill(255,255,0); ellipse(100,170,70,70); fill(81,107,150); ellipse(120,166,70,70);

//wolken

fill(255,255,255,200);

ellipse(wolkX,wolkY,wolkL,wolkH); ellipse(wolkX-20,wolkY-20,wolkL-100,wolkH+40); ellipse(wolkX+40,wolkY-20,wolkL-120,wolkH+10); ellipse(wolkX,wolkY+5,wolkL,wolkH-30);

ellipse(wolkX+400,wolkY,wolkL,wolkH); ellipse(wolkX+380,wolkY-20,wolkL-100,wolkH+40); ellipse(wolkX+440,wolkY-20,wolkL-120,wolkH+10); ellipse(wolkX+400,wolkY+5,wolkL,wolkH-30);

//vanaf hier ufo // changing Position

//bolletje fill(255,255,0); ellipse(p,o-13,15,15);

//ufo zelf fill(175); ellipse(p,o,100,30);

//raampjes fill(0); ellipse(p-25,o,5,5); ellipse(p-15,o,5,5); ellipse(p+25,o,5,5); ellipse(p+15,o,5,5); fill(255,255,0,150); ellipse(p,o,5,5); strokeWeight(2); stroke(0); line(p-25,o+12,p-30,o+25); line(p,o+12,p,o+27); line(p+25,o+12,p+30,o+25); stroke(0,0,0,0); triangle(p,o,p-50,o+400,p+50,o+400); fill(254,233,0); ellipse(p,o+400,100,20); fill(0);

//Boederij //3D aspecten fill(100,80,20); noStroke();

             triangle(1380,480,1430,480,1430,430);  
             triangle(1380,570,1380,520,1430,520);
             rect(1380,480,50,40);
             triangle(1280,430,1430,430,1355,390);
             triangle(1230,480,1280,480,1280,430);  
             rect(1280,430,150,50);
   //strokes 3D   
              stroke(110,90,25);  
              strokeWeight(2);
              line(1380,570,1430,520);
              line(1380,480,1430,430);
              line(1230,480,1280,430);
              line(1430,430,1430,520);
              line(1430,430,1355,390); 
              line(1280,430,1355,390); 
              line(1305,440,1355,390); 

   //boerderij voorkant
             strokeWeight(2);
                  stroke(110,90,25);
                  fill(100,80,20);
                  rect(1230,480,150,90);
                 triangle(1230,480,1380,480,1305,440);


     //raam + deur  
                 stroke(0);
                 fill(255, 225, 0);
                 rect(1250,500,25,25);
                 fill(115, 90, 25);
                 rect(1320,520,25,43);
                 ellipse(1327,540,3,3);


                 stroke(0,0,0,0);

//paaltjens stroke(80,60,20); strokeWeight(5);

line(1150, 575,1150,550);
line(1120, 575,1120,550);
line(1090, 575,1090,550); 
line(1060, 575,1060,550);

// line(1030, 575,1030,550); line(1000, 575,1000,550); line(970, 575,970,550);

//3D paaltjes +15,-12 strokeWeight(4); line(1165, 565,1165,540); line(1180, 553,1180,528); line(1195, 541,1195,514);

line(985, 565,985,540); line(1000, 553,1000,528); line(1015, 541,1015,514);

//achterste paaltjes
strokeWeight(4);
line(1200, 530,1200,510); //hoogte -45
line(1170, 530,1170,510);
line(1140, 530,1140,510); 
line(1110, 530,1110,510);
line(1080, 530,1080,510);
line(1050, 530,1050,510);
line(1020, 530,1020,510);

               //latten

strokeWeight(2); line(1155, 555,1055,555); line(1155, 563,1055,563); line(1000, 555,965,555); line(1000, 563,965,563); //3D latten line(1150, 555,1200,510); line(1150, 563,1200,518);

line(970, 555,1020,510); line(970, 563,1020,518);

     //achterste latten
     strokeWeight(1);

line(1203, 512,1013,512); line(1203, 520,1013,520);

//kapot hek delen stroke(80,60,20); strokeWeight(2); line(1022,570,1042,580); line(1032,565,1052,580);

noStroke(); x= 200; y= 500; for (int teller=0;teller<=4;teller++) {

xpos[teller]=x;

ypos[teller]=y;

schaap(x, y, l, h, kleur); x+=90; y+=7; }

// schaap(x, y, l, h, kleur); // schaap(300, 535, 20, 10, kleur); // schaap(250, 510, 20, 10, kleur); // schaap(400,515,20, 10, kleur); // schaap(500,525,20,10,kleur); // schaap(590,540,20,10,kleur);

}

void schaap(int x,int y,int l,int h,int kleur) {
fill(kleur);

ellipse(x,y,l,h); //200,515,20,10 ellipse(x+20,y+5,l2,h2); fill(0); ellipse(x-5,y,2,3); stroke(0); line(x+10,y+15,x+10,y+20); line(x+13,y+15,x+13,y+20); line(x+30,y+15,x+30,y+20); line(x+33,y+15,x+33,y+20); stroke(0,0,0,0); }

//--------------------- void keyPressed() { if (key == CODED) { if (keyCode == LEFT) { //if (directionX>0) { directionX=-1; directionY=0; //} } else if (keyCode == RIGHT) { //if (directionX<0) {
directionX=1; directionY=0; //} } else if (keyCode == UP) { //if (directionY<0) { directionY=-1; directionX=0; //} } else if (keyCode == DOWN) { //if (directionY<0) { directionY=1; directionX=0; //} } } }

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

Answers

  • PLease edit your post

    Edit code better

    See sticky post

  • it would help to write everything in English and not half English half netherland

    Remember to press crrl-t in processing

    Your draw is far too long- try to make functions like wolken()

    Now for the abduction: when you detect that the laser has hit the sheep make a small animation where the sheep wanders up the laser inside the ufo

  • You can use lerp() to calculate x,y of the sheep- see reference

    You can make a new state there in the program where nothing else happens- google state here in the forum

  • edited March 2018

    Thankyou for your comment. I am now working on the language of the file. I've tried to use lerp() but it says that i can only use float in lerp(). But i have used int for my variabeles. I tried to change to them to float but it did not work. Also, i cant post the code as it's original. Whenever i post the code, it will mess up the structure. Thank you for your help.

    int radius = 10, directionX = 1, directionY=0; int p=20, o=20, speed=1;

    int x=200;
    int y=515; int l=20; int h=10;

    int level=1;

    int wolkX=200; int wolkY=200; int wolkL=200; int wolkH=50; int xpos[]= new int[5]; int ypos[]= new int[5]; int kleur = 200; //A0 String missie = "коргари меҳмон Marcel, het is aan jou de taak om de ontsnapte \"schapen\" terug te brengen naar het hok. Als je baas, Johan Фишор, erachter komt dat ze weg zijn wordt je ontslagen en moet je terug naar je eigen planeet \"Полша\". Op Полша verdien je niet genoeg om rond te komen dus je moet de schapen vangen! "; //Z1

    // --------------------------------------------------------------- //int startX=1000;

    void setup () { size(1700, 620); }

    void draw() { if (level==1) { //A0 Z1 playtekst(); } else { play(); } }

    void mousePressed() { if (mousePressed) { //A0 level=level-1; } } //Z1

    void keyPressed() { if (key == CODED) { if (keyCode == LEFT) { //if (directionX>0) { directionX=-1; directionY=0; //} } else if (keyCode == RIGHT) { //if (directionX<0) {
    directionX=1; directionY=0; //} } else if (keyCode == UP) { //if (directionY<0) { directionY=-1; directionX=0; //} } else if (keyCode == DOWN) { //if (directionY<0) { directionY=1; directionX=0; //} } } }

    void schaap(int x, int y, int l, int h, int kleur) {
    fill(kleur);

    ellipse(x, y, l, h); //200,515,20,10 ellipse(x+20, y+5, l2, h2); fill(0); ellipse(x-5, y, 2, 3); stroke(0); line(x+10, y+15, x+10, y+20); line(x+13, y+15, x+13, y+20); line(x+30, y+15, x+30, y+20); line(x+33, y+15, x+33, y+20); stroke(0, 0, 0, 0); }

                    void boerderij() {
                      //Boerderij
                      //3D aspecten
                      fill(100, 80, 20);
                      noStroke();
    
                      triangle(1380, 480, 1430, 480, 1430, 430);  
                      triangle(1380, 570, 1380, 520, 1430, 520);
                      rect(1380, 480, 50, 40);
                      triangle(1280, 430, 1430, 430, 1355, 390);
                      triangle(1230, 480, 1280, 480, 1280, 430);  
                      rect(1280, 430, 150, 50);
                      //strokes 3D   
                      stroke(110, 90, 25);  
                      strokeWeight(2);
                      line(1380, 570, 1430, 520);
                      line(1380, 480, 1430, 430);
                      line(1230, 480, 1280, 430);
                      line(1430, 430, 1430, 520);
                      line(1430, 430, 1355, 390); 
                      line(1280, 430, 1355, 390); 
                      line(1305, 440, 1355, 390); 
    
                      //boerderij voorkant
                      strokeWeight(2);
                      stroke(110, 90, 25);
                      fill(100, 80, 20);
                      rect(1230, 480, 150, 90);
                      triangle(1230, 480, 1380, 480, 1305, 440);
    
    
                      //raam + deur  
                      stroke(0);
                      fill(255, 225, 0);
                      rect(1250, 500, 25, 25);
                      fill(115, 90, 25);
                      rect(1320, 520, 25, 43);
                      ellipse(1327, 540, 3, 3);
    
    
                      stroke(0, 0, 0, 0);
                      //paaltjens
                      stroke(80, 60, 20); 
                      strokeWeight(5);
    
                      line(1150, 575, 1150, 550);
                      line(1120, 575, 1120, 550);
                      line(1090, 575, 1090, 550); 
                      line(1060, 575, 1060, 550);
                      // line(1030, 575,1030,550);
                      line(1000, 575, 1000, 550);
                      line(970, 575, 970, 550);
    
                      //3D paaltjes            +15,-12
                      strokeWeight(4);
                      line(1165, 565, 1165, 540);
                      line(1180, 553, 1180, 528);
                      line(1195, 541, 1195, 514);    
    
                      line(985, 565, 985, 540);
                      line(1000, 553, 1000, 528);
                      line(1015, 541, 1015, 514);    
    
                      //achterste paaltjes
                      strokeWeight(4);
                      line(1200, 530, 1200, 510); //hoogte -45
                      line(1170, 530, 1170, 510);
                      line(1140, 530, 1140, 510); 
                      line(1110, 530, 1110, 510);
                      line(1080, 530, 1080, 510);
                      line(1050, 530, 1050, 510);
                      line(1020, 530, 1020, 510);
    
                      //latten
                      strokeWeight(2);
                      line(1155, 555, 1055, 555);
                      line(1155, 563, 1055, 563);
                      line(1000, 555, 965, 555);
                      line(1000, 563, 965, 563);
                      //3D latten
                      line(1150, 555, 1200, 510);
                      line(1150, 563, 1200, 518);
    
                      line(970, 555, 1020, 510);
                      line(970, 563, 1020, 518);
    
                      //achterste latten
                      strokeWeight(1);
                      line(1203, 512, 1013, 512);
                      line(1203, 520, 1013, 520);
    
    
    
                      //kapot hek delen
                      stroke(80, 60, 20);
                      strokeWeight(2);
                      line(1022, 570, 1042, 580);
                      line(1032, 565, 1052, 580);
                    }
    

    void UFO() { //vanaf hier ufo // changing Position

    //bolletje fill(255, 255, 0); ellipse(p, o-13, 15, 15);

    //ufo zelf fill(175); ellipse(p, o, 100, 30);

    //raampjes fill(0); ellipse(p-25, o, 5, 5); ellipse(p-15, o, 5, 5); ellipse(p+25, o, 5, 5); ellipse(p+15, o, 5, 5); fill(255, 255, 0, 150); ellipse(p, o, 5, 5); strokeWeight(2); stroke(0); line(p-25, o+12, p-30, o+25); line(p, o+12, p, o+27); line(p+25, o+12, p+30, o+25); stroke(0, 0, 0, 0); triangle(p, o, p-50, o+400, p+50, o+400); fill(254, 233, 0); ellipse(p, o+400, 100, 20); fill(0); }

    void playtekst() { //A0 fill(63, 79, 44); rect(0, 0, 1700, 620); fill(241, 255, 168); textSize(20); text(" \"Sheep Rescue \"", 60, 80, 1000, 500); text("Dag 70 - 12:21:46", 60, 100, 1000, 500); text("Planeet: синфхона E1", 60, 120, 1000, 500); text("коргари меҳмон / Нозирҷон Саймиддинов Marcel ", 60, 140, 1000, 500);

    textSize(25); text(missie, 60, 200, 1300, 500);

    text("Succes...", 60, 450, 1300, 500); textSize(18); text("KLIK OM VERDER TE GAAN", 620, 530, 1000, 100); } //Z1

    void play() { { //achetrgrond+maan background(81, 107, 150); p=p+speeddirectionX; o=o+speeddirectionY; // check boundaries if ((p>width-radius) || (p<radius)) {
    directionX=-directionX; } if ((o>height-radius) || (o<radius)) {
    directionY=-directionY; }

    stroke(0, 0, 0, 0);
    fill(25, 75, 35);
    rect(0, 510, 2000, 150);
    //maan
    fill(255, 255, 0);
    ellipse(100, 170, 70, 70);
    fill(81, 107, 150);
    ellipse(120, 166, 70, 70);
    
    
    
    
    //wolken
    
    fill(255, 255, 255, 200);
    
    ellipse(wolkX, wolkY, wolkL, wolkH);
    ellipse(wolkX-20, wolkY-20, wolkL-100, wolkH+40);
    ellipse(wolkX+40, wolkY-20, wolkL-120, wolkH+10);
    ellipse(wolkX, wolkY+5, wolkL, wolkH-30);
    
    ellipse(wolkX+400, wolkY, wolkL, wolkH);
    ellipse(wolkX+380, wolkY-20, wolkL-100, wolkH+40);
    ellipse(wolkX+440, wolkY-20, wolkL-120, wolkH+10);
    ellipse(wolkX+400, wolkY+5, wolkL, wolkH-30);
    
    
    
    
    
    
    UFO();
    

    translate(-100,0); boerderij(); translate(100,0);

    noStroke();
    x= 200;
    y= 500;
    for (int teller=0; teller<=4; teller++) {
    
      xpos[teller]=x;
    
      ypos[teller]=y;
    
      schaap(x, y, l, h, kleur);
      x+=90;
      y+=7;
    }
    
    // schaap(x, y, l, h, kleur);
    // schaap(300, 535, 20, 10, kleur);
    // schaap(250, 510, 20, 10, kleur);
    // schaap(400,515,20, 10, kleur);
    // schaap(500,525,20,10,kleur);
    // schaap(590,540,20,10,kleur);
    

    } }

    //aparte routine voor alle voorwerpen

  • https://forum.processing.org/two/discussion/15473/how-to-format-code-and-text

    I can't even stand to look at your code until you get this right.

  • @kayvanwijk -- definitely edit your post and format your code. In addition to readability, nobody can cut-paste to help test it when it isn't formatted.

  • edited March 2018

    Now the code is correct. Note: when you start the game there will be an green screen with text on it. This is the story of the game. Just click with your mouse to play.

    int radius = 10, directionX = 1, directionY=0;
    int p=20, o=20, speed=1;
    
    int x=200; 
    int y=515;
    int l=20;
    int h=10;
    
    int level=1;
    
    
    
    int wolkX=200;
    int wolkY=200;
    int wolkL=200;
    int wolkH=50;
    int xpos[]= new int[5];
    int ypos[]= new int[5];
    int kleur = 200;
    
    String missie = "??????? ?????? Marcel, het is aan jou de taak om de ontsnapte \"schapen\" terug te brengen naar het hok. Als je baas, Johan ?????, erachter komt dat ze weg zijn wordt je ontslagen en moet je terug naar je eigen planeet \"?????\". Op ????? verdien je niet genoeg om rond te komen dus je moet de schapen vangen! ";
    
    
    
    // ---------------------------------------------------------------
    //int startX=1000;
    
    void setup ()
    {
      size(1700, 620);
    }
    
    void draw() {
      if (level==1) {  //A0 Z1
        playtekst();
      } else {
        play();
      }
    }
    
    void mousePressed() {
      if (mousePressed) {   //A0
        level=level-1;
      }
    }
    //Z1
    
    
    
    void keyPressed()
    {
      if (key == CODED)
      {
        if (keyCode == LEFT)
        {
          //if (directionX>0) { 
          directionX=-1;
          directionY=0;
          //}
        } else if (keyCode == RIGHT)
        {
          //if (directionX<0) {  
          directionX=1;
          directionY=0;
          //}
        } else if (keyCode == UP)
        {
          //if (directionY<0) {
          directionY=-1;
          directionX=0;
          //}
        } else if (keyCode == DOWN)
        {
          //if (directionY<0) { 
          directionY=1;
          directionX=0;
          //}
        }
      }
    }
    
    
    
    
    void schaap(int x, int y, int l, int h, int kleur) {  
                          fill(kleur);
    
                          ellipse(x, y, l, h); //200,515,20,10
                          ellipse(x+20, y+5, l*2, h*2);
                          fill(0);
                          ellipse(x-5, y, 2, 3);
                          stroke(0);
                          line(x+10, y+15, x+10, y+20);
                          line(x+13, y+15, x+13, y+20);
                          line(x+30, y+15, x+30, y+20);
                          line(x+33, y+15, x+33, y+20);
                          stroke(0, 0, 0, 0);
                        }
    
    void boerderij() {
                          //Boerderij
                          //3D aspecten
                          fill(100, 80, 20);
                          noStroke();
    
                          triangle(1380, 480, 1430, 480, 1430, 430);  
                          triangle(1380, 570, 1380, 520, 1430, 520);
                          rect(1380, 480, 50, 40);
                          triangle(1280, 430, 1430, 430, 1355, 390);
                          triangle(1230, 480, 1280, 480, 1280, 430);  
                          rect(1280, 430, 150, 50);
                          //strokes 3D   
                          stroke(110, 90, 25);  
                          strokeWeight(2);
                          line(1380, 570, 1430, 520);
                          line(1380, 480, 1430, 430);
                          line(1230, 480, 1280, 430);
                          line(1430, 430, 1430, 520);
                          line(1430, 430, 1355, 390); 
                          line(1280, 430, 1355, 390); 
                          line(1305, 440, 1355, 390); 
    
                          //boerderij voorkant
                          strokeWeight(2);
                          stroke(110, 90, 25);
                          fill(100, 80, 20);
                          rect(1230, 480, 150, 90);
                          triangle(1230, 480, 1380, 480, 1305, 440);
    
    
                          //raam + deur  
                          stroke(0);
                          fill(255, 225, 0);
                          rect(1250, 500, 25, 25);
                          fill(115, 90, 25);
                          rect(1320, 520, 25, 43);
                          ellipse(1327, 540, 3, 3);
    
    
                          stroke(0, 0, 0, 0);
                          //paaltjens
                          stroke(80, 60, 20); 
                          strokeWeight(5);
    
                          line(1150, 575, 1150, 550);
                          line(1120, 575, 1120, 550);
                          line(1090, 575, 1090, 550); 
                          line(1060, 575, 1060, 550);
                          // line(1030, 575,1030,550);
                          line(1000, 575, 1000, 550);
                          line(970, 575, 970, 550);
    
                          //3D paaltjes            +15,-12
                          strokeWeight(4);
                          line(1165, 565, 1165, 540);
                          line(1180, 553, 1180, 528);
                          line(1195, 541, 1195, 514); 
    
                          line(985, 565, 985, 540);
                          line(1000, 553, 1000, 528);
                          line(1015, 541, 1015, 514); 
    
                          //achterste paaltjes
                          strokeWeight(4);
                          line(1200, 530, 1200, 510); //hoogte -45
                          line(1170, 530, 1170, 510);
                          line(1140, 530, 1140, 510); 
                          line(1110, 530, 1110, 510);
                          line(1080, 530, 1080, 510);
                          line(1050, 530, 1050, 510);
                          line(1020, 530, 1020, 510);
    
                          //latten
                          strokeWeight(2);
                          line(1155, 555, 1055, 555);
                          line(1155, 563, 1055, 563);
                          line(1000, 555, 965, 555);
                          line(1000, 563, 965, 563);
                          //3D latten
                          line(1150, 555, 1200, 510);
                          line(1150, 563, 1200, 518);
    
                          line(970, 555, 1020, 510);
                          line(970, 563, 1020, 518);
    
                          //achterste latten
                          strokeWeight(1);
                          line(1203, 512, 1013, 512);
                          line(1203, 520, 1013, 520);
    
    
    
                          //kapot hek delen
                          stroke(80, 60, 20);
                          strokeWeight(2);
                          line(1022, 570, 1042, 580);
                          line(1032, 565, 1052, 580);
                        }
    
    void UFO() {
                          //vanaf hier ufo
                          // changing Position
    
                          //bolletje
                          fill(255, 255, 0);
                          ellipse(p, o-13, 15, 15);
    
                          //ufo zelf
                          fill(175);
                          ellipse(p, o, 100, 30);
    
                          //raampjes
                          fill(0);
                          ellipse(p-25, o, 5, 5);
                          ellipse(p-15, o, 5, 5);
                          ellipse(p+25, o, 5, 5);
                          ellipse(p+15, o, 5, 5);
                          fill(255, 255, 0, 150);
                          ellipse(p, o, 5, 5);
                          strokeWeight(2);
                          stroke(0);
                          line(p-25, o+12, p-30, o+25);
                          line(p, o+12, p, o+27);
                          line(p+25, o+12, p+30, o+25);
                          stroke(0, 0, 0, 0);
                          triangle(p, o, p-50, o+400, p+50, o+400);
                          fill(254, 233, 0);
                          ellipse(p, o+400, 100, 20);
                          fill(0);
                        }
    
     void wolken() {
    
                          fill(255, 255, 255, 200);
    
                          ellipse(wolkX, wolkY, wolkL, wolkH);
                          ellipse(wolkX-20, wolkY-20, wolkL-100, wolkH+40);
                          ellipse(wolkX+40, wolkY-20, wolkL-120, wolkH+10);
                          ellipse(wolkX, wolkY+5, wolkL, wolkH-30);
    
                          ellipse(wolkX+400, wolkY, wolkL, wolkH);
                          ellipse(wolkX+380, wolkY-20, wolkL-100, wolkH+40);
                          ellipse(wolkX+440, wolkY-20, wolkL-120, wolkH+10);
                          ellipse(wolkX+400, wolkY+5, wolkL, wolkH-30);
                        }
    
    
    
    void playtekst() {  //A0
                          fill(63, 79, 44);
                          rect(0, 0, 1700, 620);
                          fill(241, 255, 168);
                          textSize(20);
                          text(" \"Sheep Rescue \"", 60, 80, 1000, 500); 
                          text("Dag 70 - 12:21:46", 60, 100, 1000, 500);
                          text("Planeet: ???????? E1", 60, 120, 1000, 500);
                          text("??????? ?????? / ???????? ??????????? Marcel ", 60, 140, 1000, 500);
    
                          textSize(25);
                          text(missie, 60, 200, 1300, 500);
    
                          text("Succes...", 60, 450, 1300, 500);
                          textSize(18);
                          text("KLIK OM VERDER TE GAAN", 620, 530, 1000, 100);
                        }
                        //Z1
    
    
    void play() {
                          {
                            //achetrgrond+maan
                            background(81, 107, 150);
                            p=p+speed*directionX;
                            o=o+speed*directionY; 
                            // check boundaries
                            if ((p>width-radius) || (p<radius))
                            {   
                              directionX=-directionX;
                            }
                            if ((o>height-radius) || (o<radius))
                            {   
                              directionY=-directionY;
                            } 
    
                            stroke(0, 0, 0, 0);
                            fill(25, 75, 35);
                            rect(0, 510, 2000, 150);
                            //maan
                            fill(255, 255, 0);
                            ellipse(100, 170, 70, 70);
                            fill(81, 107, 150);
                            ellipse(120, 166, 70, 70);
    
    
    
    //vanaf hier alles aanroepen
        UFO();
     translate(-100,0);
    
       wolken();
     //translate(-100,0);
    
        boerderij(); 
    translate(100,0);
    
    
        noStroke();
        x= 200;
        y= 500;
        for (int teller=0; teller<=4; teller++) {
    
          xpos[teller]=x;
    
          ypos[teller]=y;
    
          schaap(x, y, l, h, kleur);
          x+=90;
          y+=7;
        }
    
        // schaap(x, y, l, h, kleur);
        // schaap(300, 535, 20, 10, kleur);
        // schaap(250, 510, 20, 10, kleur);
        // schaap(400,515,20, 10, kleur);
        // schaap(500,525,20,10,kleur);
        // schaap(590,540,20,10,kleur);
      }
    }
    
    
    //aparte routine voor alle voorwerpen
    
  • You can use ctrl-t to auto-format (as said)

    you can use ....int(lerp(........ ));

  • edited March 2018

    The lerp function wrks now, but i still dont see any difference in the game. The lerp function is on line 40.

    int radius = 10, directionX = 1, directionY=0;
    int p=20, o=20, speed=1;
    
    int x=200; 
    int y=515;
    int l=20;
    int h=10;
    
    int level=1;
    
    
    
    int wolkX=200;
    int wolkY=200;
    int wolkL=200;
    int wolkH=50;
    int xpos[]= new int[5];
    int ypos[]= new int[5];
    int kleur = 200;
    
    String missie = "??????? ?????? Marcel, het is aan jou de taak om de ontsnapte \"schapen\" terug te brengen naar het hok. Als je baas, Johan ?????, erachter komt dat ze weg zijn wordt je ontslagen en moet je terug naar je eigen planeet \"?????\". Op ????? verdien je niet genoeg om rond te komen dus je moet de schapen vangen! ";
    
    
    
    // ---------------------------------------------------------------
    //int startX=1000;
    
    void setup ()
    {
      size(1700, 620);
    }
    
    void draw() {
      if (level==1) {  //A0 Z1
        playtekst();
      } else {
        play();
      }
      {
    x = int(lerp(x,p,0.1));  
      }
    }
    
    void mousePressed() {
      if (mousePressed) {   //A0
        level=level-1;
      }
    }
    //Z1
    
    
    
    void keyPressed()
    {
      if (key == CODED)
      {
        if (keyCode == LEFT)
        {
          //if (directionX>0) { 
          directionX=-1;
          directionY=0;
          //}
        } else if (keyCode == RIGHT)
        {
          //if (directionX<0) {  
          directionX=1;
          directionY=0;
          //}
        } else if (keyCode == UP)
        {
          //if (directionY<0) {
          directionY=-1;
          directionX=0;
          //}
        } else if (keyCode == DOWN)
        {
          //if (directionY<0) { 
          directionY=1;
          directionX=0;
          //}
        }
      }
    }
    
    
    
    
    void schaap(int x, int y, int l, int h, int kleur) {  
                          fill(kleur);
    
                          ellipse(x, y, l, h); //200,515,20,10
                          ellipse(x+20, y+5, l*2, h*2);
                          fill(0);
                          ellipse(x-5, y, 2, 3);
                          stroke(0);
                          line(x+10, y+15, x+10, y+20);
                          line(x+13, y+15, x+13, y+20);
                          line(x+30, y+15, x+30, y+20);
                          line(x+33, y+15, x+33, y+20);
                          stroke(0, 0, 0, 0);
                        }
    
    void boerderij() {
                          //Boerderij
                          //3D aspecten
                          fill(100, 80, 20);
                          noStroke();
    
                          triangle(1380, 480, 1430, 480, 1430, 430);  
                          triangle(1380, 570, 1380, 520, 1430, 520);
                          rect(1380, 480, 50, 40);
                          triangle(1280, 430, 1430, 430, 1355, 390);
                          triangle(1230, 480, 1280, 480, 1280, 430);  
                          rect(1280, 430, 150, 50);
                          //strokes 3D   
                          stroke(110, 90, 25);  
                          strokeWeight(2);
                          line(1380, 570, 1430, 520);
                          line(1380, 480, 1430, 430);
                          line(1230, 480, 1280, 430);
                          line(1430, 430, 1430, 520);
                          line(1430, 430, 1355, 390); 
                          line(1280, 430, 1355, 390); 
                          line(1305, 440, 1355, 390); 
    
                          //boerderij voorkant
                          strokeWeight(2);
                          stroke(110, 90, 25);
                          fill(100, 80, 20);
                          rect(1230, 480, 150, 90);
                          triangle(1230, 480, 1380, 480, 1305, 440);
    
    
                          //raam + deur  
                          stroke(0);
                          fill(255, 225, 0);
                          rect(1250, 500, 25, 25);
                          fill(115, 90, 25);
                          rect(1320, 520, 25, 43);
                          ellipse(1327, 540, 3, 3);
    
    
                          stroke(0, 0, 0, 0);
                          //paaltjens
                          stroke(80, 60, 20); 
                          strokeWeight(5);
    
                          line(1150, 575, 1150, 550);
                          line(1120, 575, 1120, 550);
                          line(1090, 575, 1090, 550); 
                          line(1060, 575, 1060, 550);
                          // line(1030, 575,1030,550);
                          line(1000, 575, 1000, 550);
                          line(970, 575, 970, 550);
    
                          //3D paaltjes            +15,-12
                          strokeWeight(4);
                          line(1165, 565, 1165, 540);
                          line(1180, 553, 1180, 528);
                          line(1195, 541, 1195, 514); 
    
                          line(985, 565, 985, 540);
                          line(1000, 553, 1000, 528);
                          line(1015, 541, 1015, 514); 
    
                          //achterste paaltjes
                          strokeWeight(4);
                          line(1200, 530, 1200, 510); //hoogte -45
                          line(1170, 530, 1170, 510);
                          line(1140, 530, 1140, 510); 
                          line(1110, 530, 1110, 510);
                          line(1080, 530, 1080, 510);
                          line(1050, 530, 1050, 510);
                          line(1020, 530, 1020, 510);
    
                          //latten
                          strokeWeight(2);
                          line(1155, 555, 1055, 555);
                          line(1155, 563, 1055, 563);
                          line(1000, 555, 965, 555);
                          line(1000, 563, 965, 563);
                          //3D latten
                          line(1150, 555, 1200, 510);
                          line(1150, 563, 1200, 518);
    
                          line(970, 555, 1020, 510);
                          line(970, 563, 1020, 518);
    
                          //achterste latten
                          strokeWeight(1);
                          line(1203, 512, 1013, 512);
                          line(1203, 520, 1013, 520);
    
    
    
                          //kapot hek delen
                          stroke(80, 60, 20);
                          strokeWeight(2);
                          line(1022, 570, 1042, 580);
                          line(1032, 565, 1052, 580);
                        }
    
    void UFO() {
                          //vanaf hier ufo
                          // changing Position
    
                          //bolletje
                          fill(255, 255, 0);
                          ellipse(p, o-13, 15, 15);
    
                          //ufo zelf
                          fill(175);
                          ellipse(p, o, 100, 30);
    
                          //raampjes
                          fill(0);
                          ellipse(p-25, o, 5, 5);
                          ellipse(p-15, o, 5, 5);
                          ellipse(p+25, o, 5, 5);
                          ellipse(p+15, o, 5, 5);
                          fill(255, 255, 0, 150);
                          ellipse(p, o, 5, 5);
                          strokeWeight(2);
                          stroke(0);
                          line(p-25, o+12, p-30, o+25);
                          line(p, o+12, p, o+27);
                          line(p+25, o+12, p+30, o+25);
                          stroke(0, 0, 0, 0);
                          triangle(p, o, p-50, o+400, p+50, o+400);
                          fill(254, 233, 0);
                          ellipse(p, o+400, 100, 20);
                          fill(0);
                        }
    
     void wolken() {
    
                          fill(255, 255, 255, 200);
    
                          ellipse(wolkX, wolkY, wolkL, wolkH);
                          ellipse(wolkX-20, wolkY-20, wolkL-100, wolkH+40);
                          ellipse(wolkX+40, wolkY-20, wolkL-120, wolkH+10);
                          ellipse(wolkX, wolkY+5, wolkL, wolkH-30);
    
                          ellipse(wolkX+400, wolkY, wolkL, wolkH);
                          ellipse(wolkX+380, wolkY-20, wolkL-100, wolkH+40);
                          ellipse(wolkX+440, wolkY-20, wolkL-120, wolkH+10);
                          ellipse(wolkX+400, wolkY+5, wolkL, wolkH-30);
                        }
    
    
    
    void playtekst() {  //A0
                          fill(63, 79, 44);
                          rect(0, 0, 1700, 620);
                          fill(241, 255, 168);
                          textSize(20);
                          text(" \"Sheep Rescue \"", 60, 80, 1000, 500); 
                          text("Dag 70 - 12:21:46", 60, 100, 1000, 500);
                          text("Planeet: ???????? E1", 60, 120, 1000, 500);
                          text("??????? ?????? / ???????? ??????????? Marcel ", 60, 140, 1000, 500);
    
                          textSize(25);
                          text(missie, 60, 200, 1300, 500);
    
                          text("Succes...", 60, 450, 1300, 500);
                          textSize(18);
                          text("KLIK OM VERDER TE GAAN", 620, 530, 1000, 100);
                        }
                        //Z1
    
    
    void play() {
                          {
                            //achetrgrond+maan
                            background(81, 107, 150);
                            p=p+speed*directionX;
                            o=o+speed*directionY; 
                            // check boundaries
                            if ((p>width-radius) || (p<radius))
                            {   
                              directionX=-directionX;
                            }
                            if ((o>height-radius) || (o<radius))
                            {   
                              directionY=-directionY;
                            } 
    
                            stroke(0, 0, 0, 0);
                            fill(25, 75, 35);
                            rect(0, 510, 2000, 150);
                            //maan
                            fill(255, 255, 0);
                            ellipse(100, 170, 70, 70);
                            fill(81, 107, 150);
                            ellipse(120, 166, 70, 70);
    
    
    
    //vanaf hier alles aanroepen
        UFO();
     translate(-100,0);
    
       wolken();
     //translate(-100,0);
    
        boerderij(); 
    translate(100,0);
    
    
        noStroke();
        x= 200;
        y= 500;
        for (int teller=0; teller<=4; teller++) {
    
          xpos[teller]=x;
    
          ypos[teller]=y;
    
          schaap(x, y, l, h, kleur);
          x+=90;
          y+=7;
        }
    
        // schaap(x, y, l, h, kleur);
        // schaap(300, 535, 20, 10, kleur);
        // schaap(250, 510, 20, 10, kleur);
        // schaap(400,515,20, 10, kleur);
        // schaap(500,525,20,10,kleur);
        // schaap(590,540,20,10,kleur);
      }
    }
    
    
    //aparte routine voor alle voorwerpen
    
  • ??

    The idea is that when the laser hits the sheep the sheep position gets lerp() so it floats towards the ufo

    In this new state nothing else happens

    (As said)

    Have you done this?

  • edited March 2018

    i'vetried it with if. but still does not work

    {
      if ((p == x) && (o+400 == y)){
    x = int(lerp(x,p,0.1));  
      } }
    
  • Really read the reference about lerp()

    instead of 0.1 use variable amt and increase it slowly amt+=0.04; or so.

    Also you need one lerp for x and one for y!!!!

    Also you need a new state not an if plus lerp

    And your want to lerp between sheep initially position and ufo so you need to store the initial sheep position

  • edited March 2018

    here is a lerp() example

    see also

    https://www.processing.org/reference/lerp_.html

    float amt=0;
    
    void setup() {
    
      size(1960, 1000);
      background(0);
      delay(12); 
      //
    }//func
    
    void draw() {
      //
      background(0);   // clear screen
      fill(255);
      noStroke(); 
    
      float x=lerp(  133, 1300, amt  );
      float y=lerp(  122, 900, amt  );
    
      text("test for lerp(). ", x, y);
    
      amt += 0.04;
    
      if (amt>=1.0)
        noLoop(); // reached target
      //
    }//func
    
  • edited March 2018

    I just solved it and got a nice program here

    Great fun!

    It was not easy.

    you need to get better variable names. E.g. p and o are not good names; better say ufoX, ufoY.

    Especially your sheeps are a mess.

    You should use xpos[] and xpos[] which are arrays and give those better names too like xposSheeps , yposSheeps. They hold the position of the sheeps in a list.

    Also, you don't use xpos[] and xpos[] !

    define them in setup and use them in play in these lines:

        noStroke();
        x= 200;
        y= 500;
        for (int teller=0; teller<=4; teller++) {
    
          xpos[teller]=x;
    
          ypos[teller]=y;
    
          schaap(x, y, l, h, kleur);
          x+=90;
          y+=7;
        }
    

    these lines are a not ok and half of it belongs into setup().

    since you want to abduct each sheep separately you also have to do the abduct check for each sheep separately in a for loop using xpos[] and xpos[] !!!

    Chrisir ;-)

  • edited March 2018

    Thankyou Chrisir for your help. I'm trying to make my lerp look like the example that you gave me, but it is not working yet. Could you please send the code that you've made where it is working? It would mean a lot for me since this is a school project and i do not have much time left and i really need a good note. Also i'll leave your name in the reference of my code. Again, thankyou so much for your help.

  • ??

    No, I won’t do it for you obviously.

    I told you what to do, did you follow the steps?

    You need to store the sheep positions in the 2 arrays xpos, ypos and use them in displaying the sheep and detecting of the tractor beam, both in a for loop. Only then you can start lerp() but only the sheep hit by the beam, not all of them.

    Show your entire code please

  • It’s a policy here in the forum not to do homework for others

    But I can lead you through

  • here is an example of how to use the 2 arrays xposSheep and yposSheep correctly

    That's the pre-condition of the lerp()-aduction.

    Chrisir ;-)

    float[] xposSheep = new float[5]; 
    float[] yposSheep = new float[5]; 
    
    int l=20;
    int h=10;
    int kleur = 200; // color
    
    int abductCounter=0;
    
    void setup () {
    
      size(1700, 620);
    
      float x= 200;
      float y= 500;
    
      for (int teller=0; teller<=4; teller++) {  // init 
        xposSheep[teller]=x;
        yposSheep[teller]=y;
        x+=90;
        y+=7;
      }
    
      background(0);
    }//setup
    
    void draw() {
      background(2, 123, 4);
    
      //noStroke();
      fill(255);
      textSize(32); 
      text ("Click a sheep to abduct", 200, 200); 
      if (abductCounter>=5)
        text ("...still some work to do.", 300, 250);
    
      for (int teller=0; teller<=4; teller++) {     // use it 
        schaap(xposSheep[teller], yposSheep[teller], 
          l, h, 
          kleur);
      }//for
    }//func 
    
    // ---------------------------------------------------------------
    
    void mousePressed() {
      for (int teller=0; teller<=4; teller++) {   // check it against mouse / insert beam here
    
        float myDistance = dist(mouseX, mouseY, 
          xposSheep[teller], yposSheep[teller]);
    
        if (myDistance < 52) {
          // start abduction mode here (but don't use lerp() here)
          yposSheep[teller]=-1000; 
          abductCounter++;
          return;
        }//if
      }//for
    }//func
    
    void schaap(float x, float y, 
      int l, int h, 
      int kleur) {  
    
      stroke(0); 
      fill(kleur);
    
      ellipse(x, y, l, h); //200,515,20,10
      ellipse(x+20, y+5, l*2, h*2);
    
      fill(0);
      ellipse(x-5, y, 2, 3);
    
      stroke(0);
      line(x+10, y+15, x+10, y+20);
      line(x+13, y+15, x+13, y+20);
      line(x+30, y+15, x+30, y+20);
      line(x+33, y+15, x+33, y+20);
      stroke(0, 0, 0, 0);
    }//func
    //
    
Sign In or Register to comment.