Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/* Welcome to my interactive toy project!
   My name is Alexander Durocher, and I coded all this.
   While using the toy, you control a friendly dinosaur named Buddy.
   Buddy follows your mouse, allowing you to move him around the village.
   When you place your mouse over a house, the people will say hi to Buddy.
   If you hit any of the mouse buttons, Buddy will stick his tongue out.
   There is no winning, since this is a toy and not a game.
   Hope you enjoy! Blep!
   
   References:
   Learning Processing, 2nd Edition
*/

//Village Variables (Placement)
int x1 = 245;
int y1 = 45;
int x2 = 105;
int y2 = 270;
int x3 = 295;
int y3 = 210;

//Dragon Colour Variables
float dragR;
float dragG;
float dragB;

void setup() {
  
  //Basic Setup
  size(400, 400);
  noCursor();
  noStroke();
}

void draw() {

  //Fix the Framerate from mouseClicked
  frameRate(60);

  //Planting Grass (Draw Background)
  background(0, 255, 0);

  //Call to Draw Village Function
  drawVillage();

  //Friendly People Talking
  if (mouseX > x1-20 && mouseX < x1+20 && mouseY > y1-15 && mouseY < y1+15) {
    println("Howdy partner!");
  }

  if (mouseX > x2-20 && mouseX < x2+20 && mouseY > y2-15 && mouseY < y2+15) {
    println("Oh hai Buddy!");
  }

  if (mouseX > x3-20 && mouseX < x3+20 && mouseY > y3-15 && mouseY < y3+15) {
    println("Hello Dino!");
  }
  
  //Fence(1) Loop
  int fX1 = 5;
  int fY1 = 69;
  int spaceBtwn1 = 10;
  int postLeng1 = 13;
  int endPost1 = 400;
  
  stroke(0);
  while (fX1 <= endPost1) {
    line (fX1, fY1, fX1, fY1 + postLeng1);
    fX1 = fX1 + spaceBtwn1;
  }
  
  //Fence(2) Loop
  int fX2 = 5;
  int fY2 = 360;
  int spaceBtwn2 = 10;
  int postLeng2 = 13;
  int endPost2 = 400;
  
  while (fX2 <= endPost2) {
    line (fX2, fY2, fX2, fY2 + postLeng2);
    fX2 = fX2 + spaceBtwn2;
  }
  
  //Third Fence
  line(145, 87, 145, 357);
  
  //Dino Call (Drawing the Dino)
  noStroke();
  drawDino();
}

void drawDino() {
  /*Buddy the Friendly Dino
   Rainbow Colours*/
  dragR = random(0, 155);
  dragG = random(0, 155);
  dragB = random(0, 155);
  fill(dragR, dragG, dragB);

  //Drawing Buddy the Dino
  rect(mouseX+20, mouseY, 50, 30); //Body
  triangle(mouseX+45, mouseY+15, mouseX+45, mouseY-15, mouseX+115, mouseY+5); //Tail
  triangle(mouseX, mouseY-15, mouseX+10, mouseY-15, mouseX+10, mouseY-45); //Neck
  rect(mouseX, mouseY-40, 40, 20); //Head
  rect(mouseX-10, mouseY, 25, 10); //Arm
  rect(mouseX+25, mouseY+20, 15, 25); //Leg
  triangle(mouseX+17.5, mouseY+32.5, mouseX+17.5, mouseY+27.5, mouseX+12, mouseY+32.5); //Toe
  fill(255);
  ellipse(mouseX, mouseY-50, 10, 10); //Eye
  fill(0);
  ellipse(mouseX-2, mouseY-50, 5, 5); //Pupil
}

void drawVillage() {
  //It takes a Village (Village Setup)
  rectMode(CENTER);
  fill(111, 83, 13);
  rect(x1, y1, 40, 30);
  triangle(x1-25, y1-15, x1+25, y1-15, x1, y1-40);

  rect(x2, y2, 40, 30);
  triangle(x2-25, y2-15, x2+25, y2-15, x2, y2-40);

  rect(x3, y3, 40, 30);
  triangle(x3-25, y3-15, x3+25, y3-15, x3, y3-40);
}

void mousePressed() {
  
  //Tongue Sticking Out Code
  println("Blep!");
  fill(255, 155, 255);
  frameRate(15);
  rect(mouseX-25, mouseY-35, 13, 5);
}