Project_10_sonic-story

y_sketch_2Download
//Huijun Shen
//huijuns@andrew.cmu.edu
//Section D

//Story: It is a corner of a house. In the background, there is light music. Then the phone is ringing and the dog 
//hears the ring and bark. Then we can hear the sound of human step. The sound of the dog step. The man stops at
//the phone and pick it up and says "hello".

var frameCount = 0;
var chr,dogPic,bgSound,ringSound,dogSound,helloSound,walkSound,dogBark;



function preload() {
    // call loadImage() and loadSound() for all media files here
    bg = loadImage("https://i.imgur.com/MAsTt65.png");
    chr = loadImage("https://i.imgur.com/1Z57hnP.png");
    dogPic = loadImage("https://i.imgur.com/7h6Oxjz.png");

    // load sound
    bgSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/11/bg_music.wav");
    ringSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/11/telephone_ring.wav");
    dogSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/11/dog-on-wooden.wav");
    helloSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/11/hello.mp3");
    walkSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/11/walk-1.wav");
    dogBark = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/11/puppy_bark.wav");

}


function setup() {
    createCanvas(480,480);
    useSound();
    frameRate(10);

    //create character
    man = new Object();
    man.image = chr;
    man.x=-250;
    man.y=0;
    man.dx=6;
    man.draw = manDraw;

    dog = new Object();
    dog.image = dog;
    dog.x = 0;
    dog.y = 500;
    dog.dx = 10;
    dog.draw = dogDraw;

}


function soundSetup() { // setup for audio generation
    // you can replace any of this with your own audio code:
    bgSound.setVolume(0.1);
    ringSound.setVolume(0.3);
    walkSound.setVolume(0.5);
    dogSound.setVolume(0.6);
    helloSound.setVolume(0.7);

}


function draw() {
    // you can replace any of this with your own code:
    background(200);
    image(bg,0,0,600,600);

    //sound play

    if(frameCount == 0){
    bgSound.play();
    }

    if(frameCount == 90 || frameCount ==120 || frameCount ==150){
        ringSound.play();
    }


    if(frameCount == 180 ){
        walkSound.play();
        dogBark.play();
    }

    if(frameCount == 320){
        helloSound.play();
    }


    // man enters and stops
    if(frameCount >180 ){

        man.draw();
        man.x+=man.dx;
        
        if(frameCount >= 300){
            man.dx =0;
        }
    }
    
    // dog goes across the canvas
    if(frameCount > 190 ){
        
        dog.draw();
        dog.x+=dog.dx;

    }



    frameCount ++;

    if(frameCount == 400){
        noLoop();
    }
    

    print(frameCount);
}


function manDraw(){
    image(chr,this.x,this.y);
}


function dogDraw(){    
    image(dogPic,this.x,this.y,60,90);    
}

Story: It is a corner of a house. In the background, there is light music. Then the phone is ringing and the dog hears the ring and bark. Then we can hear the sound of human step. The sound of the dog step. The man stops at the phone and pick it up and says “hello”.

The codes worked for a while on my computer and worked for the first time on the page then it stops working. I spend a lot of time to figure out why but failed.

I basically code the numbers of the sound and the details is not possible for me to refine without hearing them.

I have tried my best.

The size is not right and also the bg sound is not playing even though other sound are playing sometimes.

Leave a Reply