class Room {
	constructor(roomX, roomY, tile, id) {
		this.id = id;
		this.objects = [];
		this.room = [];
		this.x = roomX;
		this.y = roomY;
		for (var y = 0; y < this.y; y++) {
			this.room.push([]);
			var myRow = new Uint16Array(this.x);
			this.room[y].push(myRow);
			for (var x = 0; x < this.x; x++) {
				this.room[y][x] = tile;
			}
		}
	}

	setColliders() {
		console.log("this totally works");
	}

	changePoint(val, x1, y1, w, h) {
		if (val%1 != 0) {
			console.log("Not Proper Format");
		} else {
			if (w && h) {
				for (var y = y1; y < h + y1; y++) {
					for (var x = x1; x < w + x1; x++) {
						this.room[y][x] = val;
					}
				}
			} else {
				this.room[y1][x1] = val;
			}
		}
	}

	generateBorder(type, layer) {
		if (!layer) {
			layer = 0;
		}
		this.changePoint(type, 0 + layer, 0 + layer, 1, this.y - layer * 2);
		this.changePoint(type, 0 + layer, 0 + layer, this.x - layer * 2, 1);
		this.changePoint(type, this.x - 1 - layer, 0 + layer, 1, this.y - layer * 2);
		this.changePoint(type, 0 + layer, this.y - 1 - layer, this.x - layer * 2, 1);
	}

	frame(source) {

		for (var i = 0; i < this.objects.length; i++ ) {

			var instanceId = this.objects[i][0];
			var instanceX = this.objects[i][1];
			var instanceX = this.objects[i][2];
			behaviors[instanceId](i);


		}

	}

	getPoint(x, y) {
		return (this.room[x][y]);
	}
}

var R = {
	changeRooms : function(roomClassId) {
		console.log(roomClassId.id);
		myWorld = roomClassId;
	},

	drawRoom : function(roomClassId, canvasCxt, tiles) {
		for (var y = 0; y < roomClassId.y; y++) {
			for (var x = 0; x < roomClassId.x; x++) {
				var rPoint = tileNames[roomClassId.room[y][x]];
				Sys.drawImage(canvasCxt, rPoint, x * 32, y * 32, 1, 1, 1)
			}
		}
		for (var i = 0; i < roomClassId.objects.length; i++) {

			Sys.drawImage(canvasCxt, roomClassId.objects[i][3], roomClassId.objects[i][1], roomClassId.objects[i][2], 1, 1, 1)
		}

	}
}