n.create = function() {
	var t = (Math.floor(rand(0,10)) == 0) ? (Math.floor(rand(0,2)) == 0 ? 1 : 2) : 0;
	var r = 5;
	if (Math.floor(rand(0, 2)) == 0) {
		var x = rand(-r, canvas.width+r);
		var y = Math.floor(rand(0, 2)) == 0 ? -r : canvas.height+r;
	}
	else {
		var x = Math.floor(rand(0, 2)) == 0 ? -r : canvas.width+r;
		var y = rand(-r, canvas.height+r);
	}
	var ang = Math.atan2(h.y - y, h.x - x);// + rand(-45, 45);
	
	this.x.push( x );
	this.y.push( y );
	this.dx.push( Math.cos(ang) * rand(2, 3 + Math.log(frames)) );
	this.dy.push( Math.sin(ang) * rand(2, 3 + Math.log(frames)) );
	this.r.push( r );
	this.c.push( t == 0 ? "#9a9a9a" : (t == 1 ? "#ff0000" : "#00ff00") );
	this.t.push( t );
};

n.remove = function(index) {
	this.x.splice( index, 1 );
	this.y.splice( index, 1 );
	this.dx.splice( index, 1 );
	this.dy.splice( index, 1 );
	this.r.splice( index, 1 );
	this.c.splice( index, 1 );
	this.t.splice( index, 1 );
};

n.collision = function() {
	var combo = 0;

	for (var i = 0; i < this.x.length; i++) {
		// wall collision
		if (canvas.inside(this.x[i], this.y[i], this.r[i], true)!==true) {
			this.remove(i);
		}
		
		// trail collision
		if (t.inside(this.x[i], this.y[i])) {
			if (this.t[i] == 0) {
				t.s += ++combo;
				n.k++;
			}
			else if ((this.t[i] == 1) && (h.r+h.ro < canvas.width/2) && (h.r+h.ro < canvas.height/2)) {
				h.r++;
			}
			else if ((this.t[i] == 2) && (t.lim <= 30)) {
				t.lim++;
			}
			
			// every 40th kill, t.lim is incremented. unless it is less than 8
			if ((n.k%40==0) && (t.lim > 6)) t.lim--;
			
			this.remove(i);
		}
	}
};

n.inside = function(x, y, r) {
	for (var i = 0; i < n.x.length; i++)
		if (dist(this.x[i], this.y[i], x, y) < this.r[i]+r) return i;
		
	return false;
};

n.move = function(index, x, y) {
	// if house is going to move, dx & dy needs to be updated at each interval

	this.x[index] = isset(x) ? x : this.x[index] + this.dx[index];
	this.y[index] = isset(y) ? y : this.y[index] + this.dy[index];
};

n.draw = function(index) {
	ctx.fillStyle = this.c[index];

	// add cool graidiant effect (not available on mobile)
	if (!mobile) {
		// add cool gradiant effect
		ctx.globalAlpha = 0.2;
		
		var r = 0.5;
		do {
			r += 0.5;
			circle(this.x[index], this.y[index], r);
		} while (r < this.r[index]);
		
		ctx.globalAlpha = 1;
	}
	else {
		ctx.fillRect(this.x[index], this.y[index], this.r[index], this.r[index]);
	}
};

n.update = function() {
	// collisions cannot be checked together with move & draw
	// because it could remove an ememy in the middle of the loop which would cause all sorts of problems
	n.collision(i);

	for (var i = 0; i < this.x.length; i++) {
		n.move(i);
		n.draw(i);
	}
};
