sheep -Speech

My program was inspired by old adventure games where you move in a direction by physically typing where you want to be. The twist was I wanted to make a non visual text adventure game- where the sounds you hear guide what’s going on. In this case, you play as a wanderer in an infinite valley that is trying to outrun a giant cat. The cats’ distance to you is indicated by the volume of a background sound effect, while the characteristics of what’s going on around you are told in the text to speech. You can also “listen” and reveal one of the squares around you in sound. There are three types of squares- normal, muddy (which slows you down), and a storm, which makes you unable to listen.

Ideally, this would be experienced on a laptop, and the participant would go on a journey though a strange infinite landscape. Ideally, unlike it is now, there would be a lot more to see, and the landscape would be more generative.

Here is a link to it in its present state: here

My sketches

 

//Special thanks to Ted Hopp for the move towards point code: https://stackoverflow.com/questions/8537202/how-to-make-a-entity-move-towards-a-x-and-y
//Also thanks to Golan Levin
//Credit to Florence Caillon for "Duo" or Katz Beat loop
//sheep 2018
var    listUpListen2 =[];
var    listDownListen2 = [];
var    listRightListen2 = [];
var    listLeftListen2 = [];
var fallback = false;
var enemySpeed = .05;
var xSpeed = 0;
var ySpeed = 0;
var numero = 0;
var factor = 0;
var fastX = 0;
var fastY = 0;
var mySpeechRecog;
var speech;
var confidence;
var voicesynthesizer;
var you;
var it;
var land;
var song;
var caught;
var restartState = false;
var upPosition;
var downPosition;
var leftPosition;
var rightPosition
var listenDist = 10;
 
 
function preload() {
  song = loadSound('assets/monster1.wav');
  caught = loadSound('assets/bonecrunch.mp3');
}
 
function setup() {
  createCanvas(1600, 900);
  confidence = 0;
  speech = "";
  initializeMySpeechRecognizer();
  voicesynthesizer = new p5.Speech();
  you = new Char();
  it = new Monster();
  land = new Arr();
  song.loop();
  voicesynthesizer.setVoice(4);
 
  voicesynthesizer.speak("The voice commmands are go north. go south. go east. go west. and listen. Say these and evade the large, hungry black cat that is hunting you. ");
}
//=========================================
function initializeMySpeechRecognizer() {
  mySpeechRecog = new p5.SpeechRec('en-US');
 
  mySpeechRecog.continuous = true; // do continuous recognition
  mySpeechRecog.interimResults = false; // allow partial recognition 
  mySpeechRecog.onResult = parseResult; // recognition callback
  mySpeechRecog.start(); // start engine
 
 
}
 
