class Monster {
float xpos;
float ypos;
float xprev,yprev;
float scaleX;
float scaleY;
float eyeWidth, eyeHeight;
PImage faceImg;
PImage eyeImg;
PImage snakeImg;
PShape eyeShape;
PShape stalkShape;
PShape faceSvg;
int displayMode; //using this variable to tell the program what types of files to display.
//displayMode 0 is photoshop displayMode 1 is Illustrator.
Monster(int xstart, int ystart, float sxStart, float syStart)
{
xpos = xstart;
ypos = ystart;
xprev = xstart;
yprev = ystart;
scaleX = sxStart;
scaleY = syStart;
displayMode = 0;
eyeWidth = 100;
eyeHeight = 40;
faceImg = loadImage("whiteface.png");
eyeImg = loadImage("lips.png");
snakeImg = loadImage("stalk.png");
imageMode(CENTER);
faceSvg = loadShape("whiteface.svg");
shapeMode(CENTER);
eyeShape = loadShape("flower.svg");
stalkShape = loadShape("stalk.svg");
}
void setPos(int x, int y){
xprev = xpos;
yprev = ypos;
xpos = x;
ypos = y;
}
void setPos(float x, float y){
xprev = xpos;
yprev = ypos;
xpos = x;
ypos = y;
}
void setScale(int x, int y){
scaleX = x;
scaleY = y;
}
void eyestalk(int xpos, int ypos, int stalkx, int stalky) {
//Left Eye
float j;
pushMatrix();
translate(xpos, ypos);
for(j = 0; j < 15; j=j+1)
{
translate(stalkx, stalky);
if (displayMode == 0)
{
image(snakeImg, 0, 0, 20, 20);
}
if (displayMode == 1)
{
shape (stalkShape,0,0,20,20);
}
scale(1.1);
rotate( .6*sin(frameCount/40.0 + (.5*j) ) );
}
if (displayMode == 0)
{
image(eyeImg, 0, 0, eyeWidth, eyeHeight);
}
if (displayMode == 1)
{
shape (eyeShape,0,0,eyeWidth,eyeWidth);
}
popMatrix();
}
void display() {
pushMatrix();
translate(xpos, ypos);
scale(scaleX, scaleY);
//This is changing it to Photoshop.
if (displayMode == 0)
{
image(faceImg, 0, 0, 240, 320);
}
//This is changing it to Illustrator.
if (displayMode == 1)
{
shape(faceSvg, 0, 0, 155, 134);
}
eyestalk(50, -20, 15, 0); //right eye
eyestalk(-63, -15, -12, 0); //left eye
//eyestalk(0, -17, 1, 0);
popMatrix();
}
void toggleDisplay()
{
displayMode++; //the same as "displayMode = displayMode + 1;"
if (displayMode > 1)
{
displayMode = 0; //When clicking on the spacebar you will return to Photoshop.
}
}
void interact(Monster mstr1){
float newX, newY;
newX = xpos + .05 * (mstr1.xpos - xpos);
newY = ypos + .05 * (mstr1.ypos - ypos);
setPos( newX, newY);
}
}
Monster m1, m2;
void setup ()
{
size(480, 300);
m1 = new Monster(240,150,.5,.5);
m2 = new Monster(240,150,.5,.5);
}
void draw ()
{
background (0);
smooth ();
m2.setPos(mouseX, mouseY);
m1.interact(m2);
m1.display();
m2.display();
}
void keyPressed (){
if(key == ' ') //Testing to see if the spacebar is pressed.
{
m1.toggleDisplay();
}
}