public class Monster { public Monster(){ } float x, y, tempyy; float speed; boolean voltage; float displacement; int victim; float Xspeed=1; float Yspeed=1; float y1, y2; boolean down; float flapSpeed; float rotateAngle; float fillR, fillG, fillB; boolean changeVic; void monsterSetup(){ x = width/2; y = height/2; speed = 3.0; voltage = false; victim = 0; y1=0; y2 = 40; down = true; flapSpeed = 1.5; rotateAngle=0; fillR = 250; fillG = 125; fillB = 0; } void monsterDraw(){ moveMonster(); pushMatrix(); translate(x+displacement,y+displacement); rotate(rotateAngle); drawMonsterMan(); popMatrix(); if(!keyPressed) { if(voltage){ speed=5; Xspeed=5;Yspeed=5; flapSpeed=1.5; } voltage=false; } } void heatMonster(){ if(flapSpeed < 4.1) flapSpeed+=0.05; if(speed < 5) speed++; } void coolMonster(){ if(speed > 1.5) { speed--; Xspeed--; Yspeed--; flapSpeed-=0.05; } } void voltMonster(){ voltage = true; speed=0; flapSpeed=0; } void drawMonsterMan(){ fill(200,200,0,200); noStroke(); //legs: fill(0,0,0); //background: triangle(0-5,y1-1, 40,10-3, 27-5,20); triangle(0-5,y2+1, 40,30+3, 27-5,20); triangle(40,10-3, 27-5,20, 40,30+3); triangle(40,10-3, 70+5,20, 40,30+3); //fill(200,100,0); fill(fillR,fillG,fillB); //legs: triangle(0,y1, 40,10, 27,20); triangle(0,y2, 40,30, 27,20); triangle(40,10, 27,20,40,30); triangle(40,10, 70,20, 40,30); fill(0,200); triangle(40-5,10+3, 70-3,20, 40-5,30-3); flapWings(); } void flapWings(){ if(y1 < 20.0 && down) { y1+=flapSpeed; y2-=flapSpeed; } else{ down = false; if(y1 > 0.0) { y1-=flapSpeed; y2+=flapSpeed; } else{ down = true; } } } int loopcount; void moveMonster(){ changeVic = false; displacement = 0; loopcount = 0; while(sys.b[victim].x >= width || sys.b[victim].y >= height || sys.b[victim].y <=0 || sys.b[victim].x <= 0) { victim = (int)(Math.random()*(sys.numO)); loopcount++; if(loopcount > 100) { victim = 0; break; } } if(sys.b[victim].alive && blobsAlive < sys.maxBlobs){ float m = getSlope(x, y, sys.b[victim].x, sys.b[victim].y); rotateAngle = atan(m); float b = getB(x,y,m); if(x < sys.b[victim].x) { if(m > 2.5){ if(x+0.1 < width) { x+=0.1; } else { x-=1; } } else { if((x+speed < width) && (x+speed > 0)) { x+=speed; } else{ changeVic = true; } } } else { if(x > sys.b[victim].x) { if(m < -2.5){ if(x-0.2 > 0 && x-0.2 < width) { x-=0.2; } else { x+=1; } } else { if(x-speed > 0 && x-speed < width) { x-=speed; } else { changeVic = true; } } } } tempyy = (float)((m*x) +b); if(tempyy < height && tempyy > 0) { y = tempyy; } else { changeVic = true; } if(x <= sys.b[victim].x+(speed+10) && x >= sys.b[victim].x-(speed+10) && y <= sys.b[victim].y+(speed+10) && y >= sys.b[victim].y-(speed+10)) { cloneBlobs(victim); victim = (int)(Math.random()*(sys.numO)); } }//end of if there is a victim method else { victim++; } if(voltage){ displacement = (float)(Math.random()*8); } if(changeVic) { 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))); } }