2012-02-17 20:32:58 +01:00
# include <allegro5/allegro.h>
# include <allegro5/allegro_font.h>
2012-02-18 04:14:35 +01:00
# include <math.h>
2012-02-17 20:32:58 +01:00
# include "intro.h"
void Intro_Draw ( struct Game * game ) {
al_clear_to_color ( al_map_rgb ( 0 , 0 , 0 ) ) ;
2012-02-18 04:14:35 +01:00
//printf("%f\n", ((-1*((game->intro.position)%al_get_display_width(game->display)))/(float)al_get_display_width(game->display)));
if ( game - > intro . in_animation )
2012-02-18 05:10:42 +01:00
al_draw_bitmap ( game - > intro . table , - 1 * ( game - > intro . page ) * al_get_display_width ( game - > display ) + ( cos ( ( ( - 1 * ( ( game - > intro . position ) % al_get_display_width ( game - > display ) ) ) / ( float ) al_get_display_width ( game - > display ) ) * ( 3.1415 ) ) / 2.0 ) * al_get_display_width ( game - > display ) + al_get_display_width ( game - > display ) / 2.0 , 0 , 0 ) ; //al_get_display_height(game->display)*((game->intro.position/3.0)/(float)al_get_display_width(game->display)), 0);
2012-02-18 04:14:35 +01:00
else
2012-02-18 05:10:42 +01:00
al_draw_bitmap ( game - > intro . table , - 1 * ( game - > intro . page ) * al_get_display_width ( game - > display ) , 0 , 0 ) ; //al_get_display_height(game->display)*((game->intro.position/3.0)/(float)al_get_display_width(game->display)), 0);
2012-02-17 20:32:58 +01:00
al_draw_text ( game - > font , al_map_rgb ( 255 , 255 , 255 ) , al_get_display_width ( game - > display ) / 2 , al_get_display_height ( game - > display ) / 2 , ALLEGRO_ALIGN_CENTRE , " Not implemented yet! " ) ;
2012-02-18 05:53:39 +01:00
al_draw_text ( game - > intro . font , al_map_rgb ( 255 , 255 , 255 ) , al_get_display_width ( game - > display ) / 2 , al_get_display_height ( game - > display ) * 0.90 , ALLEGRO_ALIGN_CENTRE , " Press any key to continue or escape to skip... " ) ;
2012-02-18 04:14:35 +01:00
//PrintConsole(game, "drawing");
if ( game - > intro . in_animation ) {
//PrintConsole(game, "animating");
2012-02-18 05:10:42 +01:00
game - > intro . position - = 10 ;
2012-02-18 04:14:35 +01:00
if ( game - > intro . position % al_get_display_width ( game - > display ) = = 0 ) {
game - > intro . in_animation = false ;
PrintConsole ( game , " Animation finished. " ) ;
}
else if ( game - > intro . position < = - 3 * al_get_display_width ( game - > display ) ) {
PrintConsole ( game , " This was the last page. " ) ;
UnloadGameState ( game ) ;
game - > gamestate = GAMESTATE_LOADING ;
2012-02-18 05:53:39 +01:00
game - > loadstate = GAMESTATE_MAP ;
2012-02-18 04:14:35 +01:00
}
}
2012-02-17 20:32:58 +01:00
}
2012-02-18 04:41:45 +01:00
void Intro_Load ( struct Game * game ) {
ALLEGRO_EVENT ev ;
for ( int fadeloop = 0 ; fadeloop < 256 ; fadeloop + = 10 ) {
al_wait_for_event ( game - > event_queue , & ev ) ;
2012-02-18 06:45:15 +01:00
al_draw_tinted_bitmap ( game - > intro . table , al_map_rgba_f ( fadeloop / 255.0 , fadeloop / 255.0 , fadeloop / 255.0 , 1 ) , 0 , 0 , 0 ) ;
2012-02-18 04:41:45 +01:00
DrawConsole ( game ) ;
al_flip_display ( ) ;
}
}
2012-02-18 04:14:35 +01:00
int Intro_Keydown ( struct Game * game , ALLEGRO_EVENT * ev ) {
if ( ev - > keyboard . keycode = = ALLEGRO_KEY_ESCAPE ) {
UnloadGameState ( game ) ;
game - > gamestate = GAMESTATE_LOADING ;
2012-02-18 05:53:39 +01:00
game - > loadstate = GAMESTATE_MAP ;
2012-02-18 04:14:35 +01:00
return 0 ;
}
if ( ! game - > intro . in_animation ) {
PrintConsole ( game , " Animate page... " ) ;
game - > intro . in_animation = true ;
game - > intro . page + + ;
}
return 0 ;
}
void Intro_Preload ( struct Game * game ) {
game - > intro . position = 0 ;
game - > intro . page = 0 ;
game - > intro . in_animation = false ;
2012-02-18 06:45:15 +01:00
game - > intro . table_bitmap = al_load_bitmap ( " discord.png " ) ;
2012-02-18 05:10:42 +01:00
game - > intro . table = al_create_bitmap ( al_get_display_width ( game - > display ) * 4 , al_get_display_height ( game - > display ) ) ;
2012-02-18 05:53:39 +01:00
game - > intro . font = al_load_ttf_font ( " ShadowsIntoLight.ttf " , al_get_display_height ( game - > display ) * 0.045 , 0 ) ;
2012-02-18 04:14:35 +01:00
al_set_target_bitmap ( game - > intro . table ) ;
al_draw_bitmap ( game - > intro . table_bitmap , 0 , 0 , 0 ) ;
2012-02-18 06:45:15 +01:00
//game->intro.table_bitmap = al_load_bitmap( "table.png" );
2012-02-18 04:14:35 +01:00
al_draw_bitmap ( game - > intro . table_bitmap , al_get_display_width ( game - > display ) , 0 , ALLEGRO_FLIP_HORIZONTAL ) ;
//game->intro.table_bitmap = al_load_bitmap( "menu.png" );
al_draw_bitmap ( game - > intro . table_bitmap , al_get_display_width ( game - > display ) * 2 , 0 , 0 ) ;
//game->intro.table_bitmap = al_load_bitmap( "table.png" );
al_draw_bitmap ( game - > intro . table_bitmap , al_get_display_width ( game - > display ) * 3 , 0 , ALLEGRO_FLIP_HORIZONTAL ) ;
al_set_target_bitmap ( al_get_backbuffer ( game - > display ) ) ;
}
void Intro_Unload ( struct Game * game ) {
2012-02-18 04:41:45 +01:00
ALLEGRO_EVENT ev ;
for ( int fadeloop = 255 ; fadeloop > = 0 ; fadeloop - = 10 ) {
al_wait_for_event ( game - > event_queue , & ev ) ;
if ( game - > intro . in_animation )
2012-02-18 05:10:42 +01:00
al_draw_tinted_bitmap ( game - > intro . table , al_map_rgba_f ( fadeloop / 255.0 , fadeloop / 255.0 , fadeloop / 255.0 , 1 ) , - 1 * ( game - > intro . page ) * al_get_display_width ( game - > display ) + ( cos ( ( ( - 1 * ( ( game - > intro . position ) % al_get_display_width ( game - > display ) ) ) / ( float ) al_get_display_width ( game - > display ) ) * ( 3.1415 ) ) / 2.0 ) * al_get_display_width ( game - > display ) + al_get_display_width ( game - > display ) / 2.0 , 0 , 0 ) ; //al_get_display_height(game->display)*((game->intro.position/3.0)/(float)al_get_display_width(game->display)), 0);
2012-02-18 04:41:45 +01:00
else
2012-02-18 05:10:42 +01:00
al_draw_tinted_bitmap ( game - > intro . table , al_map_rgba_f ( fadeloop / 255.0 , fadeloop / 255.0 , fadeloop / 255.0 , 1 ) , - 1 * ( game - > intro . page ) * al_get_display_width ( game - > display ) , 0 , 0 ) ; //al_get_display_height(game->display)*((game->intro.position/3.0)/(float)al_get_display_width(game->display)), 0);
2012-02-18 04:41:45 +01:00
//al_draw_tinted_bitmap(game->intro.table_bitmap,al_map_rgba_f(fadeloop/255.0,fadeloop/255.0,fadeloop/255.0,1),-1*(game->intro.page)*al_get_display_width(game->display), al_get_display_height(game->display)*((game->intro.position/3.0)/(float)al_get_display_width(game->display)),0);
DrawConsole ( game ) ;
al_flip_display ( ) ;
}
2012-02-18 04:14:35 +01:00
al_destroy_bitmap ( game - > intro . table_bitmap ) ;
al_destroy_bitmap ( game - > intro . table ) ;
2012-02-18 05:53:39 +01:00
al_destroy_font ( game - > intro . font ) ;
2012-02-18 04:14:35 +01:00
}