enum ENEMY {
	NAME,
	SPRITE,
	LIFE,
	DELAY,
	MONEY
};

global.enemy = [];
global.enemy_count = 0;
var _enemies = 0;
var _ignore_line = false;

var _file = file_text_open_read(PATH_DATA + "enemies.txt");

while(!file_text_eof(_file)) {
	var _line = file_text_readln(_file);
	_line = string_replace_all(_line, chr(10), "");
	_line = string_replace_all(_line, chr(13), "");
	_line = string_replace_all(_line, " ", "");
	
	show_debug_message(_line);
	
	var _first_ch = string_char_at(_line, 1);
	if (_first_ch == "#")
		continue;
	
	var _line_is_empty = (string_length(_line) == 0);
	
	if (_ignore_line) {
		if (_line_is_empty) {
			continue;
		}
		else {
			_enemies++;
			global.enemy[_enemies, ENEMY.NAME] = "ERROR";
			global.enemy[_enemies, ENEMY.SPRITE] = spr_en_error;
			global.enemy[_enemies, ENEMY.LIFE] = 0;
			global.enemy[_enemies, ENEMY.DELAY] = 0;
			global.enemy[_enemies, ENEMY.MONEY] = 0;
			_ignore_line = false;
		}
	}
	else if (_line_is_empty) {
		_ignore_line = true;
		continue;
	}
	
	var _en_var = "";
	var _en_val = "";
	var _type = 0;
	for(var i = 1; i <= string_length(_line)+1; i++) {
		var _c = string_char_at(_line, i);
		if (_c == "=") {
			_type++;
			continue;
		}
		else if (_type == 0) {
			_en_var += _c;
		}
		else if (_type == 1) {
			_en_val += _c;
		}
	}
	switch(_en_var) {
	case "name":
		global.enemy[_enemies, ENEMY.NAME] = _en_val;
		break;
	case "sprite":
		var _spr = asset_get_index(_en_val);
		if (_spr != -1)
			global.enemy[_enemies, ENEMY.SPRITE] = _spr;
		else
			global.enemy[_enemies, ENEMY.SPRITE] = spr_en_error;
		break;
	case "life":
		global.enemy[_enemies, ENEMY.LIFE] = real(_en_val);
		break;
	case "delay":
		global.enemy[_enemies, ENEMY.DELAY] = real(_en_val);
		break;
	case "money":
		global.enemy[_enemies, ENEMY.MONEY] = real(_en_val);
		break;
	}
}

file_text_close(_file);

show_debug_message("Enemy array: " + string(global.enemy));

global.enemy_count = _enemies;