xxxxxxxxxx
121
var germs = [];
var num = 10; //15
var currentTime = 0;
var startTime = 0;
var germPop;
var success;
// var squish;
var scream;
var timerAlpha = 250;
var score = 0;
var timer;
var hands;
var play = true;
var resetTime = 15000;
function preload(){
hands = loadImage('images/backgroundgame.png');
germ = loadImage('images/CUTEGERM.png');
germPop = loadSound('sounds/pop.wav');
success = loadSound('sounds/success.wav');
// squish = loadSound('sounds/squish.wav');
scream = loadSound('sounds/scream.wav');
}
function setup() {
createCanvas(600, 400);
textSize(60);
textAlign(CENTER);
germPop.setVolume(2);
success.setVolume(0.2);
scream.setVolume(0.8);
for(var i=0; i<num; i++){
germs[i] = new Germ();
}
// console.log("Kill the germs in under "+resetTime/1000+" seconds before they repoduce!");
startTime = millis();
}
function draw() {
background(255);
image(hands,0,0);
scream.rate(random(4,8));
currentTime = millis() //timestamp
// setInterval(console.log(germs.length),1000);
for(var i=germs.length-1; i>=0; i--){
// if (germs[i] === undefined) {
// continue;
// }
germs[i].display();
germs[i].move();
if(germs[i].disappear()){
germs.splice(i,1);
continue;
// console.log(germs.length + " germs left!");
}
for(var j=germs.length-1; j>=0; j--){
// if (germs[i] === undefined) {
// continue;
// }
if(i != j && germs[i].intersects(germs[j])){
germs[i].newGerm();
}
}
//produce germs if more than n seconds have elapsed
if(currentTime-startTime >= resetTime){
for(var t=germs.length; t<num; t++){
germs[t] = new Germ();
// console.log("Oops! Time ran out! The germs reproduced!");
germPop.play();
}
startTime = millis();
// score = score - 5;
score = 0;
// console.log(currentTime);
}
}
//win message
if(germs.length === 0){
fill(10, 32, 240,150);
text("GOOD JOB!", 300, 300);
playSuccess();
}
//timer
push();
timer = (resetTime-(currentTime-startTime))/1000;
textSize(30);
fill(255, 0, 200,timerAlpha);
text(floor(timer), 20, 30);
text("sec left", 92, 30);
pop();
//score
push();
textSize(30);
fill(255, 0, 200,255);
text("Score:",width-80, 30);
text(score,width-20, 30);
pop();
}
function mousePressed(){
for(var i=germs.length-1; i>=0; i--){
germs[i].explode();
}
}
function playSuccess(){
if(play == true){
success.play();
timerAlpha = 0;
}
play = false;
}