Objects interacting when they collide.

I want to create a program where a small rectangle passes through other static rectangles and either deletes or changes the colour of them to give the impression of being created or deleted, this series of static rectangles are going to create simple letter forms sort of like dot matrix, here is what i have come up with so far, bearing in mind i have never coded in my life before any help would be much appreciated.

Block Block1;
Letter Letter1;

void setup() {
  size(200,200);
  Block1 = new Block(color(0),50,50,1);
  Letter1 = new Letter(color(0),60,50);
}

void draw() {
  background(255);
  Block1.drive();
  Block1.display();
  Letter1.display();
}

class Letter {
  color o;
  float xpos;
  float ypos;

  Letter(color tempO, float tempXpos, float tempYpos) {
    o = tempO;
    xpos = tempXpos;
    ypos = tempYpos;
  }

  void display() {
    stroke(255);
    fill(o);
    rectMode(CENTER);
    rect(xpos,ypos,10,10);
    }

}

class Block {
  color o;
  float xpos;
  float ypos;
  float xspeed;

  Block(color tempO, float tempXpos, float tempYpos, float tempXspeed) {
    o = tempO;
    xpos = tempXpos;
    ypos = tempYpos;
    xspeed = tempXspeed;
  }

  void display() {
    stroke(0);
    fill(o);
    rectMode(CENTER);
    rect(xpos,ypos,20,10);
  }

  void drive() {
    xpos = xpos +xspeed;
    if (xpos > width) {
      xpos = 0;
    }
  }
}

Answers

Sign In or Register to comment.