/// @description 

if (keyboard_check_pressed(kkey[KKEY.SELECT])) {
	if (global.win_scale > global.win_scale_max-1)
		global.win_scale = 1;
	sc_refresh_window(global.win_scale + 1);
}

if (global.game_state == GAME_STATE.GAME_OVER
||  global.game_state == GAME_STATE.VICTORY)
	exit;
if (global.game_state == GAME_STATE.MENU) {
	if (menu_button_cur != noone) {
		var _cur = menu_button_cur;
		if (keyboard_check_pressed(kkey[KKEY.LEFT]))
			menu_button_cur = sc_find_button(_cur.x, _cur.y, menu_button_cur, 180);
		else if (keyboard_check_pressed(kkey[KKEY.RIGHT]))
			menu_button_cur = sc_find_button(_cur.x, _cur.y, menu_button_cur, 0);
		else if (keyboard_check_pressed(kkey[KKEY.UP]))
			menu_button_cur = sc_find_button(_cur.x, _cur.y, menu_button_cur, 90);
		else if (keyboard_check_pressed(kkey[KKEY.DOWN]))
			menu_button_cur = sc_find_button(_cur.x, _cur.y, menu_button_cur, 270);
		else if (keyboard_check_pressed(kkey[KKEY.AA])) {
			sc_sound_play(SOUND.SELECT2, 5);
			_cur.alarm[0] = 1;
		}
		else if (keyboard_check_pressed(kkey[KKEY.BB])) {
			sc_sound_play(SOUND.SELECT2, 5);
			_cur.alarm[1] = 1;
		}
		if (_cur != menu_button_cur)
			sc_sound_play(SOUND.SELECT, 5);
	}
	exit;
}

if (keyboard_check_pressed(vk_anykey)) {
	/*if (keyboard_check_pressed(kkey[KKEY.SELECT])) {
		if ((++pal_cur) > sprite_get_number(spr_palette)-1)
			pal_cur = 1;
		sc_palette_swap(pal_cur);
	}*/
	if (keyboard_check_pressed(kkey[KKEY.START])) {
		if (!instance_exists(obj_level))
			sc_menu_load(MENU.MAIN);
		else
			sc_menu_load(MENU.PAUSE);
		global.game_state = GAME_STATE.MENU;
	}
}
/*if (keyboard_check_pressed(kkey[KKEY.SELECT])) {
	alarm[0] = 10;
}
else if (keyboard_check_released(kkey[KKEY.SELECT]) && alarm[0] == -1) {
	alarm[0] = -1;
	global.pal_enable = !global.pal_enable;
}*/

if (turret_shop) {
	if (keyboard_check_pressed(kkey[KKEY.AA])) {
		var _cur = global.tur_array[shop_cur];
		if (global.money >= global.turret[_cur, TURRET.COST]) {
			with(obj_cursor) {
				with(instance_create_layer(x, y, "Turrets", obj_turret)) {
					x = sc_snap_grid(x, BLOCK_WIDTH) + BLOCK_WIDTH/2;
					y = sc_snap_grid(y, BLOCK_HEIGHT) + BLOCK_HEIGHT/2;
					cost = global.turret[_cur, TURRET.COST];
					sc_turret_set(_cur);
				}
				tilemap_set_at_pixel(global.road_tile, ROAD_TYPE.TURRET, x, y);
				sc_block_update();
			}
			sc_money_add(-global.turret[_cur, TURRET.COST]);
			obj_cursor.alarm[0] = 1;
			turret_shop = false;
			sc_sound_play(SOUND.PLACE, 5);
		}
	}
	else if (keyboard_check_pressed(kkey[KKEY.BB])) {
		obj_cursor.alarm[0] = 1;
		turret_shop = false;
		sc_sound_play(SOUND.CANCEL, 3);
	}
	else if (keyboard_check_pressed(kkey[KKEY.UP])) {
		shop_cur = max(--shop_cur, 0);
		sc_sound_play(SOUND.SELECT, 3);
		alarm[3] = 3; // anim
	}
	else if (keyboard_check_pressed(kkey[KKEY.DOWN])) {
		shop_cur = min(++shop_cur, array_length_1d(global.tur_array)-1);
		sc_sound_play(SOUND.SELECT, 3);
		alarm[3] = 3; // anim
	}
}

if (alarm[1] == -1)
	global.money_draw = lerp(global.money_draw, global.money, 0.5);