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 int health = 100; 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(); } } //check for collisions with bullets and react on it for (int ib=0; ib