public class Bugger { //***********pencil guy public float x,y, tempyy; float rotDegree; float xFactor, yFactor; float rotFactor; public boolean alive; public boolean toKill; float myAlpha; int victim; boolean bringAlive; boolean beingCloned; int clonerID; float red1, red2, red3, green1, green2, green3, blue1, blue2, blue3; public Bugger(boolean a){ alive = a; } public void bSetup(){ rotDegree=0.4; rotFactor=5.0; x=200; y=(int)(Math.random()*(height-200)); xFactor=4; yFactor=1; toKill = false; myAlpha = 255; victim = (int)(Math.random()*sys.numO); bringAlive = false; if(!this.alive) myAlpha = 0; beingCloned = false; clonerID = 0; //COLOR FOR RECTANGLES: red1 =201; green1 = 243; blue1 = 160; //COLOR FOR TRIANGLE EDGES: red2= 51; green2 = 140; blue2 = 230; //COLOR FOR FRONT CIRCLE: red3= 105; green3 = 171; blue3 = 236; } public void bDraw(){ pushMatrix(); translate(x,y); drawGuy(); popMatrix(); rotDegree+=rotFactor; //moveXY(); if(this.bringAlive) { this.makeAlive(); } else { if(!beingCloned) movePencil(); } if(this.toKill){ this.killGuy(); } } void volt(){ if(this.rotFactor < 15){ this.rotFactor++; } } void unvolt(){ if(this.rotFactor > 5) this.rotFactor-=0.1; } void moveXY(){ if(this.x>width || this.x<0) this.xFactor*=(-1); if(this.y>height || this.y<0) this.yFactor*=(-1); this.x+=this.xFactor; this.y+=this.yFactor; } void drawGuy(){ rotate(radians(this.rotDegree)); stroke(0,myAlpha); fill(255, myAlpha); rectMode(CORNER); //background: fill(0, myAlpha); triangle(-10,-11, -38,0, -10,11); triangle(10,-11, 38,0, 10,11); triangle( -11,-11, 0,-26, 11,-11); triangle( -11,11, 0,26, 11,11); //front: fill(red1,green1,blue1, myAlpha); fill(red2,green2,blue2, myAlpha); triangle(-9,-9, -35,0, -9,9); triangle(9,-9, 35,0, 9,9); triangle( -8,-11, 0,-25, 8,-11); triangle( -8, 11, 0,25, 8,11); ellipseMode(CENTER); fill(0,myAlpha); ellipse(0,0,25,25); fill(red3,green3,blue3, myAlpha); ellipse(0,0,20,20); } void killGuy(){ if(rotFactor < 60) rotFactor+=0.8; myAlpha-=2; xFactor = yFactor = 0; if(myAlpha < 1) this.alive = false; } boolean changeVic = false; void movePencil(){ changeVic =false; while(sys.b[victim].x >= (width-20) || sys.b[victim].y >= (height-20) || sys.b[victim].y <=0 || sys.b[victim].x <= 0) { victim = (int)(Math.random()*(sys.numO)); } if(sys.b[victim].alive && blobsAlive > 10){ float m = getSlope(x, y, sys.b[victim].x, sys.b[victim].y); float b = getB(x,y,m); if(x < sys.b[victim].x) { if(m > 3.5){ if(x+0.2 < width && x+0.2 > 0) { x+=0.2; } else { x-=1; } } else { if(x+xFactor > 0 && x+xFactor < width) { x+=xFactor; } else { changeVic = true; } } } else { if(x > sys.b[victim].x) { if(m < -3.5) { if(x-0.2 > 0 && x-0.2 < width) { x-=0.2; } else { x+=1; } } else { if(x-xFactor > 0 && x-xFactor < width) { x-=xFactor; } else { changeVic = true; } } } } tempyy = (float)((m*x) +b); if(tempyy < height && tempyy > 0) { y = tempyy; } else { changeVic = true; } if(x <= sys.b[victim].x+(xFactor+30) && x >= sys.b[victim].x-(xFactor+30) && y <= sys.b[victim].y+(yFactor+30) && y >= sys.b[victim].y-(yFactor+30)) { xs.add(new Explosion(sys.b[victim].x, sys.b[victim].y, sys.b[victim].bRed, sys.b[victim].bGreen, sys.b[victim].bBlue)); sys.b[victim].alive = false; blobsAlive--; boolean anyAlive = false; for(int j =0; j (3*width/4))) { SBsetup((int)(sys.b[victim].x), (int)(sys.b[victim].y)); } victim = (int)((Math.random()*sys.numO)); } } else { victim=(int)(Math.random()*sys.numO); } if(changeVic) { if(xFactor < 5) xFactor+=0.1; victim = (int)((Math.random()*sys.numO)); } } float getSlope(float x1, float y1, float x2, float y2){ if(x2-x1 == 0) return 4; return ((float)((y2 - y1)/(x2 - x1))); } float getB(float x1, float y1, float m){ return ((float)(y1 - (m *x1))); } public void heat(){ if(xFactor < 5) xFactor+=0.2; } public void cool(){ if(xFactor > 3) xFactor-=0.2; } void bringtolife(int id, float locX, float locY){ this.bringAlive = true; this.alive=true; myAlpha = 0; this.x=(int)(locX); this.y=(int)(locY); xFactor=(float)(Math.random()*5)-2.5; yFactor=(float)(Math.random()*2)-1; rotDegree=0.4; rotFactor=5.0; toKill = false; clonerID = id; pencil[clonerID].beingCloned = true; } public void makeAlive(){ myAlpha+=5; if(myAlpha >= 255){ this.bringAlive = false; pencil[clonerID].beingCloned = false; } } }