function parseResult() {
	confidence = mySpeechRecog.resultConfidence;
	if (confidence > 0.2){
		console.log(mySpeechRecog.resultString);
		speech = mySpeechRecog.resultString.split(' ').pop();
 
	if (speech == "up" || speech =="north" || speech == "North") {
 
	    you.up();
	    if (enemySpeed < .15){
	    enemySpeed +=.001;
		}
	    you.mudLose();
	    fallback = true;
 
	  }
	  if (speech == "down" || speech == "south" || speech == "South") {
	    you.down();
	    	    if (enemySpeed < .15){
	    enemySpeed +=.001;
		}
	    fallback = true;
	    you.mudLose();
	  }
	  if (speech== "right" || speech == "rite" || speech == "East" || speech == "east") {
	    you.right();
	    	    if (enemySpeed < .15){
	    enemySpeed +=.003;
		}
		fallback = true;
	    you.mudLose();
	  }
	  if (speech == "left"|| speech =="west" || speech == "West" ) {
	    you.left();
	    	    if (enemySpeed < .15){ enemySpeed +=.001; } fallback = true; you.mudLose(); } if (speech == "listen"){ you.listen(); } } } //==================================== function draw() { background(255-numero); numero +=1; if (restartState === true) { background(255); speech = ""; confidence = 0; you = new Char(); it = new Monster(); land = new Arr(); caught.play(); song.stop(); song.loop(); restartState = false; upPosition = 0; downPosition = 0; leftPosition = 0; rightPosition = 0; listenDist = 10; restartState = false; enemySpeed = .05; xSpeed = 0; ySpeed = 0; factor = 0; fastX = 0; fastY = 0; numero = 0; } it.move(); song.setVolume(2/you.monsterdistance()); } function Char() { this.x = 400; this.y = 400; this.func; this.speed = 30; this.mudon = 0; this.display = function() { fill(255); ellipseMode(CENTER); ellipse(this.x, this.y, 10, 10); }; this.up = function() { land.landShift("up"); this.func = land.check(); if (this.func == "storm"){ you.storm(); } if (this.func == "mud"){ you.mud(); } if (this.func == "dont"){ you.doNothing(); } fastX = 0; fastY = this.speed; this.func = ""; it.fallback(); }; this.down = function() { land.landShift("down"); this.func = land.check(); if (this.func == "storm"){ you.storm(); } if (this.func == "mud"){ you.mud(); } if (this.func == "dont"){ you.doNothing(); } fastX = 0; fastY = -this.speed; this.func = ""; it.fallback(); }; this.left = function() { land.landShift("left"); this.func = land.check(); if (this.func == "storm"){ you.storm(); } if (this.func == "mud"){ you.mud(); } if (this.func == "dont"){ you.doNothing(); } fastX = this.speed; fastY = 0; this.func = ""; it.fallback(); }; this.right = function() { land.landShift("right"); this.func = land.check(); if (this.func == "storm"){ you.storm(); } if (this.func == "mud"){ you.mud(); } if (this.func == "dont"){ you.doNothing(); } fastX = -this.speed; fastY = 0; this.func = ""; it.fallback(); }; this.listen = function() { land.listen(); }; this.mudLose = function() { if (this.mudon > 0) {
      this.mudon -= 1;
    }
    if (this.mudon === 0) {
      this.speed = 30;
    }
  };
 
  this.mud = function() {
    this.speed = 5;
    this.mudon = 3;
    voicesynthesizer.speak("You fell into a mud pit. your speed is lowered.");
  };
 
  this.storm = function() {
    listenDist = 0;
    voicesynthesizer.speak("You are in a storm. the rain and thunder blocks out most sounds.");
  };
 
  this.doNothing = function() {
  	listenDist = 10;
    voicesynthesizer.speak("Nothing is happening here.");
  };
 
  this.monsterdistance = function() {
  	if ((round(((sqrt(sq(it.x - this.x)) + sqrt(sq(it.y - this.y)))))) < 2) {
  		restartState = true;
  	}
    return (round(((sqrt(sq(it.x - this.x)) + sqrt(sq(it.y - this.y))))));
  }
};
 
 
function Monster() {
  this.x = 700;
  this.y = 400;
 
  this.speed = enemySpeed;
  this.display = function() {
    fill(0);
    ellipseMode(CENTER);
    ellipse(this.x, this.y, 10, 10);
 
  };
  this.showX = function() {
  	return this.x;
  }
    this.showY = function() {
  	return this.y;
  }
  this.move = function() {
  	this.speed = enemySpeed;
    xSpeed = (this.x - you.x) / 2;
    ySpeed = (this.y - you.y) / 2;
    factor = this.speed / sqrt(xSpeed * xSpeed + ySpeed * ySpeed);
    xSpeed *= factor;
    ySpeed *= factor;
    this.x -= xSpeed;
    this.y -= ySpeed;
 
 
 
  }
  this.fallback = function() {
  	this.x += fastX;
  	this.y += fastY;
  }
 
 
};
 
