2012-02-28 13:09:12 +01:00
/*! \file intro.c
* \ brief Intro view with plot description .
*/
2012-03-04 13:32:42 +01:00
/*
* Copyright ( c ) Sebastian Krzyszkowiak < dos @ dosowisko . net >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
2012-02-18 04:14:35 +01:00
# include <math.h>
2012-02-19 20:18:28 +01:00
# include <stdio.h>
2012-02-17 20:32:58 +01:00
# include "intro.h"
2012-02-22 10:19:02 +01:00
# include "map.h"
2012-02-17 20:32:58 +01:00
2012-04-04 00:06:47 +02:00
void AnimPage ( struct Game * game , int page ) {
al_set_target_bitmap ( game - > intro . animation ) ;
al_clear_to_color ( al_map_rgba ( 0 , 0 , 0 , 0 ) ) ;
if ( page < 6 ) al_draw_bitmap_region ( game - > intro . animsprites [ page - 1 ] , al_get_display_width ( game - > display ) * 0.3125 * ( int ) fmod ( game - > intro . anim , 3 ) , al_get_display_height ( game - > display ) * 0.63 * ( ( ( int ) ( game - > intro . anim / 3 ) ) % 3 ) , al_get_display_width ( game - > display ) * 0.3125 , al_get_display_height ( game - > display ) * 0.63 , al_get_display_width ( game - > display ) * 0.08 , al_get_display_height ( game - > display ) * 0.18 , 0 ) ;
if ( page < 5 ) al_draw_bitmap_region ( game - > intro . animsprites [ page ] , al_get_display_width ( game - > display ) * 0.3125 * ( int ) fmod ( game - > intro . anim , 3 ) , al_get_display_height ( game - > display ) * 0.63 * ( ( ( int ) ( game - > intro . anim / 3 ) ) % 3 ) , al_get_display_width ( game - > display ) * 0.3125 , al_get_display_height ( game - > display ) * 0.63 , al_get_display_width ( game - > display ) * 1.08 , al_get_display_height ( game - > display ) * 0.18 , 0 ) ;
al_set_target_bitmap ( al_get_backbuffer ( game - > display ) ) ;
game - > intro . anim + = tps ( game , 2 ) ;
}
2012-03-01 13:15:20 +01:00
void FillPage ( struct Game * game , int page ) {
2012-03-04 22:02:23 +01:00
char filename [ 30 ] = { } ;
sprintf ( filename , " data/intro/%d.flac " , page ) ;
//if (game->intro.audiostream) al_destroy_audio_stream(game->intro.audiostream);
game - > intro . audiostream = al_load_audio_stream ( filename , 4 , 1024 ) ;
2012-03-13 12:42:28 +01:00
al_attach_audio_stream_to_mixer ( game - > intro . audiostream , game - > audio . voice ) ;
2012-03-04 22:02:23 +01:00
al_set_audio_stream_playing ( game - > intro . audiostream , false ) ;
al_set_audio_stream_gain ( game - > intro . audiostream , 1.75 ) ;
2012-03-01 13:15:20 +01:00
al_set_target_bitmap ( game - > intro . table ) ;
float y = 0.2 ;
float oldx = - 1 ;
void draw_text ( int page , char * text ) {
float x = 0.45 ;
if ( page ! = oldx ) { y = 0.2 ; oldx = page ; }
al_draw_text_with_shadow ( game - > intro . font , al_map_rgb ( 255 , 255 , 255 ) , al_get_display_width ( game - > display ) * x , al_get_display_height ( game - > display ) * y , ALLEGRO_ALIGN_LEFT , text ) ;
y + = 0.07 ;
}
void DrawPage ( int p ) {
switch ( p ) {
case 1 :
al_draw_bitmap ( game - > intro . table_bitmap , 0 , 0 , 0 ) ;
draw_text ( 1 , " Since Twilight Sparkle and her five best " ) ;
draw_text ( 1 , " friends defeated Discord and imprisoned " ) ;
draw_text ( 1 , " him in a stone using the Elements of " ) ;
draw_text ( 1 , " Harmony, Equestia has been a peaceful " ) ;
draw_text ( 1 , " place for a quite long time. " ) ;
break ;
case 2 :
al_draw_bitmap_region ( game - > intro . table_bitmap , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , 0 , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , al_get_bitmap_height ( game - > intro . table_bitmap ) , al_get_display_width ( game - > display ) * 0 , 0 , 0 ) ;
al_draw_bitmap_region ( game - > intro . table_bitmap , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , 0 , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , al_get_bitmap_height ( game - > intro . table_bitmap ) , al_get_display_width ( game - > display ) * 0.5 , 0 , 0 ) ;
draw_text ( 2 , " Suddenly, one day some reckless pony " ) ;
draw_text ( 2 , " accidentally introduced a tiny little " ) ;
draw_text ( 2 , " bit of chaos near Discords figure. " ) ;
break ;
case 3 :
al_draw_bitmap_region ( game - > intro . table_bitmap , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , 0 , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , al_get_bitmap_height ( game - > intro . table_bitmap ) , al_get_display_width ( game - > display ) * 0 , 0 , 0 ) ;
al_draw_bitmap_region ( game - > intro . table_bitmap , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , 0 , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , al_get_bitmap_height ( game - > intro . table_bitmap ) , al_get_display_width ( game - > display ) * 0.5 , 0 , 0 ) ;
draw_text ( 3 , " A tiny little bit of chaos turned not to " ) ;
draw_text ( 3 , " be enough for Discord to escape from rock, " ) ;
draw_text ( 3 , " but enough to turn nearly dropped muffins " ) ;
draw_text ( 3 , " into muffinzombies, with aim to destroy all " ) ;
draw_text ( 3 , " the harmony in Equestria. " ) ;
break ;
case 4 :
al_draw_bitmap_region ( game - > intro . table_bitmap , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , 0 , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , al_get_bitmap_height ( game - > intro . table_bitmap ) , al_get_display_width ( game - > display ) * 0 , 0 , 0 ) ;
al_draw_bitmap_region ( game - > intro . table_bitmap , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , 0 , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , al_get_bitmap_height ( game - > intro . table_bitmap ) , al_get_display_width ( game - > display ) * 0.5 , 0 , 0 ) ;
draw_text ( 4 , " Discord, who has learned his lession after " ) ;
draw_text ( 4 , " last failure, turned his muffinzombie-gang " ) ;
draw_text ( 4 , " against the same mares who previously " ) ;
draw_text ( 4 , " defeated him, prisoning them in their own " ) ;
draw_text ( 4 , " houses. Thanks to that, he's now able to " ) ;
draw_text ( 4 , " wait until the world is again chaotic enough " ) ;
draw_text ( 4 , " for him to escape and rule Equestria " ) ;
draw_text ( 4 , " once again. " ) ;
break ;
case 5 :
al_draw_bitmap_region ( game - > intro . table_bitmap , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , 0 , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , al_get_bitmap_height ( game - > intro . table_bitmap ) , al_get_display_width ( game - > display ) * 0 , 0 , 0 ) ;
al_draw_bitmap_region ( game - > intro . table_bitmap , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , 0 , al_get_bitmap_width ( game - > intro . table_bitmap ) / 2 , al_get_bitmap_height ( game - > intro . table_bitmap ) , al_get_display_width ( game - > display ) * 0.5 , 0 , 0 ) ;
draw_text ( 5 , " Who is able to defeat Discord when the " ) ;
draw_text ( 5 , " Elements of Harmony are unavailable? " ) ;
draw_text ( 5 , " " ) ;
draw_text ( 5 , " Well... There is somepony who knows " ) ;
draw_text ( 5 , " everything about muffins... " ) ;
break ;
}
}
DrawPage ( page ) ;
ALLEGRO_BITMAP * second = al_create_bitmap ( al_get_display_width ( game - > display ) , al_get_display_height ( game - > display ) ) ;
al_set_target_bitmap ( second ) ;
DrawPage ( page + 1 ) ;
al_set_target_bitmap ( game - > intro . table ) ;
al_draw_bitmap ( second , al_get_display_width ( game - > display ) , 0 , 0 ) ;
al_set_target_bitmap ( al_get_backbuffer ( game - > display ) ) ;
2012-03-01 22:07:48 +01:00
al_destroy_bitmap ( second ) ;
2012-03-01 13:15:20 +01:00
}
2012-02-17 20:32:58 +01:00
void Intro_Draw ( struct Game * game ) {
al_clear_to_color ( al_map_rgb ( 0 , 0 , 0 ) ) ;
2012-04-04 00:06:47 +02:00
if ( game - > intro . in_animation ) {
AnimPage ( game , game - > intro . page ) ;
2012-03-01 13:15:20 +01:00
al_draw_bitmap ( game - > intro . table , - 1 * al_get_display_width ( game - > display ) + ( cos ( ( ( - 1 * ( ( game - > intro . position ) % al_get_display_width ( game - > display ) ) ) / ( float ) al_get_display_width ( game - > display ) ) * ( ALLEGRO_PI ) ) / 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-04-04 00:06:47 +02:00
al_draw_bitmap ( game - > intro . animation , - 1 * al_get_display_width ( game - > display ) + ( cos ( ( ( - 1 * ( ( game - > intro . position ) % al_get_display_width ( game - > display ) ) ) / ( float ) al_get_display_width ( game - > display ) ) * ( ALLEGRO_PI ) ) / 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);
}
else {
AnimPage ( game , game - > intro . page + 1 ) ;
2012-03-01 13:15:20 +01:00
al_draw_bitmap ( game - > intro . table , 0 , 0 , 0 ) ; //al_get_display_height(game->display)*((game->intro.position/3.0)/(float)al_get_display_width(game->display)), 0);
2012-04-04 00:06:47 +02:00
al_draw_bitmap ( game - > intro . animation , 0 , 0 , 0 ) ; //al_get_display_height(game->display)*((game->intro.position/3.0)/(float)al_get_display_width(game->display)), 0);
}
2012-02-24 23:58:18 +01:00
al_draw_text_with_shadow ( 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-03-03 00:02:34 +01:00
int old = game - > intro . position % al_get_display_width ( game - > display ) ;
2012-03-01 10:49:20 +01:00
game - > intro . position - = tps ( game , 600 ) ;
2012-03-03 00:02:34 +01:00
//PrintConsole(game, "%d", game->intro.position%al_get_display_width(game->display));
if ( game - > intro . position % al_get_display_width ( game - > display ) > old ) {
2012-03-01 13:15:20 +01:00
//DrawConsole(game);
//al_flip_display();
2012-02-18 04:14:35 +01:00
game - > intro . in_animation = false ;
2012-03-01 13:15:20 +01:00
FillPage ( game , game - > intro . page + 1 ) ;
2012-02-18 04:14:35 +01:00
PrintConsole ( game , " Animation finished. " ) ;
2012-03-04 22:02:23 +01:00
al_set_audio_stream_playing ( game - > intro . audiostream , true ) ;
2012-02-18 04:14:35 +01:00
}
2012-02-22 10:22:48 +01:00
else if ( game - > intro . position < = - 4 * al_get_display_width ( game - > display ) ) {
2012-02-18 04:14:35 +01:00
PrintConsole ( game , " This was the last page. " ) ;
UnloadGameState ( game ) ;
2012-02-18 05:53:39 +01:00
game - > loadstate = GAMESTATE_MAP ;
2012-02-22 11:53:26 +01:00
PrintConsole ( game , " Chainloading GAMESTATE_MAP... " ) ;
LoadGameState ( game ) ;
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 ) {
2012-03-05 21:07:42 +01:00
al_play_sample_instance ( game - > intro . music ) ;
2012-02-18 04:41:45 +01:00
ALLEGRO_EVENT ev ;
2012-02-29 12:16:11 +01:00
int fadeloop ;
2012-03-01 10:49:20 +01:00
for ( fadeloop = 0 ; fadeloop < 256 ; fadeloop + = tps ( game , 600 ) ) {
2012-02-18 04:41:45 +01:00
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-04-04 00:06:47 +02:00
al_draw_tinted_bitmap ( game - > intro . animation , 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-03-04 22:02:23 +01:00
al_set_audio_stream_playing ( game - > intro . audiostream , true ) ;
2012-02-19 22:20:05 +01:00
Intro_Draw ( game ) ;
2012-02-18 04:41:45 +01:00
}
2012-02-25 22:26:31 +01:00
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 ) ;
2012-02-18 05:53:39 +01:00
game - > loadstate = GAMESTATE_MAP ;
2012-02-22 10:19:02 +01:00
PrintConsole ( game , " Chainloading GAMESTATE_MAP... " ) ;
LoadGameState ( game ) ;
2012-02-18 04:14:35 +01:00
return 0 ;
}
if ( ! game - > intro . in_animation ) {
2012-03-04 22:02:23 +01:00
if ( game - > intro . audiostream ) {
2012-04-05 12:56:58 +02:00
al_set_audio_stream_playing ( game - > intro . audiostream , false ) ;
2012-03-04 22:02:23 +01:00
al_destroy_audio_stream ( game - > intro . audiostream ) ;
game - > intro . audiostream = NULL ;
}
2012-02-19 22:54:33 +01:00
PrintConsole ( game , " Animate page (was on %d)... " , + + game - > intro . page ) ;
2012-02-18 04:14:35 +01:00
game - > intro . in_animation = true ;
}
return 0 ;
}
2012-02-25 22:26:31 +01:00
2012-02-18 04:14:35 +01:00
void Intro_Preload ( struct Game * game ) {
2012-03-04 22:02:23 +01:00
game - > intro . audiostream = NULL ;
2012-02-18 04:14:35 +01:00
game - > intro . position = 0 ;
game - > intro . page = 0 ;
game - > intro . in_animation = false ;
2012-04-04 00:06:47 +02:00
game - > intro . anim = 0 ;
game - > intro . animsprites [ 0 ] = LoadScaledBitmap ( " discord.png " , al_get_display_width ( game - > display ) * 0.3125 * 3 , al_get_display_height ( game - > display ) * 0.63 * 3 ) ;
game - > intro . animsprites [ 1 ] = LoadScaledBitmap ( " derpcycle.png " , al_get_display_width ( game - > display ) * 0.3125 * 3 , al_get_display_height ( game - > display ) * 0.63 * 3 ) ;
game - > intro . animsprites [ 2 ] = LoadScaledBitmap ( " zombie.png " , al_get_display_width ( game - > display ) * 0.3125 * 3 , al_get_display_height ( game - > display ) * 0.63 * 3 ) ;
game - > intro . animsprites [ 3 ] = LoadScaledBitmap ( " loading.png " , al_get_display_width ( game - > display ) * 0.3125 * 3 , al_get_display_height ( game - > display ) * 0.63 * 3 ) ;
game - > intro . animsprites [ 4 ] = LoadScaledBitmap ( " letter.png " , al_get_display_width ( game - > display ) * 0.3125 * 3 , al_get_display_height ( game - > display ) * 0.63 * 3 ) ;
2012-03-01 01:14:24 +01:00
2012-03-04 15:57:23 +01:00
game - > intro . table_bitmap = LoadScaledBitmap ( " paper.png " , al_get_display_width ( game - > display ) , al_get_display_height ( game - > display ) ) ;
2012-03-01 01:14:24 +01:00
2012-02-19 20:18:28 +01:00
game - > intro . sample = al_load_sample ( " data/intro.flac " ) ;
2012-03-05 21:07:42 +01:00
game - > intro . music = al_create_sample_instance ( game - > intro . sample ) ;
al_attach_sample_instance_to_mixer ( game - > intro . music , game - > audio . music ) ;
al_set_sample_instance_playmode ( game - > intro . music , ALLEGRO_PLAYMODE_LOOP ) ;
2012-02-19 20:18:28 +01:00
if ( ! game - > intro . sample ) {
fprintf ( stderr , " Audio clip sample not loaded! \n " ) ;
exit ( - 1 ) ;
}
2012-03-01 13:15:20 +01:00
game - > intro . table = al_create_bitmap ( al_get_display_width ( game - > display ) * 2 , al_get_display_height ( game - > display ) ) ;
2012-04-04 00:06:47 +02:00
game - > intro . animation = al_create_bitmap ( al_get_display_width ( game - > display ) * 2 , al_get_display_height ( game - > display ) ) ;
2012-02-23 12:23:19 +01:00
2012-03-01 13:15:20 +01:00
game - > intro . font = al_load_ttf_font ( " data/ShadowsIntoLight.ttf " , al_get_display_height ( game - > display ) * 0.04 , 0 ) ;
2012-02-18 11:16:30 +01:00
2012-03-01 13:15:20 +01:00
FillPage ( game , 1 ) ;
2012-04-04 00:06:47 +02:00
AnimPage ( game , 1 ) ;
2012-02-18 04:14:35 +01:00
al_set_target_bitmap ( al_get_backbuffer ( game - > display ) ) ;
2012-02-22 10:19:02 +01:00
PrintConsole ( game , " Chainpreloading GAMESTATE_MAP... " ) ;
Map_Preload ( game ) ;
2012-02-18 04:14:35 +01:00
}
2012-02-25 22:26:31 +01:00
2012-02-18 04:14:35 +01:00
void Intro_Unload ( struct Game * game ) {
2012-04-05 12:56:58 +02:00
if ( game - > intro . audiostream ) {
al_set_audio_stream_playing ( game - > intro . audiostream , false ) ;
al_destroy_audio_stream ( game - > intro . audiostream ) ;
}
2012-02-18 04:41:45 +01:00
ALLEGRO_EVENT ev ;
2012-02-29 12:16:11 +01:00
int fadeloop ;
2012-03-01 10:49:20 +01:00
for ( fadeloop = 255 ; fadeloop > = 0 ; fadeloop - = tps ( game , 600 ) ) {
2012-02-18 04:41:45 +01:00
al_wait_for_event ( game - > event_queue , & ev ) ;
2012-04-04 00:06:47 +02:00
if ( game - > intro . in_animation ) {
2012-03-01 13:15:20 +01:00
al_draw_tinted_bitmap ( game - > intro . table , al_map_rgba_f ( fadeloop / 255.0 , fadeloop / 255.0 , fadeloop / 255.0 , 1 ) , - 1 * 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-04-04 00:06:47 +02:00
al_draw_tinted_bitmap ( game - > intro . animation , al_map_rgba_f ( fadeloop / 255.0 , fadeloop / 255.0 , fadeloop / 255.0 , 1 ) , - 1 * 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);
}
else {
2012-03-01 13:15:20 +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 ) ; //al_get_display_height(game->display)*((game->intro.position/3.0)/(float)al_get_display_width(game->display)), 0);
2012-04-04 00:06:47 +02:00
al_draw_tinted_bitmap ( game - > intro . animation , al_map_rgba_f ( fadeloop / 255.0 , fadeloop / 255.0 , fadeloop / 255.0 , 1 ) , 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
DrawConsole ( game ) ;
al_flip_display ( ) ;
}
2012-02-18 04:14:35 +01:00
al_destroy_bitmap ( game - > intro . table ) ;
2012-04-04 00:06:47 +02:00
al_destroy_bitmap ( game - > intro . animation ) ;
int i ;
for ( i = 0 ; i < 5 ; i + + ) {
al_destroy_bitmap ( game - > intro . animsprites [ i ] ) ;
}
2012-02-18 05:53:39 +01:00
al_destroy_font ( game - > intro . font ) ;
2012-03-05 21:07:42 +01:00
al_destroy_sample_instance ( game - > intro . music ) ;
2012-02-19 20:18:28 +01:00
al_destroy_sample ( game - > intro . sample ) ;
2012-03-01 13:15:20 +01:00
al_destroy_bitmap ( game - > intro . table_bitmap ) ;
2012-02-18 04:14:35 +01:00
}