how to do inetarcction

2»

Answers

  • I was wrong code, I pass the right, I can not find it, nose if I deleted it

  • Another way to write that? baladx = map(mouseX, 0, width, -10, 10);

  • pppppp
    edited November 2017

    LETS DO BY PARTS

    FIRST OF ALL, WHY DON'T WORK, I PUT THE 2 ARRAYS, BUT DON'T WORKS, I DON'T WRITE NOTHING ABOUT THE COLLISION

    ArrayList bales;
    Bala bala1;
    PImage img;
    
    void setup() {
      size(800, 450);
      stroke(255);
      fill(255, 255, 255);
      bales = new ArrayList();
      bala1 = new Bala();
      img = loadImage("pa.jpg");
      bales.add( bala1 );
    }
    
    void draw() {
      image(img, 0, 0);
    
      line(400, 450, mouseX, 2 * mouseY);
      strokeWeight(mouseY/10);
    
    
      for ( int i = 0; i < bales.size(); i++) {
        bala1  = (Bala)bales.get(i);
        bala1.balesmoviment();
      }
    }
    
    class Bala {
      float balapx, balapy;
      float baladx, balady;
      Bala() {//creamos una bala
        balapx = width/2.0;
        balapy = height;
        baladx = map(mouseX, 0, width, -10, 10);
        balady = -10;
      }
    
      void balesmoviment() {
        balapx += baladx;
        balapy += balady;
        ellipse( balapx, balapy, 2, 2);
      }
    }
    
    
    void mousePressed() {
      if ( bales.size() > 9 ) bales.remove(0);
      bales.add( new Bala() );
    }
    {
      ArrayList soldats;
      Soldat soldat1;
    
      void setup() {
        soldats= new ArrayList();
        soldat1 = new Soldat();
        soldats.add (soldat1);
      }
      void draw() {
        for ( int i = 0; i < bales.size(); i++) {
          soldat1  = (Soldat)soldats.get(i);
          soldat1.soldatsmoviment();
        }    
          class Soldat { // Here the problem, how to make rectangles that move and avance in the map
            float soldatpx, soldatpy;
            float i;
            Soldat() {//creamos unsoldat
              soldatpx = width+i;
              soldatpy = 0;
            }
            void soldatsmoviment() {
              soldatpx +=i;
    
              rect( soldatpx, balapy, 10, 20);
            }
          }
        }
      }
    }
    
  •       boolean choque( float balaX, float balaY, float balaR, float soldatX, float soldatY, float soldatW, float soldatH ) {
         if (balaX==soldatX)&&(balaY==soldatY)&&(balaR==(soldatW*soldatH)) {
         choque=true;
    
         else()
         choque= false;
    
This discussion has been closed.