'use strict';

var config = require('../config');
var Backbone = require('backbone');
var User = require('./user');
var db = require('../db');

var World = module.exports = Backbone.Model.extend({
  initialize: function () {
    this.users = new User.Collection();
    var world = this;
    this.users.on('kill', function (kill) {
      db.registerKill(kill.killer);
      world.getScores(function (er, scores) {
        world.trigger('scores', scores);
      });
    });
  },
  getScores: function (cb) {
    db.getScores(this.users.recent.invoke('toUserData'), cb);
  },
  // control flow
  step: function () {
    var now = Date.now();
    var dt = (now - this.lastStep) / 1000;
    this.lastStep = now;
    this.users.removeDeadPlayers(dt);
    this.users.invoke('step', dt);
    this.users.checkCollisions();
    this.trigger('step', this.users.invoke('toFrame'));
  },
  start: function () {
    if (this.running) {
      console.error('game already running!');
    } else {
      this.lastStep = Date.now();
      this.running = setInterval(this.step.bind(this), 1000 / config.world.fps);
      console.log('game started!');
    }
  },
  stop: function () {
    if (!this.running) {
      console.error('game not currently running!');
    } else {
      console.log('game stopped!');
      clearInterval(this.running);
    }
  }
});

World.Collection = Backbone.Collection.extend({
  model: World
});

@@ -8,16 +8,47 @@
 rict';%0A%0A
+var _ = require('underscore');%0A
 var conf
@@ -70,24 +70,24 @@
 ./config');%0A
-
 var Backbone
@@ -221,16 +221,33 @@
 xtend(%7B%0A
+  timeScalar: 1,%0A
   initia
@@ -368,24 +368,50 @@
 on (kill) %7B%0A
+      world.bulletTime();%0A
       db.reg
@@ -719,16 +719,17 @@
 ar dt = 
+(
 (now - t
@@ -748,16 +748,35 @@
 ) / 1000
+) * this.timeScalar
 ;%0A    th
@@ -1413,22 +1413,220 @@
 nning);%0A
-
     %7D%0A
+  %7D,%0A  bulletTime: function () %7B%0A    clearTimeout(this.bulletTimeout);%0A    this.timeScalar = 0.05;%0A    var self = this;%0A    this.bulletTimeout = _.delay(function () %7B self.timeScalar = 1; %7D, 1000);%0A
   %7D%0A%7D);%0A

Add bullettime