Advertisement
Dvoyles

Timer

Jul 29th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    /**
  2.      * Converts seconds to "MM:SS"
  3.      * @param {float} seconds
  4.      *      Takes seconds
  5.      */
  6.     var secondsToTimeString = function (seconds) {
  7.  
  8.         var s         = Math.floor(seconds % 60);
  9.         var m         = Math.floor((seconds * 1000 / (1000 * 60)) % 60);
  10.         var strFormat = "MM:SS";
  11.  
  12.         if (s < 10) s = "0" + s;
  13.         if (m < 10) m = "0" + m;
  14.  
  15.         strFormat = strFormat.replace(/MM/, m);
  16.         strFormat = strFormat.replace(/SS/, s);
  17.  
  18.         return strFormat;
  19.     };
  20.  
  21.  
  22.     /**
  23.      * Place in update() to get total time since user has started game.
  24.      */
  25.     var elapsedTime = function () {
  26.         var end       = new Date();
  27.         var elapsedMS = end.getTime() - start.getTime();
  28.         var seconds   = Math.round(elapsedMS / 1000);
  29.         var minutes   = Math.round(seconds   /   60);
  30.  
  31.         nCurrentTime = seconds;
  32.     };
  33.  
  34.  
  35.     /**
  36.      * All events occuring in Hall One are triggered from this
  37.      */
  38.     var eventsHallOne = function () {
  39.  
  40.     nCurrentTime = elapsedTime(); // Returns seconds
  41.         switch (nCurrentTime) {
  42.             case 0:
  43.                 triggerTrap(camHallOne.c21, camHallOne.c, aStills.HallOne);
  44.                 break;
  45.             case 7:
  46.                 console.log("Time is: " + nCurrentTime)
  47.                 break;
  48.         }
  49.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement