var Game = {};
var light = false;
var timerset = false;
var timersetflash = false;
var fading = false;
Game.fps = 50;



Game.initialize = function() {
  this.entities = [];
  this.context = document.getElementById("viewport").getContext("2d");
  
};

Game.fadeOutRectange = function(x, y, w, h, r, g, b) {
    var self = document.getElementById("viewport").getContext("2d");
    var steps = 50;
    var dr = (255 - r) / steps; // how much red should be added each time
    var dg = (255 - g) / steps; // green
    var db = (255 - b) / steps; // blue
    var count = 0; // step counter
    var interval = setInterval(function() {
        self.fillStyle = 'rgb(' + Math.round(r + dr * count) + ',' + Math.round(g + dg * count) + ',' + Math.round(b + db * count) + ')';
        self.fillRect(x, y, w, h); // will redraw the area each time
        count++;
        if(count === steps) { // stop if done
            clearInterval(interval);
            fading = false;
        }
    }, 30);
  };


Game.draw = function() {

  this.context.clearRect(0, 0, 512, 288);
  this.context.fillStyle = "#1F3D5C";
  this.context.fillRect(0, 0, 512, 288);
  
  /*if(timersetflash == false){ //flash timer
    setTimeout(function(){
      light = false;
      timersetflash = false;
    }, 200);
    timersetflash = true;
  }*/
  
  if(light == true ){ 
    this.context.fillStyle = "#FFFFFF";
    this.context.fillRect(0, 0, 512, 288);
    
    if(fading == false){
      fading = true;
      fadeOutRectange(0, 0, 512, 288, 31, 61, 92);
    }
    
    setTimeout(function() {
      light = false;
      timerset = false;
      flash = 0;
    }, 3000);
  }
  
  
  if(timerset == false){ //if we haven't set a timer yet, set one
    setTimeout(function(){
      light = true;
    }, 5000);
    timerset = true;
  }
  
  
  for (var i=0; i < this.entities.length; i++) {
    this.entities[i].draw(this.context);
  }
};

Game.update = function() {
  for (var i=0; i < this.entities.length; i++) {
    this.entities[i].update();
  }
};

Game.addRect = function(initX) {
  Game.entities.push(new Rect(initX));
};
Game.addRain = function() {
  Game.entities.push(new Rain());
};

Game.addPlayer = function(){
  Game.entites.push(new Player());
};

@@ -300,24 +300,603 @@
 g, b) %7B%0A    
+%0A  %7D;%0A%0A%0AGame.draw = function() %7B%0A%0A  this.context.clearRect(0, 0, 512, 288);%0A  this.context.fillStyle = %22#1F3D5C%22;%0A  this.context.fillRect(0, 0, 512, 288);%0A  %0A  /*if(timersetflash == false)%7B //flash timer%0A    setTimeout(function()%7B%0A      light = false;%0A      timersetflash = false;%0A    %7D, 200);%0A    timersetflash = true;%0A  %7D*/%0A  %0A  if(light == true )%7B %0A    this.context.fillStyle = %22#FFFFFF%22;%0A    this.context.fillRect(0, 0, 512, 288);%0A    %0A    if(fading == false)%7B%0A      fading = true;%0A      //fadeOutRectange(0, 0, 512, 288, 31, 61, 92);%0A      var r = 31, g = 61, b = 92;%0A      
 var self = d
@@ -948,24 +948,26 @@
 (%222d%22);%0A    
+  
 var steps = 
@@ -970,24 +970,26 @@
 s = 50;%0A    
+  
 var dr = (25
@@ -1046,24 +1046,26 @@
 ch time%0A    
+  
 var dg = (25
@@ -1089,16 +1089,18 @@
 / green%0A
+  
     var 
@@ -1131,24 +1131,26 @@
 // blue%0A    
+  
 var count = 
@@ -1168,16 +1168,18 @@
 counter%0A
+  
     var 
@@ -1214,32 +1214,34 @@
 ion() %7B%0A        
+  
 self.fillStyle =
@@ -1354,32 +1354,34 @@
  + ')';%0A        
+  
 self.fillRect(x,
@@ -1378,26 +1378,30 @@
 illRect(
-x, y, w, h
+0, 0, 512, 288
 ); // wi
@@ -1425,24 +1425,26 @@
 a each time%0A
+  
         coun
@@ -1456,16 +1456,18 @@
         
+  
 if(count
@@ -1508,16 +1508,18 @@
         
+  
 clearInt
@@ -1551,579 +1551,49 @@
     
-fading = false;%0A        %7D%0A    %7D, 30);%0A  %7D;%0A%0A%0AGame.draw = function() %7B%0A%0A  this.context.clearRect(0, 0, 512, 288);%0A  this.context.fillStyle = %22#1F3D5C%22;%0A  this.context.fillRect(0, 0, 512, 288);%0A  %0A  /*if(timersetflash == false)%7B //flash timer%0A    setTimeout(function()%7B%0A      light = false;%0A      timersetflash = false;%0A    %7D, 200);%0A    timersetflash = true;%0A  %7D*/%0A  %0A  if(light == true )%7B %0A    this.context.fillStyle = %22#FFFFFF%22;%0A    this.context.fillRect(0, 0, 512, 288);%0A    %0A    if(fading == false)%7B%0A      fading = true;%0A      fadeOutRectange(0, 0, 512, 288, 31, 61, 92
+  fading = false;%0A          %7D%0A      %7D, 30
 );%0A 

Update game.js