Srishty’s Project 10

I made a simple story about a girl (me) who goes on a walk to the park. During her time there as she walks by, she sees tom and jerry start chasing each other all over the park and she starts laughing. The background d elements and all elements other than tom and jerry were done on illustrator and imported to imgur. My 4 characters are the cloud making the wind sound, the tom making the meow sound, the girl laughing, and the bird chirping.

sketch

// SRISHTY BHAVSAR
//SECTION C
//PROJECT 10
/*
I made a simple story about a girl (me) who goes on a walk to the park. During her time there as she walks by, 
she sees tom and jerry start chasing each other all over the park and
she starts laughing. The background d elements and all elements other than tom and jerry were done on illustrator
and imported to imgur. My 4 characters are the cloud making the wind sound, the tom making the meow sound, the girl 
laughing, and the bird chirping.
*/



// call global variables

//background image
var bgPhoto

//CHARACTERS
// cloud
    var cloudX = 0;

    // bird
    var birdImage = [];
    var birdX = 500;
    var birditem = 0;
    var birdwidth = 80

    // srishty (me)
    var srishtyImage;
    var srishtyx =500;

    // cloud
    var cloudImage;
    var cloudx = 300

    // tom and jerry
    var tomandjerry = [];
    var tomandjerryx = 70;
    var tomandjerryitem = 0;
    var tjdy = 1
    var tjdx = 1

// frame counter initializer
var count = 0; 




//load images to imgur
function preload() {
    bgPhoto = loadImage("https://i.imgur.com/75aDbMe.png");
    // images
    birdImage[0] = loadImage("https://i.imgur.com/o1P0pBO.png"); // first image in the bird list
    birdImage[1] = loadImage("https://i.imgur.com/48woLcm.png"); // first image in the bird list
    srishtyImage = loadImage("https://i.imgur.com/b5N2LzO.png"); // srishty image
    cloudImage = loadImage("https://i.imgur.com/xG8RjYF.png"); // cloud image
    tomandjerry[0] =loadImage("https://i.imgur.com/8nNCYkE.png");
    tomandjerry[1] =loadImage("https://i.imgur.com/cDSNU65.png");
    tomandjerry[2] =loadImage("https://i.imgur.com/LcYpbag.png");
    tomandjerry[3] =loadImage("https://i.imgur.com/wYhvMJo.png"); 

    //sounds
    wind = loadSound("https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/wind.wav");
    meow = loadSound("https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/meow.wav");
    laugh = loadSound("https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/laugh.wav");    
    chirp = loadSound("https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/chirp.wav");  
}


function soundSetup(){
    wind.setVolume(.1);
    meow.setVolume(2);
    chirp.setVolume(.1);
    laugh.setVolume(2);
}

function setup() {
    createCanvas(400, 400);
    //frameRate(5);
    imageMode(CENTER);
    useSound();

}

function draw() {
    count++; // add one frame to draw function
    //background image
    image(bgPhoto, width/2, height/2, width, height);



    wind.play();
    chirp.play();



    //call characters
    drawCloud();
    drawbird();
    drawTandJ()
    drawSrishty();
  
    if (count == 450 || count == 750) {
        meow.play();
    }
    if (count == 500 || count ==800) {
        laugh.play();
    }
}

// function for bird flapping

function drawbird() {

    image(birdImage[birditem], birdX, 104, birdwidth,30); 
    // if the frame counter is odd have the bird's item be the first one, if even have it be the second one 
    //fkapping affect 
    if (count % 2 === 0 ) { // bird frame 1
        birditem = 1;
        birdwidth = 100
        birdX -= .5; // bird flies to left
    }
    if (count % 2 === 1 ) {    // bird frame 0
        birditem = 0;
        birdwidth = 80;
        birdX -= .5; // bird flies to left
    }

}

function drawSrishty() {
    var heightcount = .5
    if (count >= 30) { // srishty walks in 30 frames after bird

        // staggering heights so it looks like walking rather than glide
        if (count % 2 === 0 ) { //odd
            image(srishtyImage, srishtyx - heightcount, 325, 66.2218, 205.4745); 
            srishtyx -= .3; // srishty walks to left

        }
        if (count % 2 === 1 ) { //even
            image(srishtyImage, srishtyx, 325 + heightcount, 66.2218, 205.4745); 
            srishtyx -= .3; // srishty walks to left

        }
    }

}

function drawCloud() { // draw cloud
    image(cloudImage, cloudx, 69, 130.2123 , 46.6313 );
    cloudx -= 0.09; //cloud moves very slowly
}

function drawTandJ() { // tom and jerry frames chasing eachother

        if (count >= 0 & count <= 400 ) { 
            image(tomandjerry[tomandjerryitem], tomandjerryx, 300, 216.9349, 162.7012);
            tomandjerryitem = 0
        }

        if (count >= 400 & count <= 500) { 
            image(tomandjerry[tomandjerryitem], (tomandjerryx + 100) + tjdx, 300, 216.9349, 162.7012);
            tomandjerryitem = 1
            tjdx += .5
        }

        if (count >= 500 & count <= 750) {
            image(tomandjerry[tomandjerryitem], (tomandjerryx + 300) -tjdx, 400 - tjdy, 220, 120.7012);
            tomandjerryitem = 2
            tjdy += .5;
            tjdx += .5
        }
        if (count >= 750 & count <= 2000 ) { 
            image(tomandjerry[tomandjerryitem], (tomandjerryx + 200)-tjdx, 400 - tjdy, 216.9349/2, 162.7012/2); 
            tomandjerryitem = 3
            tjdy += .5;
            tjdx += 2;

        }

}