xxxxxxxxxx
147
// Connie Hu
// Code! 2 - assignment 2
// New code is everything related to sounds added. If you'd like to see, use CTRL - F and search for the word 'sound'
// initializing variables
let right_eye
let left_eye
let gravity = 0.1
let button
let song1
let song2
let song3
// preload images
function preload(){
lemon = loadImage('images/lemon.png');
headbang = loadImage('images/beavis_butthead.gif');
bababa = loadImage('images/king_of_the_hill.gif');
doraemon_nose = loadImage('images/doraemon.png');
notepad = loadImage('images/notepad_blues_clues.png');
//preload 2 of the songs that don't start out playing
song2 = loadSound("songs/song2.mp3")
song3 = loadSound("songs/song3.mp3")
}
// setup
function setup() {
createCanvas(400, 450);
// callback setup for first song that will start playing when file runs
song1 = loadSound("songs/song1.mp3", loaded)
// button that will be used to control / change songs
button = createButton("Song 1");
button.mousePressed(togglePlaying);
//create new instances of objects according to classes/blueprints - in sepparate files
left_eye = new Eye (145, 170, 75, 75);
right_eye = new Eye (255, 170, 75, 75);
bouncing_head = new Bounce(60, 0, 50, 50)
}
// functions for changing songs!
// start with playing song 1
function loaded() {
song1.play();
}
// toggele between 3 songs!
function togglePlaying() {
if(song1.isPlaying()) {
song1.pause();
song2.play();
song2.setVolume(0.3);
button.html("Song 2");
} else if(song2.isPlaying()) {
song2.pause();
song3.play();
song3.setVolume(0.3);
button.html("Song 3")
} else {
song3.pause();
song1.play();
song1.setVolume(0.3);
button.html("Song 1")
}
}
// draw function, continuously reloads
function draw() {
background(185, 255, 79);
// song.setVolume(slider.value())
image(bababa, -30, 0, 220, 195 ) // top left corner
// body/yellow shirt
strokeWeight(2);
stroke(0);
fill(247, 189, 86); // shirt color
rect(40, 320, 300, 200, 20);
// outline/stroke and fill color for face and arms
stroke(209, 173, 140);
strokeWeight(2);
fill(241, 202, 161);
// arm holding notepad
rect(320, 300, 60, 200, 10); // arm
image(notepad, 300, 210, 100,100)
// face
ellipse(200, 200, 230, 280);
// glasses
// lenses
stroke(71, 58, 99);
strokeWeight(5);
fill(111, 231, 215);
ellipse(255, 80, 90, 85);
ellipse(155, 80, 90, 85);
//connector
stroke(14, 52, 76);
strokeWeight(2);
fill(188, 140, 226);
rect(185, 60, 40, 10, 20);
// Nose - Doraemon's Head
image(doraemon_nose, 185, 205, 35, 35)
// Mouth - a bit conveluted but I like how it looks. I drew inspiration from my frog last semester, but personalized it to be proportional to my self portrait face
stroke(0);
strokeWeight(5);
line(165, 267, 235, 267);
noStroke();
fill(255, 92, 92); // tongue color red
arc(210, 269, 30, 50, 0, PI, CHORD);
// shirt design
// BEAVIS AND BUTTHEAD HAHAHAHHHAHHAHAHAHAHA
image(headbang, 145, 345, 120, 95)
// make eyes appear
// class in sepparate folder called 'eye'
left_eye.show();
right_eye.show();
// make bouncing doraemon appear and update according to class instructions
// class in sepparate folder called 'bounce'
bouncing_head.display();
bouncing_head.update();
}