/// @description 

if (global.game_state != GAME_STATE.GAME)
	exit;

if (!active)
	exit;

var _move_x = keyboard_check_pressed(kkey[KKEY.RIGHT]) - keyboard_check_pressed(kkey[KKEY.LEFT]);
var _move_y = keyboard_check_pressed(kkey[KKEY.DOWN]) - keyboard_check_pressed(kkey[KKEY.UP]);

if (_move_x != 0 || _move_y != 0) {
	x += _move_x * BLOCK_WIDTH;
	y += _move_y * BLOCK_HEIGHT;
	
	x = clamp(sc_snap_grid(x, BLOCK_WIDTH), 0, room_width-BLOCK_WIDTH);
	y = clamp(sc_snap_grid(y, BLOCK_HEIGHT), 0, room_height-BLOCK_HEIGHT);
	
	sc_block_update();
}
if (keyboard_check_pressed(kkey[KKEY.AA])) {
	sc_block_update();
	if (road_type == ROAD_TYPE.PLACE) {
		obj_game.turret_shop = true;
		active = false;
		sc_sound_play(SOUND.SELECT, 3);
	}
	else if (road_type == ROAD_TYPE.TURRET
			&& turret_cur != noone) {
		var _cur = turret_cur.num;
		var _up = global.turret[_cur, TURRET.UP];
		if (_up != -1) {
			var _cost = global.turret[_up, TURRET.COST];
			if (global.money >= _cost) {
				with(turret_cur) {
					sc_turret_set(_up);
					cost += _cost;
				}
				sc_money_add(-_cost);
				sc_sound_play(SOUND.UPGRADE, 5);
			}
		}
	}
}
else if (keyboard_check(kkey[KKEY.BB]) && road_type == ROAD_TYPE.TURRET) {
	turret_destroy++;
	turret_cur.visible = turret_destroy/2 mod 2;
	if (turret_destroy > 50) {
		sc_money_add(turret_cur.cost div 4);
		instance_create_layer(turret_cur.x, turret_cur.y, "Parts", obj_ef_explosion);
		instance_destroy(turret_cur);
		tilemap_set_at_pixel(global.road_tile, ROAD_TYPE.PLACE, x, y);
		sc_block_update();
		sc_sound_play(SOUND.EXPLOSION, 5);
	}
}
else if (keyboard_check_released(kkey[KKEY.BB])) {
	sc_block_update();
}
var _enemy = instance_position(x+BLOCK_WIDTH/2, y+BLOCK_HEIGHT/2, obj_entity);
if (_enemy != noone) {
	enemy_cur = _enemy;
}

x_draw = lerp(x_draw, x, 0.5);
y_draw = lerp(y_draw, y, 0.5);