Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
//Shannon Umerez   991514126
//Interactive toy project


//* -->click the mouse to eat the circle and grow
//* -->once you get too big, you change characters and settings
    
//variables


//Location of moving pebble
int x = 400;
//Size of creature
int creatureSize = 50;
int sunX = 50;
int sunY = 50;
//variables to make sun rays move
int sunRayX = 90;
int sunRayY= 35;
int cloudSpeed = 0;
int creature = 1;
//seaweed movement
float sw = 400;
float starPositionX;
float starPositionY;


void setup(){
 //set size of screen
  size(400,400); 
}

void draw(){
 //set backgroud to white
  //set framerate to 60 frames per second
  frameRate(60);
  rectMode(CENTER);
  smooth();
  drawBackground();
  drawSun();
  drawCreature();
  drawCircle();
  
 
 //if cirles is at less than 0 then reset on other side of screen
  if (x<0){
  x=400;
  }
  //variable to make seaweed move from right to left
  //once reaches end of screen then resets
  if (sw<=0){
  sw=400;
  }
 //if cloud is more than the screen then reset to other side
  if (cloudSpeed>400){
  cloudSpeed=0;
  }
}


///draww backgrounds according to creature///
void drawBackground(){
  background(175,238,238);
 //change backgrounds according to creature type 
  if (creature==1){
//make the grass tirange background 
   fill(50,205,50);  
    for(int q = 10;q < 400; q+=20){
      triangle(q,160,q-10,width/2,q+10,width/2);
     }
    
//second row of triangles
    fill(107,142,35);
    for(int i = 0; i < 400; i+=20){
      triangle(i, 170, i-10,width/2,i+10,width/2);
    }
    rect(width/2, 300, 400, 200 );
     drawSun();
     drawClouds();
  }
  else if (creature==2){
    background(0); 
    fill(34,139,34);
 //make the grass tirange background
    for(int w = 10;w < 400; w+=20){
      triangle(w,160,w-10,width/2,w+10,width/2);
     }
    
//second row of triangles
    fill(107,142,35);
    for(int i = 0; i < 400; i+=20){
      triangle(i, 170, i-10,width/2,i+10,width/2);
    }
    rect(width/2, 300, 400, 200);
    drawSun();
    drawClouds();
    
     //draw stars
     fill(255);
     ellipse(30,100, 3+sin(frameCount), 3+sin(frameCount));
     ellipse(50,60, 3+sin(frameCount),3+sin(frameCount));
     ellipse(70,90, 3+sin(frameCount),3+sin(frameCount));
     ellipse(100, 20, 3+sin(frameCount),3+sin(frameCount));
     ellipse(115,30, 3+sin(frameCount),3+sin(frameCount));
     ellipse(124, 80, 3+sin(frameCount),3+sin(frameCount));
     ellipse(130, 70,3+sin(frameCount),3+sin(frameCount));
     ellipse(120, 100, 3+sin(frameCount),3+sin(frameCount));
     ellipse(110, 150, 3+sin(frameCount),3+sin(frameCount));
     ellipse(200, 90,3+sin(frameCount),3+sin(frameCount));
     ellipse(198, 170, 3+sin(frameCount),3+sin(frameCount));
     ellipse(150, 150, 3+sin(frameCount),3+sin(frameCount));
     ellipse(140, 140,3+sin(frameCount),3+sin(frameCount));
     ellipse(145, 100, 3+sin(frameCount),3+sin(frameCount));
     ellipse(230,100, 3+sin(frameCount), 3+sin(frameCount));
     ellipse(250,60, 3+sin(frameCount),3+sin(frameCount));
     ellipse(270,90, 3+sin(frameCount),3+sin(frameCount));
     ellipse(300, 20, 3+sin(frameCount),3+sin(frameCount));
     ellipse(315,30, 3+sin(frameCount),3+sin(frameCount));
     ellipse(224, 80, 3+sin(frameCount),3+sin(frameCount));
     ellipse(230, 70,3+sin(frameCount),3+sin(frameCount));
     ellipse(220, 100, 3+sin(frameCount),3+sin(frameCount));
     ellipse(310, 150, 3+sin(frameCount),3+sin(frameCount));
     ellipse(300, 90,3+sin(frameCount),3+sin(frameCount));
     ellipse(398, 170, 3+sin(frameCount),3+sin(frameCount));
     ellipse(350, 150, 3+sin(frameCount),3+sin(frameCount));
     ellipse(340, 140,3+sin(frameCount),3+sin(frameCount));
     ellipse(345, 100, 3+sin(frameCount),3+sin(frameCount));
  }
  else if (creature==3){
    //fish background bubbles
    rectMode(CORNERS);
    fill(127,255,212);
    rect(0,100+sin(frameCount*.025),400,150);
    fill(64,224,208);
    rect(0,150+sin(frameCount*.25),400,400);
    fill(46,139,8);
    for(int w = 10;w < 400; w+=20){
      triangle(w,380,w-10,height,w+10,height);
     }
    drawSeaweed();
   
  }
}

