Creating complex gravity bouncing objects

fixed.

import processing.video.*;
Movie myMovie;

int numVideos = 5;
Video v1, v2, v3, v4, v5;

float groundY = 580;
float s = random(1);

void setup() {
  size (640, 640);
  myMovie = new Movie(this, "fogata.mp4");
  myMovie.loop();
  v1 = new Video(4096/20, 2160/20);
  v2 = new Video(4096/30, 2160/30);
  v3 = new Video(4096/10, 2160/10);
  v4 = new Video(4096/45, 2160/45);
  v5 = new Video(4096/25, 2160/25);
}

void draw() {
  background(64);
  stroke(255);
  line(0, groundY, width, groundY);
  v1.display();
  v1.move();
  v1.collide();
  v2.display();
  v2.move();
  v2.collide();
  v3.display();
  v3.move();
  v3.collide();
  v4.display();
  v4.move();
  v4.collide();
  v5.display();
  v5.move();
  v5.collide();
}
void movieEvent(Movie m) {
  m.read();
}
class Video {
  float rectW, rectH;
  float rectSpeedY;
  float rectSpeedX = 1;
  float rectY = 5;
  float rectX = map(width, (random(15)*50), 650, 0, 0);


  Video (float w, float h) {
    rectW = w;
    rectH = h;
  }

  void move() {
    rectX = rectX+1*rectSpeedX;
    rectY = rectY+1*rectSpeedY;

    if ((rectX <=0) || (rectX+rectW>= width)) {
      rectSpeedX *= -1;
    }
    if ((rectY <= 0) || (rectY +rectH*s>= height-60)) {
      rectSpeedY *= -1;
    }

    rectY += rectSpeedY;
    if (rectY+s + rectH+s >= groundY) {
      rectY = groundY - rectH;
      //bounce
      rectSpeedY *= -1 ;
    } else {
      rectSpeedY++;
    }
  }

  void collide() {
  }

  void display() {
    image(myMovie, rectX, rectY, rectW, rectH);
  }
}
2 Likes