/* April Grow (agrow) * November 18, 2009 * Processing Monster for Film 20c at UCSC * Monster inspired by mb09's BlinkEyeMonster: * http://www.rmx.cz/monsters/blink_eye_monster/index.html * * Cat class: stores cat's position and controlls the movement and drawing of the cat. */ class Cat{ float x, y; // x,y position of the cat, based on the head's center point boolean faceBodyLeft; // Changes the left/right facing position of the cat based on mouse position boolean jumping; // Determines rotation on body and arms boolean caught; // Determines wiggle and grin-drawing float wiggle; // Wiggles the arms if the cursor is caught - clapping? clawing? You decide! int count; // Increments the wiggle /* Constructor * Takes in the starting position from CatMonster and applies it to local variables */ Cat(float xPos, float yPos){ x = xPos; y = yPos; wiggle = 0; count = 1; } /* Update * Changes the position of the cat based on mouse position */ void update(float xMouse, float yMouse){ // Detect if the model will be facing left/right, always toward mouse cursor if (x < xMouse){ faceBodyLeft = true; } else if (x > xMouse){ faceBodyLeft = false; } // Cat always follows the cursor horizontally x += (xMouse - x) * 0.1; // Determine 'caught' if (((xMouse - x) < 2 && (xMouse - x) > -2) && ((yMouse - y) < 2 && (yMouse - y) > -2)){ caught = true; } else { caught = false; } // Calculate wiggle if (caught == true){ wiggle += count; if (wiggle > 5 || wiggle < 0){ count = -count; } } } /* Jump * Updates the movement of the cat for jumping, based on mouse click * Also sets flag for jumping, for use in Draw */ void jump(float xMouse, float yMouse, boolean mouse){ // Move the cat vertically to the cursor - chase that prey! if (mouse == true){ jumping = true; y += (yMouse - y) * 0.2; } else { // Drop the cat to the ground if the mouse is not clicked jumping = false; if (y < height*9/10){ y += 16; // Fairly realistic fall speed } else { y = height*9/10; // keeps from falling through floor } } } /* Draw * Draws the cat based on the new variables from Update. * Push/pop a matrix for each body part to have local transformations. * And 1 push/pop for the global transformation. (See project description for further details) */ void draw(){ pushMatrix(); // Global transformations translate(x-55, y-50); if (faceBodyLeft == false){ // Flip the cat shape so that it's facing the right direction scale(-1,1); translate(-110, 0); } if (jumping == true){ rotate(-45 * (PI/180)); } fill(0); // Colors all the insides black // Body: Follows global transformations ellipse(-35, 40, 125, 50); // body // Legs: // Front legs wiggle indenpendently if prey is caught // One leg wiggles one way pushMatrix(); if (caught == true){ translate(wiggle, 0); } ellipse(0, 55, 15, 50); // front leg 1 popMatrix(); // The other leg wiggles the opposite way pushMatrix(); if (caught == true){ translate(-wiggle, 0); } ellipse(10, 55, 15, 50); // front leg 2 popMatrix(); // Back legs face downward while jumping pushMatrix(); if (jumping == true){ rotate(50 * (PI/180)); translate(50, 50); } ellipse(-80, 55, 15, 50); // back leg 1 ellipse(-70, 55, 15, 50); // back leg 2 popMatrix(); // Head/ears/...face?: // While jumping, rotate to face to upright position, and move slightly forward after the prey pushMatrix(); if (jumping == true){ translate(40, 40); rotate(45 * (PI/180)); } ellipse(0, 0, 100, 50); // head triangle(10, -5, 40, -45, 45, -0); // right ear triangle(-10, -5, -40, -45, -45, -0); // left ear // If they prey is caught, draw a creepy, fun grin on the kitty as it plays with the prey/claps if (caught == true){ // Top row of teeth fill(255, 255, 255); // teeth! triangle(0, 3, 10, 20, 20, 2); triangle(0, 3, -10, 20, -20, 2); triangle(20, 2, 30, 15, 40, 1); triangle(-20, 2, -30, 15, -40, 1); triangle(40, 1, 44, 5, 47.5, 0); triangle(-40, 1, -44, 5, -47.5, 0); // Bottom row of teeth triangle(10, 23, 0, 5, -10, 23); triangle(-31, 18, -20, 4, -10, 23); triangle(31, 18, 20, 4, 10, 23); triangle(-45, 9, -40, 3, -29, 19); triangle(45, 9, 40, 3, 29, 19); fill(0, 0, 0); } popMatrix(); // Tail: Follows global transformations strokeWeight(10); // Thickness of the tail stroke(0, 0, 0); // Make sure tail is black noFill(); // Do not fill in curve bezier(-80, 30, -115, 40, -115, -80, -135, -70); // tail popMatrix(); } }