A ECRIRE
#include <MLV/MLV_all.h> // // Attention ! // Pour pouvoir compiler ce programme sous windows et sous macintosh, // il faut, pour la déclaration du main, respecter strictement la syntaxe // suivante : // int main( int argc, char *argv[] ){ int width = 640, height = 480; MLV_init_audio(); MLV_create_window( "advanced - 9 animation", "animation", width, height ); MLV_Image* creature = MLV_load_image("creature.png"); MLV_Animation_sequence* animation_sequence; int w = 79, h = 79; MLV_Image* images[4]; images[0] = MLV_copy_partial_image( creature, 0, 0, w, h ); images[1] = MLV_copy_partial_image( creature, 1*(w+1), 0, w, h ); images[2] = MLV_copy_partial_image( creature, 2*(w+1), 0, w, h ); images[3] = MLV_copy_partial_image( creature, 3*(w+1), 0, w, h ); MLV_Sound* sound = MLV_load_sound( "walk.ogg" ); int nb_frames = 6; int nb_layers = 1; animation_sequence = MLV_create_animation_sequence( nb_frames, nb_layers, 1 ); int layer = 0; MLV_add_frame_in_animation_sequence( images+0, &sound, 4, animation_sequence ); MLV_add_frame_in_animation_sequence( images+1, NULL, 4, animation_sequence ); MLV_add_frame_in_animation_sequence( images+2, &sound, 4, animation_sequence ); MLV_add_frame_in_animation_sequence( images+3, NULL, 4, animation_sequence ); MLV_Animation* animation = MLV_create_animation( animation_sequence ); MLV_play_animation( animation ); MLV_turn_on_sound_on_animation( animation, 0 ); MLV_change_sound_volume_on_animation( animation, 0, 0.2 ); MLV_change_frame_rate( 24 ); int avance = 0; int pas = 4; int touche; while( MLV_get_event ( &touche, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) == MLV_NONE || touche != MLV_KEYBOARD_ESCAPE ){ MLV_update_animation( animation ); MLV_draw_filled_rectangle( 0,0, width, height, MLV_COLOR_BROWN ); MLV_draw_filled_rectangle( width/2,0, width/2, height, MLV_COLOR_YELLOW ); avance += pas; if( avance > width-w ){ MLV_play_revert_animation( animation ); pas = -pas; } if( avance < 0 ){ MLV_play_animation( animation ); pas = -pas; } int position_y = 20; MLV_draw_animation( animation, layer, avance, position_y ); MLV_actualise_window(); MLV_delay_according_to_frame_rate(); } MLV_free_animation( animation ); MLV_free_animation_sequence( animation_sequence ); MLV_free_image( images[0] ); MLV_free_image( images[1] ); MLV_free_image( images[2] ); MLV_free_image( images[3] ); MLV_free_image( creature ); MLV_free_window(); MLV_free_audio(); return 0; }