Hey goToLoop,
Here is the revised code that attempts to have different class object detection. Its not compiling correctly, though.
class:
- class cellOne {
- final PVector location = new PVector(random(width), random(height));
- final PVector velocity = new PVector();
- final PVector acceleration = new PVector();
- final PVector attraction = new PVector(mouseX, mouseY);
- final static float TOP_SPEED = 2;
- final static short DIAM = 20;
- final static short DIM = 5, MIN_DIST = 60, MAX_SPD = 5;
- float objectColor = 0200;
- void update() {
- PVector.random2D(acceleration).mult(noise(3));
- velocity.add(acceleration);
- velocity.limit(TOP_SPEED);
- location.add(velocity);
- }
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(objectColor);
- ellipse(location.x, location.y, DIAM, DIAM);
- }
- void checkEdges() {
- if (location.x > width) location.x = 0;
- else if (location.x < 0) location.x = width;
- if (location.y > height) location.y = 0;
- else if (location.y < 0) location.y = height;
- // if(location.x == mouseX
- }
- boolean isNear(cellOne other) {
- //return dist(x, y, other.x, other.y) < MIN_DIST;
- //return sq(abs(other.x - x)) + sq(abs(other.y - y)) < MIN_DIST*MIN_DIST;
- return abs(other.location.x - location.x) < MIN_DIST
- && abs(other.location.y - location.y) < MIN_DIST;
- }
- void drawLine(cellOne other) {
- stroke(4);
- line(location.x, location.y, other.location.x, other.location.y);
- location.x += 3; //move opposite direction to not intersect
- location.y += 3;
- objectColor = 0;
- }
- void drawLine2(cellFast other) {
- stroke(4);
- line(location.x, location.y, other.location.x, other.location.y);
- location.x += 3; //move opposite direction to not intersect
- location.y += 3;
- objectColor = 0;
- }
- boolean intersect( cellFast b)
- {
- return abs(b.location.x - location.x) < MIN_DIST
- && abs(b.location.y - location.y) < MIN_DIST;
- }
- }
main:
- mainCell player1;
- HEALTH healthBar;
- Animation animation1;
- final static int NUM = 30;
- final static int NUM5 = 5;
- int frames = 60;
- final static cellOne[] mover = new cellOne[NUM];
- final static cellFast[] speedy = new cellFast[NUM5];
- boolean isPaused;
- void setup(){
- //stuff
- }
- void draw(){
- for (int i = 0; i != NUM; connectPoints(i++)) {
- mover[i].update();
- mover[i].checkEdges();
- mover[i].display();
- }
- for (int i = 0; i != NUM5; connectPointsSpeed(i++)) {
- speedy[i].update1();
- speedy[i].checkEdges1();
- speedy[i].displayFast();
- }
- for (int j =0; j < mover.length; compareTwo(j++)){
- for (int k=0; k < speedy.length; compareTwo(j++)){
- mover[j].update();
- mover[j].checkEdges();
- mover[j].display();
- speedy[k].update1();
- speedy[k].checkEdges1();
- speedy[k].displayFast();
- }
- final static void connectPoints(int i) {
- for (int z = i+1; z != NUM; z++){
- if ( mover[i].isNear(mover[z]) ) mover[i].drawLine(mover[z]);
- }
- }
- final static void connectPointsSpeed(int i) {
- for (int z = i+1; z != NUM5; z++){
- if ( speedy[i].isNear(speedy[z]) ) speedy[i].drawLine(speedy[z]);
- }
- }
- void compareTwo(int j){
- for(int m = j+1; m != mover.length; m++){
- if ( mover[j].intersect(speedy[m]) ) mover[j].drawLine2(speedy[m]);
- }
- }