/// @description 

var _xx = global.camera_x;
var _yy = global.camera_y;

//var _pal_name = ["", "WARM", "LEMMING", "PSYCHO", "GB", "COOL", "ZX SPECTRUM"];
if (global.game_state == GAME_STATE.MENU) {
	draw_set_color(c_black);
	draw_set_alpha(0.5);
	draw_rectangle(_xx, _yy, _xx+WIN_WIDTH, _yy+WIN_HEIGHT, false);
	draw_set_color(c_white);
	
	draw_set_color(0x666666);
	
	draw_set_alpha(1);
	draw_set_halign(fa_center);
	draw_text(WIN_WIDTH/2, 10, GAME_NAME);
	
	draw_set_halign(fa_right);
	draw_set_font(font_small);
	draw_text(WIN_WIDTH-5, WIN_HEIGHT-10, "BY GEEPEE");
	draw_set_font(font_default);
	draw_set_halign(fa_left);
	
	draw_set_color(c_white);
	exit;
}
else if (global.game_state == GAME_STATE.GAME_OVER) {
	game_over++;
	
	draw_set_alpha(game_over/100);
	draw_set_color(c_black);
	draw_rectangle(0, 0, WIN_WIDTH, WIN_HEIGHT, false);
	draw_set_color(c_white);
	
	draw_set_halign(fa_center);
	draw_set_valign(fa_middle);
	draw_text(WIN_WIDTH/2, WIN_HEIGHT/2, "DEFEAT!");
	draw_set_halign(fa_left);
	draw_set_valign(fa_top);
	
	draw_set_alpha(1);
	if (game_over > 150) {
		game_over = 0;
		game_menu = MENU.SELECT_LEVEL;
		alarm[2] = 2;
		room_restart();
	}
	exit;
}
else if (global.game_state == GAME_STATE.VICTORY) {
	game_over++;
	
	//draw_set_alpha(game_over/100);
	
	if (!surface_exists(global.victory_surf)) {
		global.victory_surf = surface_create(WIN_WIDTH, WIN_HEIGHT);
		//surface_set_target(global.victory_surf);
		//draw_clear_alpha(c_black, 0);
		//surface_reset_target();
	}
	
	draw_surface(global.victory_surf, 0, 0);
	
	surface_set_target(global.victory_surf);
	{
		gpu_set_blendmode(bm_add);
		draw_set_color(c_black);
		draw_set_alpha(0.25);
		repeat(20)
			draw_circle(irandom(WIN_WIDTH), irandom(WIN_HEIGHT), 5+irandom(5), false);
			//draw_point(irandom(WIN_WIDTH), irandom(WIN_HEIGHT));
		gpu_set_blendmode(bm_normal);
	}
	surface_reset_target();
	//draw_rectangle(0, 0, WIN_WIDTH, WIN_HEIGHT, false);
	draw_set_alpha(1);
	draw_set_color(c_white);
	
	draw_set_halign(fa_center);
	draw_set_valign(fa_middle);
	draw_text(WIN_WIDTH/2, WIN_HEIGHT/2, "VICTORY!");
	draw_set_halign(fa_left);
	draw_set_valign(fa_top);
	
	draw_set_alpha(1);
	if (game_over > 250) {
		surface_free(global.victory_surf);
		game_over = 0;
		game_menu = MENU.SELECT_LEVEL;
		alarm[2] = 2;
		room_restart();
	}
	exit;
}
//draw_text(_xx, _yy, fps_real);
if (!instance_exists(obj_cursor))
	exit;

draw_set_color(c_black);
draw_set_alpha(0.5);
draw_rectangle(_xx, _yy, _xx+WIN_WIDTH, _yy+32, false);
draw_set_color(c_white);
draw_set_alpha(1);

var _cx = obj_cursor.x div BLOCK_WIDTH;
var _cy = obj_cursor.y div BLOCK_HEIGHT;

var _xs = _xx + WIN_WIDTH/2;
var _ys = _yy + 16;
//draw_text(_xx, _yy, string(_cx) + "/" + string(_cy));
var _imoney = round(global.money_draw);
draw_text(_xx, _yy, "$" + string(global.money));

