Semiclassical wave functions in billiards built on classical trajectories. Energy quantization, scars and periodic orbits