class BugNormal { Vector2D position; Vector2D velocity; float angle; float vangle; float size, speed; int state; //stand, turn, move, int stateCnt, stateLen, stateSubType; int type; //0 - random slow walker public BugNormal() { this.position = new Vector2D(0, 0); this.velocity = new Vector2D(0, 0); } public BugNormal(Vector2D position, float size, float speed) { this.position = position; this.velocity = new Vector2D(0, 0); this.size = size; this.speed = speed; state = 0; type = 0; } void update(int myIdx) { if (type == 0) { if (state == 0) //stand and wait { if (stateCnt > stateLen) { state = 1; //int(random(0,12)/10); //(move or rotate) stateLen = int(random(10, 60)); stateCnt = 0; stateSubType = round(random(0,1)); //(left or right) if (stateSubType == 0) stateSubType = -1; } } else if (state == 1) //rotate { angle += 0.04 * float(stateSubType); // print(0.04 * float(stateSubType)); // print(stateSubType); if (stateCnt > stateLen) { state = 2; stateLen = int(random(10, 40)); stateCnt = 0; } } else if (state == 2) //move { velocity = new Vector2D(speed, 0); velocity.rotateTo(angle); if (stateCnt > stateLen) { state = 0; stateLen = int(random(7, 18)); stateCnt = 0; velocity.zero(); } if (!position.isInside(new Vector2D(width, height))) { state = 3; stateLen = int(random(40, 80)); stateCnt = 0; velocity.reverse(); velocity.divideBy(3); } for (int i=0; i stateLen) { state = 0; stateCnt = 0; velocity.zero(); } } stateCnt ++; } if (position.isCircleCollision(size/2, new Vector2D(myShip.x, myShip.y), 15)) { myShip.health -= 0.03 * size; } angle += vangle; position = position.plus(velocity); } void draw() { pushMatrix(); translate(position.getX(), position.getY()); rotate(angle); //smooth(); if (type == 0) { if (state < 99) //die or remov { noFill(); stroke(color(139, 150, 121)); ellipse(0, 0, size, size); //smooth(); line(cos(radians(50))*size/2, sin(radians(50))*size/2, cos(radians(-50))*size/2, sin(radians(-50))*size/2); float deg = 60; if (state != 0) deg += random(-10,10); line(cos(radians(deg))*size/2, sin(radians(deg))*size/2, cos(radians(deg))*size*0.7, sin(radians(deg))*size*0.7); deg = -60; if (state != 0) deg += random(-10,10); line(cos(radians(deg))*size/2, sin(radians(deg))*size/2, cos(radians(deg))*size*0.7, sin(radians(deg))*size*0.7); deg = 90; if (state != 0) deg += random(-10,10); line(cos(radians(deg))*size/2, sin(radians(deg))*size/2, cos(radians(deg))*size*0.7, sin(radians(deg))*size*0.7); deg = -90; if (state != 0) deg += random(-10,10); line(cos(radians(deg))*size/2, sin(radians(deg))*size/2, cos(radians(deg))*size*0.7, sin(radians(deg))*size*0.7); deg = 120; if (state != 0) deg += random(-10,10); line(cos(radians(deg))*size/2, sin(radians(deg))*size/2, cos(radians(deg))*size*0.7, sin(radians(deg))*size*0.7); deg = -120; if (state != 0) deg += random(-10,10); line(cos(radians(deg))*size/2, sin(radians(deg))*size/2, cos(radians(deg))*size*0.7, sin(radians(deg))*size*0.7); } } popMatrix(); } int clean(int i) { for (int ib=0; ib