draw_set_font(font_small);
with(obj_portal) {
	if (!victory) {
		draw_set_halign(fa_center);
		var _wave_count = global.level_data[# LEVEL_WAVE.COUNT, enemy];
		var _bar = enemy_count/_wave_count*48-1;
		draw_rectangle(_xx+8, _yy+22, _xx+8+_bar, _yy+24, false);
		draw_sprite(spr_wave_gui, 0, _xx+32, _yy+18);
		draw_text(_xx+32, _yy+14, "WAVE " + string(enemy+1));
		draw_set_halign(fa_left);
	}
}

/*
if (global.money != global.money_draw) {
	var _val = global.money - _imoney;
	draw_text(_xx, _yy+10, string(_val));
}
*/
draw_set_font(font_default);
	
//draw_set_font(font_small);
//draw_text(_xx, _yy+24, floor(fps_real));
//draw_set_font(font_default);
if (turret_shop) {
	var _cur = global.tur_array[shop_cur];
	draw_sprite(spr_turret_gui, 0, _xs, _ys);
		
	draw_sprite(global.turret[_cur, TURRET.SPRITE], 0, _xs, _ys);
	draw_set_font(font_small);
	draw_text(_xs, _yy+4, CH_DMG + string(global.turret[_cur, TURRET.DAMAGE]));
	draw_text(_xs+16, _yy+4, CH_TIME + string(global.turret[_cur, TURRET.COOLDOWN]));
	draw_text(_xs+32, _yy+4, CH_RANGE + string(global.turret[_cur, TURRET.RANGE]));
	draw_set_font(font_default);
	if (global.money < global.turret[_cur, TURRET.COST])
		draw_set_color(0x666666);
	draw_text(_xs+12, _yy+11, "$" + string(global.turret[_cur, TURRET.COST]));
	draw_set_color(c_white);
	if (shop_cur > 0)
		draw_sprite(spr_arrow, 0, _xs+48, _ys-4-alarm[3]);
	if (shop_cur < array_length_1d(global.tur_array)-1)
		draw_sprite(spr_arrow, 1, _xs+48, _ys+4+alarm[3]);
}
else if (obj_cursor.turret_cur != noone) {
	var _turret = obj_cursor.turret_cur;
	var _cur = _turret.num;
	
	if (obj_cursor.turret_destroy > 0) {
		draw_set_valign(fa_middle);
		draw_set_alpha(max(sin(current_time/100 mod 360), 0.2));
		var _text = "DESTROYING!";
		draw_text(_xs, _ys, _text);
		draw_rectangle(_xs, _ys+8,
			_xs+(1-obj_cursor.turret_destroy/50)*string_width(_text), _ys+8, false);
		draw_set_alpha(1);
		draw_set_valign(fa_top);
		exit;
	}
	var _up = global.turret[_cur, TURRET.UP];
	if (_up != -1) {
		draw_sprite(spr_turret_gui, 1, _xs, _ys);
		draw_sprite(global.turret[_up, TURRET.SPRITE], 0, _xs + 48, _ys);
		draw_text(_xs+12, _ys-5, "$" + string(global.turret[_up, TURRET.COST]));
	}
	else {
		draw_sprite(spr_turret_gui, 2, _xs, _ys);
		draw_set_font(font_small);
		draw_text(_xs+10, _ys-2, "FULLY UPGRADED");
	}
	draw_set_font(font_small);
	draw_text(_xs, _yy+4, CH_DMG + string(global.turret[_cur, TURRET.DAMAGE]));
	draw_text(_xs+16, _yy+4, CH_TIME + string(global.turret[_cur, TURRET.COOLDOWN]));
	draw_text(_xs+32, _yy+4, CH_RANGE + string(global.turret[_cur, TURRET.RANGE]));
	draw_set_font(font_default);
	draw_sprite(global.turret[_cur, TURRET.SPRITE], 0, _xs, _ys);
		
	draw_set_alpha(0.41);
	draw_circle(_turret.x-1, _turret.y-1, _turret.range, true);
	draw_set_alpha(1);
}
else if (obj_cursor.enemy_cur != noone) {
	var _en = obj_cursor.enemy_cur;
	if (instance_exists(_en)) {
		var _bar = _en.life/_en.life_max;
		draw_set_font(font_small);
		draw_text(_xs+8, _ys-14, _en.name);
		draw_sprite(spr_enemy_gui, 0, _xs, _ys);
		draw_sprite(_en.sprite_index, _en.image_index, _xs, _ys);
		
		draw_set_alpha(min(_bar*0.75, 0.5));
		draw_rectangle(_xs+10, _ys-4, _xs+10+(_bar*40), _ys+3, false);
		if (_en.alarm[1] != -1) {
			draw_set_alpha(_en.alarm[1]/15);
			draw_text(_xs+8, _ys+8, "SLOWNESS");
		}
		draw_set_alpha(1);
		draw_set_font(font_small);
		draw_set_halign(fa_center);
		draw_text(_xs+30, _ys-3, string(_en.life) + CH_PLUS + string(_en.life_max));
		draw_set_font(font_default);
		draw_set_halign(fa_left);
	}
}
//draw_text(_xx, _yy + 10, "PAL:" + _pal_name[pal_cur]);
/*
	draw_set_color(c_black);
	draw_rectangle(x-5, y-12, x+5, y-10, false);
	draw_set_color(c_white);
	draw_rectangle(x-5, y-11, x-5+(life/life_max*10), y-11, false);
*/