Script main structure and animation loop