Please download the files and play the game though local server. I tried uploading the files to both wordpress and the andrew webite that students are given but, neither work.
This project is a continuation of project that I did in a previous class and wanted to expand on. Roger signed off on this agreeing that I would make it clear what was pre-made. ONLY the audio and mic input functions are new. Everthing esle was made preiviously. I have also sectioned off and uncommented the code that is not new and marked it “Pre-made DO NOT GRADE”.
This added in audio function is an exploration on simple machine learning. For a little while I was trying to use recordings and slice those recordings into arrays to make the audio. But this proved too dificult for my skill level and also did not really achive the effect I wanted. So instead how the program works is that there is a very sensative volume monitor analyzing input from the mic and then depending on how loadly you talk (or sing or hum or what ever) the program puts in diffrent sound files.
As I said the monitor is very sensative and the game it ment to be a little dificult. A simple cheet that I’ve found is that singing or humming work better then actually talking.
//Pre-made DO NOT GRADE
///////////////////////////////////
var background_sound;
var end_sound;
var bgs;
var bgi;
var character;
var feed;
var clean;
var talk;
var ending1 = false;
var ending2 = false;
var hunger = 3;
var MAX_HUNGER = 10;
var dirty = 3;
var MAX_DIRTY = 10;
var purity = 10
var MAX_PURITY = 20
var volume = 0;
var mic;
var pixelScale = 4;
var idle_animation;
var play_animation;
var board_animation;
var barf_animation;
var die_animation;
var dirty_animation;
var clean_animation;
var tooClean_animation;
var feed_icon;
var feed_icon_roll;
var fire_image
var house_image;
////////////////////////////////
//sound variables
var play_sound;
var barf_sound;
var hunger_sound;
var chat_sound;
var tooLoud_sound;
var ah_sound;
var eee1_sound;
var eee2_sound;
var talk_sound;
var haEh_sound;
var nahnah_sound;
var hello_sound;
var no_sound;
var nonono_sound;
var yes_sound;
var playCleanHouse_sound;
var help_sound;
var look_sound;
var tooMuch_sound;
var stop_sound;
var good_sound;
var pleaseHelp_sound;
var thankYou_sound;
var whatIs_sound;
var stopIt_sound;
var youAre_sound;
var iNeedYou_sound;
var doYou_sound;
var clean2_sound;
var fun_sound;
var thisFeels_sound;
var thisIs_sound;
var who_sound;
var tooClean_sound;
var Clean_sound;
//variables that will keep track of how sounds files change
var talk = 0
var talkIncrease = .01
var MAX_TALK = 10
function preload() {
//Pre-Made DO NOT GRADE
////////////////////////////////////////////////////////////////////
background_sound = loadSound("assets/bg.mp3");
end_sound = loadSound("assets/end.mp3");
sprite_sheet = loadSpriteSheet('assets/idle.png', 65, 65, 48);
idle_animation = loadAnimation(sprite_sheet);
sprite_sheet = loadSpriteSheet('assets/play.png', 65, 65, 60);
play_animation = loadAnimation(sprite_sheet);
sprite_sheet = loadSpriteSheet('assets/board.png', 65, 65, 12);
board_animation = loadAnimation(sprite_sheet);
sprite_sheet = loadSpriteSheet('assets/lazer.png', 65, 65, 23);
barf_animation = loadAnimation(sprite_sheet);
sprite_sheet = loadSpriteSheet('assets/clean.png', 65, 65, 37);
clean_animation = loadAnimation(sprite_sheet);
sprite_sheet = loadSpriteSheet('assets/tooClean.png', 65, 65, 44);
tooClean_animation = loadAnimation(sprite_sheet);
sprite_sheet = loadSpriteSheet('assets/dirty.png', 65, 65, 21);
dirty_animation = loadAnimation(sprite_sheet);
bg_image = loadImage("assets/bg.png");
end_image = loadImage("assets/end.png");
fire_image = loadImage("assets/fire.png");
house_image = loadImage("assets/house.png");
feed_icon = loadImage("assets/feed_button.png");
feed_icon_roll = loadImage("assets/feed_button_roll.png");
clean_icon = loadImage("assets/feed_button.png");
clean_icon_roll = loadImage("assets/feed_button_roll.png");
talk_icon = loadImage("assets/feed_button.png");
talk_icon_roll = loadImage("assets/feed_button_roll.png");
idle_animation.frameDelay = 8;
play_animation.frameDelay = 12;
tooClean_animation.frameDelay = 12;
clean_animation.frameDelay = 8
/////////////////////////////////////////////////////////////////
//load sound
eat_sound = loadSound("assets/eat.wav");
barf_sound = loadSound("assets/barf.wav");
hunger_sound = loadSound("assets/chirp.wav");
die_sound = loadSound("assets/die.wav");
tooLoud_sound = loadSound("assets/tooLoud.wav");
chat_sound = loadSound("assets/chat.wav");
ah_sound = loadSound("assets/ah.mp3");
eee1_sound = loadSound("assets/eee1.wav");
eee2_sound = loadSound("assets/eee2.mp3");
talk_sound = loadSound("assets/talk.wav");
haEh_sound = loadSound('assets/haEh.mp3');
nahnah_sound = loadSound('assets/nahnah.mp3');
hello_sound = loadSound('assets/hello.mp3');
no_sound = loadSound('assets/no.mp3');
nonono_sound = loadSound('assets/nonono.mp3');
yes_sound = loadSound('assets/yes.mp3');
playCleanHouse_sound = loadSound('assets/playCleanHouse.mp3');
help_sound = loadSound('assets/help.mp3');
look_sound = loadSound('assets/look.mp3');
tooMuch_sound = loadSound('assets/tooMuch.mp3');
stop_sound = loadSound('assets/stop.mp3');
good_sound = loadSound('assets/good.mp3')
pleaseHelp_sound = loadSound('assets/pleaseHelp.mp3');
thankYou_sound = loadSound('assets/thankYou.mp3');
whatIs_sound = loadSound('assets/whatIs.mp3');
stopIt_sound = loadSound('assets/stopIt.mp3');
youAre_sound = loadSound('assets/youAre.mp3');
iNeedYou_sound = loadSound('assets/iNeedYou.mp3')
doYou_sound = loadSound('assets/doYou.mp3');
clean2_sound = loadSound('assets/clean.mp3');
fun_sound = loadSound('assets/fun.mp3');
thisFeels_sound = loadSound('assets/thisFeels.mp3');
thisIsFun_sound = loadSound('assets/thisIsFun.mp3');
who_sound = loadSound('assets/who.mp3');
tooClean_sound = loadSound("assets/tooClean.wav")
clean_sound = loadSound("assets/Clean.wav");
}
function setup() {
//set up mic input
mic = new p5.AudioIn();
mic.start();
//Pre-Made DO NOT GRADE
////////////////////////////////////////////////////////////////////
var canvas = createCanvas(150, 150);
bgs = background_sound.play();
background_sound.loop();
canvas.style("width", width * pixelScale + "px");
canvas.style("height", height * pixelScale + "px");
noSmooth();
bgi = createSprite(width/2,(height/2)-3,150,145);
character = createSprite(77, 41, 65, 65);
character.addAnimation('idle', idle_animation);
character.addAnimation('play', play_animation);
character.addAnimation('board', board_animation);
character.addAnimation('barf', barf_animation);
character.addAnimation('clean', clean_animation);
character.addAnimation('tooClean', tooClean_animation);
character.addAnimation('dirty', dirty_animation);
character.addAnimation('fire',fire_image);
character.addAnimation('house',house_image);
bgi.addAnimation("bg",bg_image);
bgi.addAnimation("end",end_image);
feed = createSprite(4, 32, 4, 4);
clean = createSprite(18, 32, 4, 4);
feed.addImage(feed_icon);
clean.addImage(feed_icon);
////////////////////////////////////////////////////////////////////
//Pre-Made DO NOT GRADE
////////////////////////////////////////////////////////////////////
feed.onMousePressed = function() {
if (character.getAnimationLabel() == "idle" || character.getAnimationLabel() == "board") {
if(purity <= 0){
bgs = end_sound.play();
bgi.changeAnimation("end");
character.changeAnimation("fire");
character.animation.rewind();
ending1 = true
feed.remove();
clean.remove();
}
if(purity >= MAX_PURITY){
bgs = end_sound.play();
bgi.changeAnimation("end");
character.changeAnimation("fire");
character.animation.rewind();
ending2 = true
feed.remove();
clean.remove();
}
hunger -= 4;
purity += 1
if (hunger >= 0 ) {
character.changeAnimation("play");
character.animation.rewind();
eat_sound.play();
}
if (hunger <= 0) {
hunger = 0;
purity -=5
character.changeAnimation("barf");
character.animation.rewind();
barf_sound.play();
}
}
}
feed.onMouseOver = function() {
feed.addImage(feed_icon_roll);
}
feed.onMouseOut = function() {
feed.addImage(feed_icon);
}
clean.onMousePressed = function() {
if (character.getAnimationLabel() == "idle" || character.getAnimationLabel() == "dirty") {
if(purity <= 0){
bgs = end_sound.play();
bgi.changeAnimation("end");
character.changeAnimation("fire");
character.animation.rewind();
ending1 = true
feed.remove();
clean.remove();
}
if(purity >= MAX_PURITY){
bgs = end_sound.play();
bgi.changeAnimation("end");
character.changeAnimation("fire");
character.animation.rewind();
ending2 = true
feed.remove();
clean.remove();
}
dirty-= 1;
purity += 1
if (dirty >= 0){
character.changeAnimation("clean");
character.animation.rewind();
clean_sound.play();
}
if (dirty <= 0){
purity -=5
dirty = 0;
character.changeAnimation("tooClean");
character.animation.rewind();
tooClean_sound.play();
}
}
}
clean.onMouseOver = function() {
clean.addImage(feed_icon_roll);
}
clean.onMouseOut = function() {
clean.addImage(feed_icon);
}
}
////////////////////////////////////////////////////////////////////
function draw() {
var v = mic.getLevel(); //get volume of mic
volume += (v-volume)/3; //smooth out reading of volume
var micMap = map(volume, 0, 1, 10, 100); // map volume
if(ending1 == false || ending2 == false){ //only activate if endings are false
if(talk <= 0){ // set when to change sound
//if mic is less than 30 then uncofertable sound plays and purity goes down
if (micMap >= 30 ){
purity -= .1
eee1_sound.play();
}
//if between 20 and 30 then chat souns play
if (micMap > 20 & micMap < 30 ){
talk_sound.play();
//talk increase when talk to it softly
if(talk <=MAX_TALK){
talk += talkIncrease
}
}
}
//repeat similar set up for 9 more levels
if(talk <= 1 & talk > 0){
if (micMap >= 30 ){
purity -= .1
eee1_sound.play();
}
if (micMap > 20 & micMap < 30 ){
chat_sound.play();
if(talk <=MAX_TALK){
talk += talkIncrease
}
}
}
if(talk <= 2 & talk > 1){
hunger_sound = ah_sound
if (micMap >= 30 ){
purity -= .1
eee2_sound.play();
}
if (micMap > 20 & micMap < 30 ){
ah_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
if(talk <= 3 & talk > 2){
hunger_sound = nahnah_sound
if (micMap >= 30 ){
purity -= .1
nahnah_sound.play();
}
if (micMap > 20 & micMap < 30 ){
haEh_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
if(talk <= 4 & talk > 3){
hunger_sound = no_sound;
clean_sound = yes_sound;
eat_sound = yes_sound;
tooClean_sound = nonono_sound;
if (micMap >= 30 ){
purity -= .1
nonono_sound.play();
}
if (micMap > 20 & micMap < 30 ){
hello_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
if(talk <= 5 & talk > 4){
hunger_sound = stop_sound;
clean_sound = yes_sound;
eat_sound = yes_sound;
tooClean_sound = nonono_sound;
if (micMap >= 30 ){
purity -= .1
nonono_sound.play();
}
if (micMap > 20 & micMap < 30 ){
playCleanHouse_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
if(talk <= 6 & talk > 5){
hunger_sound = help_sound;
clean_sound = good_sound;
eat_sound = good_sound;
tooClean_sound = tooMuch_sound;
if (micMap >= 30 ){
purity -= .1
tooMuch_sound.play();
}
if (micMap > 20 & micMap < 30 ){
look_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
if(talk <= 7 & talk > 6){
hunger_sound = pleaseHelp_sound;
clean_sound = thankYou_sound;
eat_sound = thankYou_sound;
tooClean_sound = tooMuch_sound;
if (micMap >= 30 ){
purity -= .1
tooMuch_sound.play();
}
if (micMap > 20 & micMap < 30 ){
whatIs_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
if(talk <= 7 & talk > 6){
hunger_sound = pleaseHelp_sound;
clean_sound = clean2_sound;
eat_sound = fun_sound;
tooClean_sound = tooMuch_sound;
if (micMap >= 30 ){
purity -= .1
stopIt_sound.play();
}
if (micMap > 20 & micMap < 30 ){
whatIs_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
if(talk <= 8 & talk > 7){
hunger_sound = iNeedYou_sound;
clean_sound = thisFeels_sound;
eat_sound = thisIsFun_sound;
tooClean_sound = stopIt_sound;
if (micMap >= 30 ){
purity -= .1
youAre_sound.play();
}
if (micMap > 20 & micMap < 30 ){
doYou_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
if(talk > 8){
hunger_sound = iNeedYou_sound;
clean_sound = thisFeels_sound;
eat_sound = thisIsFun_sound;
tooClean_sound = stopIt_sound;
if (micMap >= 30 ){
purity -= .1
youAre_sound.play();
}
if (micMap > 20 & micMap < 30 ){
who_sound.play();
if(talk <= MAX_TALK){
talk += talkIncrease
}
}
}
}
//Pre-Made DO NOT GRADE
////////////////////////////////////////////////////////////////////
background(0);
print(talk)
if(frameCount % 800 == 0)
{
if(hunger<MAX_HUNGER){
hunger+=2;
}
if(dirty<MAX_DIRTY){
dirty+=1;
}
if((hunger>8 & ending1 == false) || (dirty>=MAX_DIRTY && ending2 == false)){
character.changeAnimation("board");
hunger_sound.play();
}
if((dirty>8 & ending1 == false) || (dirty>=MAX_DIRTY && ending2 == false)){
character.changeAnimation("dirty");
hunger_sound.play();
}
if((hunger>=MAX_HUNGER & ending1 == false)|| (dirty>=MAX_DIRTY && ending2 == false)){
purity -=5
}
if((dirty>=MAX_DIRTY && ending1 == false) || (dirty>=MAX_DIRTY && ending2 == false)){
purity -=5
}
}
if (character.getAnimationLabel() == "play" && character.animation.getFrame() == character.animation.getLastFrame()) {
character.changeAnimation("idle");
}
if (character.getAnimationLabel() == "barf" & character.animation.getFrame() == character.animation.getLastFrame()) {
character.changeAnimation("idle");
}
if (character.getAnimationLabel() == "clean" & character.animation.getFrame() == character.animation.getLastFrame()) {
character.changeAnimation("idle");
}
if (character.getAnimationLabel() == "tooClean" & character.animation.getFrame() == character.animation.getLastFrame()) {
character.changeAnimation("idle");
}
drawSprites();
{
if(ending1 == false & ending2 == false){
noStroke()
textSize(5);
fill(60);
var rectangleLength = map(hunger, 0, MAX_HUNGER, 0, 20);
rect(9,30,3,floor(rectangleLength));
text('play',2, 25);
var rectangleLength = map(dirty, 0, MAX_DIRTY, 0, 20);
rect(22,30,3,floor(rectangleLength));
text('clean',18, 25);
var rectangleLength = map(micMap, 0, 50, 0, 20);
text('volume', 40, 83);
rect(40, 85,floor(rectangleLength),3);
fill(255);
var rectangleLength = map(purity, 0, MAX_PURITY, 0, 20);
rect(125,30,5,floor(rectangleLength));
text('purity', 125,25);
}
if (ending1 == true){
character.changeAnimation("fire");
noStroke();
fill(255);
textSize(6);
textAlign(CENTER);
text("it's free. it's made it's jugement. everything is gone.",width/2, height*.75);
}
if (ending2 == true){
character.changeAnimation("house");
noStroke();
fill(255);
textSize(6);
textAlign(CENTER);
text("finaly. its free. the world can now be pure.",width/2, height*.75);
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////