text: "use strict"
  var Pack = require('../static/js/JPack.js');
  var C = require('../static/js/const.js');
  
  var Items = [];
  for (let key in Pack.items) {
  	Items.push(Pack.items[key]);
  }
  
  var Item = function (game, type) {
  	this.game = game;
  	if (type === undefined) {
  		type = Math.floor(Math.random() * Items.length);
  	}
  	this.id = Items[type].id;
  	this.count = Items[type].count || 0;
  	this.lifetime = 3000;
  	this.slowdown = 0;
  	this.vx = Math.random()+.5;
  	this.vy = Math.random()+.5;
  	this.dead = false;
  }
  Item.prototype.update = function () {
  	this.slowdown++;
  	if (this.x >= this.game.props.w - C.IS || this.x <= C.IS) {
  		this.vx *= -1
  	}
  
  	if (this.y >= this.game.props.h - C.IS || this.y <= C.IS) {
  		this.vy *= -1
  	}
  	this.lifetime--;
  	if (this.lifetime < 0) {
  		this.dead = true;
  	}
  	if (this.slowdown < 100) {
  		this.x += this.vx * this.slowdown/100;
  		this.y += this.vy * this.slowdown/100;
  	} else {
  		this.x += this.vx;
  		this.y += this.vy;
  	}
  }
  Item.prototype.touchUser = function (u) {
  	if (this.id == Pack.items.drug.id) {
  		this.dead = true;
  		u.killed('drug');
  	} else {
  		this.dead = true;
  		u.carry = this.id;
  		u.carryCount = this.count;
  	}
  }
  Item.prototype.getData = function () {
  	return Pack.itemPack.encode(this);
  }
  
  module.exports = Item;