//draw moving coulds//
void drawClouds(){
  //draw clouds that move accross screen
  fill(255);
  noStroke();
  ellipse(cloudSpeed+10, 30, 50,20);
  ellipse(cloudSpeed,15, 30,22);
  ellipse(cloudSpeed-5,40, 40,30);
  cloudSpeed= cloudSpeed+1;
}


void drawSun(){
 //if creature 1 is shown then draw shining sun
  if (creature==1){
    fill (255,255,0);
    noStroke();
    ellipse(sunX,sunY, 70,70);
 //makes rays move
    triangle(sunRayX, sunRayY,sunRayX, sunRayY+30, sunRayX+30+(1*sin(frameCount)), sunRayY+15+(1*sin(frameCount)));
    triangle(sunRayX-25,sunRayY+55, sunRayX-55,sunRayY+55,sunRayX-40+(1*sin(frameCount)), sunRayY+80+(1*sin(frameCount)));
  }
  //if creature 2 is show then draw moon
  else if(creature==2){
    fill(250,240,230);
    noStroke();
    ellipse(sunX,sunY, 70,70);
    fill(220,220,220);
    ellipse(sunX+10,sunY+20,10,10);
    ellipse(sunX-10,sunY-27,15,10);
    ellipse(sunX+5,sunY+5,15,20);
  }
}


void drawSeaweed(){
 //draw my seaweed
  fill(46,139,8);
  triangle(sw, 400, sw-10,400, sw-5,350);
  triangle(sw-5,350,sw-10,320,sw,320);
  triangle(sw-9,320,sw,325,sw+12,300);
  
  triangle(sw,400,sw-5,400,sw+10,360);
  triangle(sw+10,360, sw+15,340, sw+15,306);
  
  triangle(sw,400,sw-10,400,sw-15,365);
  triangle(sw-15,365,sw-13,350,sw-10,355);
//move left 1 pixel each screen (60 a sec)
  sw = sw-1;
}

void drawCircle(){
  //draw moving circle to eat
  fill(0);
  stroke(123);
  ellipse(x,height/4*2.5,20,20);
  x = x-3;
}


//draw my creature//


void drawCreature(){
 
  //draw spider
  if(creature==1){
    rectMode(CENTER);
    fill(0);
    ellipse(width/4, height/4*2.5, creatureSize,creatureSize);
    noFill();
    stroke(2);
    //right side legs
    line(width/4+10,height/4*2.5-5, 150,230);
    line(150,230,170,250);
    line(width/4+10,height/4*2.5,153,240);
    line(153,240,175,260);
    line(width/4+10,height/4*2.5,160,250);
    line(160,250,180,270);
    
    //left side legs
    line(width/4-10,height/4*2.5-5,50,230);
    line(50,230,35, 250);
    line(width/4+10,height/4*2.5,46,240);
    line(46,240,30,260);
    line(width/4+10,height/4*2.5,43,250);
    line(43,250,25,270);
    
    //sports wear
    fill(148,0,211);
    rect(width/4,height/4*2.5-7,creatureSize,creatureSize/3);
    
    //face
    fill(255);
    ellipse(width/4-10,height/4*2.5, 20,20);
    ellipse(width/4+10,height/4*2.5,10,10);
  }
  //draw ET
  else if(creature==2){
    rectMode(CORNERS);
    fill(160,82,45);
    rect(100,200,150,210);
    rect(150,210,140,215);
    rect(95,205,110,270);
    rect(95,270,130,275);
    rect(130,245,120,265);
    rect(120,265,140,270);
    
    ellipse(120,237,creatureSize-10,creatureSize-10);
  }
  //draw fish
  else if(creature==3){
    fill(255,165,0);
    stroke(1);
    triangle(127,240,60,260+sin(frameCount),60, 220+sin(frameCount));
    triangle(160,220,150,210,120,220);
    ellipse(145,240,creatureSize*2,creatureSize);
    triangle(155,240,135,230,140,250);
    fill(255);
    ellipse(180,240,10,10);
  }
}


  
void mousePressed(){
  
 //if circle is at square and mouse is pressed than reset the circle
 //increase the size of square
 //size +50 each time it eats circle
  
  //conditional!!!
  if(x <= width/4 + 60 && x >= width/4 - 50){
    x= 600;
    creatureSize = creatureSize +5;
  }
  
 //if the size of square is greater than or equal to 65 than "blow up"
  if (creatureSize >= 65){
    frameRate(1);
    background(0);
//every time size reaches 65, reset to 50 and add one to creature
    creatureSize = 50;
    creature = creature+1;
  }

  //if no more creature reset
  if(creature>3){
  creature = 1;
  }
}