function Arr() {
  this.x = 340;
  this.y = 340;
  this.list = [];
  this.words = ['dont', 'dont','dont','dont','dont','mud','mud', 'mud','storm'];
  for (g = 0; g < 12; g++) {
    append(this.list, []);
    for (c = 0; c < 12; c++) {
      append(this.list[g], random(this.words));
    }
  }
 
  this.display = function() {
    for (c = 0; c < this.list.length; c++) {
      for (h = 0; h < this.list[c].length; h++) {
        text(""+(this.list[c][h]) + "",this.x + (10 * h), this.y + (10 * c));
      }
    }
  };
 
  this.listen = function() {
 
 
  	 var speak = true;
    for (v = 0; v < this.list.length-1; v++){
    	for (i = 0; i < this.list.length-1;i++){
    		if (speak == true){
 
 
    			var angle =  (atan2(this.y + (10 * v)-you.y,this.x + (10 * i)-you.x));
 
    			var distance = sqrt(sq(this.x + (10 * i)-you.x)+sq(this.y+(10 * v)-you.y));
 
 
    			if (angle== (3*PI)/2 && distance <= listenDist && distance!=0 && this.list[v][i]!= "dont"){
    				voicesynthesizer.speak("You can hear the " + this.list[v][i] + " to your North");
    				speak = false;
    	}
    	    	else if (angle==PI && distance <= listenDist&&  distance!=0 &&this.list[v][i]!= "dont"){
    		voicesynthesizer.speak("You can hear the bubbling of the " + this.list[v][i] + " to your Left");
    		speak = false;
    	}
    	    	else if (angle==(PI)/2 && distance <= listenDist &&  distance!=0 &&this.list[v][i]!= "dont"){
    		voicesynthesizer.speak("You can hear the sloshing of the " + this.list[v][i] + " down south");
    		speak = false;
    	}
    	    	else if (angle==0 && distance <= listenDist &&  distance!=0 &&this.list[v][i]!= "dont"){
    		voicesynthesizer.speak("You can hear rushing of the " + this.list[v][i] + " to your Right");
    		speak = false;
    	}
 
    		}
 
    	}
    	}
 
    voicesynthesizer.speak("You can't hear anything else.");
    		speak = false;
 
  };
 
  this.check = function() {
    for (c = 0; c < this.list.length; c++) {
      for (h = 0; h < this.list[c].length; h++) {
        if (this.x + (10 * h) == you.x && this.y + (10 * c) == you.y) {
 
          	return this.list[c][h];
        }
      }
    }
  };
 
  this.landShift = function(dir) {
    if (dir == "down") {
      for (g = 0; g < this.list.length-1; g++) {
        this.list[g] = this.list[g + 1];
      }
     this.list.splice(this.list.length-1,1);
     var list1 = [];
     for (h = 0; h < 12;h++){
     	append(list1, random(this.words));
     }
     append(this.list, list1);
 
 
 
    }
 
    if (dir == "up") {
      for (g = 0; g < this.list.length - 1; g++) {
        this.list[this.list.length - g-1] = this.list[this.list.length -g-2];
 
      }
      var list2 = [];
		for (h = 0; h < 12;h++){
		append(list2, random(this.words));
		 }
      this.list[0] = list2;
 
 
 
    }
    if (dir == "left") {
      for (h = 0; h < this.list.length - 1; h++) {
        for (g = 0; g < this.list.length - 2; g++) {
          this.list[h][this.list.length - 1 - g] = this.list[h][this.list.length- 2 - g];
 
        }
      }
      var list3 = [];
      for (h = 0; h < 12;h++){
		append(list3, random(this.words));
		 }
      for (h = 0; h < this.list.length - 1; h++) {
        this.list[0][h] = list3[h];
        }
      }
 
 
      if (dir == "right") {
        for (g = 0; g < this.list.length - 1; g++) {
          for (c = 0; c < 12; c++) {
            this.list[g][c] = this.list[g][c + 1];
          }
        }
         var list4 = [];
      for (h = 0; h < 12;h++){
		append(list4, random(this.words));
		 }
      for (h = 0; h < this.list.length - 1; h++) {
        this.list[h][this.list.length-1] = list4[h];
        }
 
      }
 
    }
 
}