bring back Intro gamestate

This commit is contained in:
Sebastian Krzyszkowiak 2012-12-26 23:48:05 +01:00
parent 632be33eaa
commit 1e901cf51b
11 changed files with 159 additions and 151 deletions

View file

@ -12,7 +12,7 @@ ENDMACRO()
#GAMESTATE("menu")
GAMESTATE("disclaimer")
#GAMESTATE("intro")
GAMESTATE("intro")
#GAMESTATE("map")
##GAMESTATE("level")
GAMESTATE("about")

View file

@ -20,12 +20,13 @@
*/
#include <stdio.h>
#include <allegro5/allegro_ttf.h>
#include "../utils.h"
#include "about.h"
int Gamestate_ProgressCount = 0;
void Gamestate_Logic(struct Game *game, struct About_Resources* data) {
void Gamestate_Logic(struct Game *game, struct AboutResources* data) {
if (al_get_sample_instance_position(data->music)<700000) { return; }
if (data->fadeloop==0) {
PrintConsole(game, "Fade in");
@ -35,7 +36,7 @@ void Gamestate_Logic(struct Game *game, struct About_Resources* data) {
data->x+=0.00025;
}
void Gamestate_Draw(struct Game *game, struct About_Resources* data) {
void Gamestate_Draw(struct Game *game, struct AboutResources* data) {
/*PrintConsole(game, "%d", al_get_sample_instance_position(data->music));*/
if ((al_get_sample_instance_position(data->music)<700000) || (data->fadeloop==0)) {
al_clear_to_color(al_map_rgba(0,0,0,0));
@ -56,12 +57,12 @@ void Gamestate_Draw(struct Game *game, struct About_Resources* data) {
}
}
void Gamestate_Start(struct Game *game, struct About_Resources* data) {
void Gamestate_Start(struct Game *game, struct AboutResources* data) {
al_play_sample_instance(data->music);
data->fadeloop = 0;
}
void Gamestate_ProcessEvent(struct Game *game, struct About_Resources *data, ALLEGRO_EVENT *ev) {
void Gamestate_ProcessEvent(struct Game *game, struct AboutResources *data, ALLEGRO_EVENT *ev) {
if (ev->type == ALLEGRO_EVENT_KEY_DOWN) {
if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
SwitchGamestate(game, "about", "menu");
@ -71,7 +72,7 @@ void Gamestate_ProcessEvent(struct Game *game, struct About_Resources *data, ALL
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game *game)) {
struct About_Resources *data = malloc(sizeof(struct About_Resources));
struct AboutResources *data = malloc(sizeof(struct AboutResources));
data->image =LoadScaledBitmap(game, "table.png", game->viewport.width, game->viewport.height);
data->letter = LoadScaledBitmap(game, "about/letter.png", game->viewport.height*1.3, game->viewport.height*1.3 );
@ -186,7 +187,7 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game *game)) {
return data;
}
void Gamestate_Unload(struct Game *game, struct About_Resources* data) {
void Gamestate_Unload(struct Game *game, struct AboutResources* data) {
al_destroy_bitmap(data->image);
al_destroy_bitmap(data->letter);
al_destroy_bitmap(data->text_bitmap);
@ -196,13 +197,14 @@ void Gamestate_Unload(struct Game *game, struct About_Resources* data) {
free(data);
}
void Gamestate_Stop(struct Game *game, struct About_Resources* data) {
void Gamestate_Stop(struct Game *game, struct AboutResources* data) {
if (data->fadeloop!=0) {
FadeGamestate(game, false);
}
al_stop_sample_instance(data->music);
}
void Gamestate_Reload(struct Game *game, struct About_Resources* data) {}
void Gamestate_Reload(struct Game *game, struct AboutResources* data) {}
void Gamestate_Resume(struct Game *game, struct About_Resources* data) {}
void Gamestate_Pause(struct Game *game, struct About_Resources* data) {}
void Gamestate_Resume(struct Game *game, struct AboutResources* data) {}
void Gamestate_Pause(struct Game *game, struct AboutResources* data) {}

View file

@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
struct About_Resources {
struct AboutResources {
ALLEGRO_BITMAP *image; /*!< Background bitmap. */
ALLEGRO_BITMAP *text_bitmap; /*!< Bitmap with scrolled text. */
ALLEGRO_BITMAP *letter; /*!< Paper bitmap. */

View file

@ -19,14 +19,15 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <allegro5/allegro_ttf.h>
#include "../utils.h"
#include "disclaimer.h"
int Gamestate_ProgressCount = 0;
void Gamestate_Logic(struct Game *game, struct Disclaimer_Resources* data) {}
void Gamestate_Logic(struct Game *game, struct DisclaimerResources* data) {}
void Gamestate_Draw(struct Game *game, struct Disclaimer_Resources* data) {
void Gamestate_Draw(struct Game *game, struct DisclaimerResources* data) {
al_clear_to_color(al_map_rgb(0,0,0));
DrawTextWithShadow(data->font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height*0.3, ALLEGRO_ALIGN_CENTRE, "This is an early development preview of the game.");
DrawTextWithShadow(data->font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height*0.4, ALLEGRO_ALIGN_CENTRE, "It's not supposed to be complete!");
@ -35,35 +36,35 @@ void Gamestate_Draw(struct Game *game, struct Disclaimer_Resources* data) {
DrawTextWithShadow(data->font_small, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height*0.9, ALLEGRO_ALIGN_CENTRE, "Press any key to continue...");
}
void Gamestate_Start(struct Game *game, struct Disclaimer_Resources* data) {
void Gamestate_Start(struct Game *game, struct DisclaimerResources* data) {
FadeGamestate(game, true);
}
void Gamestate_ProcessEvent(struct Game *game, struct Disclaimer_Resources* data, ALLEGRO_EVENT *ev) {
void Gamestate_ProcessEvent(struct Game *game, struct DisclaimerResources* data, ALLEGRO_EVENT *ev) {
if (ev->type==ALLEGRO_EVENT_KEY_DOWN) {
SwitchGamestate(game, "disclaimer", "about");
SwitchGamestate(game, "disclaimer", "intro");
}
}
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
struct Disclaimer_Resources *data = malloc(sizeof(struct Disclaimer_Resources));
struct DisclaimerResources *data = malloc(sizeof(struct DisclaimerResources));
data->font_small = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.05,0 );
data->font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.065,0 );
if (progress) (*progress)(game);
return data;
}
void Gamestate_Stop(struct Game *game, struct Disclaimer_Resources* data) {
void Gamestate_Stop(struct Game *game, struct DisclaimerResources* data) {
FadeGamestate(game, false);
}
void Gamestate_Unload(struct Game *game, struct Disclaimer_Resources* data) {
void Gamestate_Unload(struct Game *game, struct DisclaimerResources* data) {
al_destroy_font(data->font);
al_destroy_font(data->font_small);
free(data);
}
void Gamestate_Reload(struct Game *game, struct Disclaimer_Resources* data) {}
void Gamestate_Reload(struct Game *game, struct DisclaimerResources* data) {}
void Gamestate_Resume(struct Game *game, struct Disclaimer_Resources* data) {}
void Gamestate_Pause(struct Game *game, struct Disclaimer_Resources* data) {}
void Gamestate_Resume(struct Game *game, struct DisclaimerResources* data) {}
void Gamestate_Pause(struct Game *game, struct DisclaimerResources* data) {}

View file

@ -19,6 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
struct Disclaimer_Resources {
struct DisclaimerResources {
ALLEGRO_FONT *font, *font_small;
};

View file

@ -20,21 +20,24 @@
*/
#include <math.h>
#include <stdio.h>
#include <allegro5/allegro_ttf.h>
#include "../utils.h"
#include "intro.h"
#include "map.h"
void AnimPage(struct Game *game, int page, ALLEGRO_COLOR tint) {
int Gamestate_ProgressCount = 0;
void AnimPage(struct Game *game, struct IntroResources *data, int page, ALLEGRO_COLOR tint) {
int offset = 0;
if (game->intro.in_animation) offset = -1*game->viewportWidth + (cos(((-1*((game->intro.position)%game->viewportWidth))/(float)game->viewportWidth)*(ALLEGRO_PI))/2.0)*game->viewportWidth + game->viewportWidth/2.0;
if (data->in_animation) offset = -1*game->viewport.width + (cos(((-1*((data->position)%game->viewport.width))/(float)game->viewport.width)*(ALLEGRO_PI))/2.0)*game->viewport.width + game->viewport.width/2.0;
int amount1 = 2, amount2 = 2;
float anim = game->intro.anim;
float anim = data->anim;
if (page==2) { amount1=4; amount2=3; }
if (page==3) { amount1=3; amount2=3; }
if (page==5) { amount1=5; amount2=3; anim*=2; }
if (page<6) al_draw_tinted_bitmap_region(game->intro.animsprites[page-1],tint,game->viewportHeight*1.6*0.3125*(int)fmod(anim,amount1),game->viewportHeight*0.63*(((int)(anim/amount1))%amount2),game->viewportHeight*1.6*0.3125, game->viewportHeight*0.63,offset+game->viewportWidth*0.09, game->viewportHeight*0.18,0);
if (page<6) al_draw_tinted_bitmap_region(data->animsprites[page-1],tint,game->viewport.height*1.6*0.3125*(int)fmod(anim,amount1),game->viewport.height*0.63*(((int)(anim/amount1))%amount2),game->viewport.height*1.6*0.3125, game->viewport.height*0.63,offset+game->viewport.width*0.09, game->viewport.height*0.18,0);
amount1 = 2;
amount2 = 2;
@ -42,25 +45,25 @@ void AnimPage(struct Game *game, int page, ALLEGRO_COLOR tint) {
if (page==2) { amount1=3; amount2=3; }
if (page==4) { amount1=5; amount2=3; anim*=2; }
if (page<5) al_draw_tinted_bitmap_region(game->intro.animsprites[page],tint,game->viewportHeight*1.6*0.3125*(int)fmod(anim,amount1),game->viewportHeight*0.63*(((int)(anim/amount1))%amount2),game->viewportHeight*1.6*0.3125, game->viewportHeight*0.63,offset+game->viewportWidth*1.09, game->viewportHeight*0.18,0);
if (page<5) al_draw_tinted_bitmap_region(data->animsprites[page],tint,game->viewport.height*1.6*0.3125*(int)fmod(anim,amount1),game->viewport.height*0.63*(((int)(anim/amount1))%amount2),game->viewport.height*1.6*0.3125, game->viewport.height*0.63,offset+game->viewport.width*1.09, game->viewport.height*0.18,0);
}
void FillPage(struct Game *game, int page) {
void FillPage(struct Game *game, struct IntroResources *data, int page) {
char filename[30] = { };
sprintf(filename, "intro/%d.flac", page);
game->intro.audiostream = al_load_audio_stream(GetDataFilePath(filename), 4, 1024);
al_attach_audio_stream_to_mixer(game->intro.audiostream, game->audio.voice);
al_set_audio_stream_playing(game->intro.audiostream, false);
al_set_audio_stream_gain(game->intro.audiostream, 1.75);
data->audiostream = al_load_audio_stream(GetDataFilePath(filename), 4, 1024);
al_attach_audio_stream_to_mixer(data->audiostream, game->audio.voice);
al_set_audio_stream_playing(data->audiostream, false);
al_set_audio_stream_gain(data->audiostream, 1.75);
al_set_target_bitmap(game->intro.table);
al_set_target_bitmap(data->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), game->viewportWidth*x, game->viewportHeight*y, ALLEGRO_ALIGN_LEFT, text);
DrawTextWithShadow(data->font, al_map_rgb(255,255,255), game->viewport.width*x, game->viewport.height*y, ALLEGRO_ALIGN_LEFT, text);
y+=0.07;
}
@ -68,7 +71,7 @@ void FillPage(struct Game *game, int page) {
switch (p) {
case 1:
al_hold_bitmap_drawing(true);
al_draw_bitmap(game->intro.table_bitmap, 0, 0, 0);
al_draw_bitmap(data->table_bitmap, 0, 0, 0);
al_hold_bitmap_drawing(true);
draw_text(1, "Ever since Twilight Sparkle and her");
draw_text(1, "friends imprisoned Discord in stone,");
@ -77,8 +80,8 @@ void FillPage(struct Game *game, int page) {
al_hold_bitmap_drawing(false);
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), game->viewportWidth*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), game->viewportWidth*0.5, 0, 0);
al_draw_bitmap_region(data->table_bitmap, al_get_bitmap_width(data->table_bitmap)/2, 0, al_get_bitmap_width(data->table_bitmap)/2, al_get_bitmap_height(data->table_bitmap), game->viewport.width*0, 0, 0);
al_draw_bitmap_region(data->table_bitmap, al_get_bitmap_width(data->table_bitmap)/2, 0, al_get_bitmap_width(data->table_bitmap)/2, al_get_bitmap_height(data->table_bitmap), game->viewport.width*0.5, 0, 0);
al_hold_bitmap_drawing(false);
al_hold_bitmap_drawing(true);
draw_text(2, "Until one day a reckless pony caused");
@ -88,8 +91,8 @@ void FillPage(struct Game *game, int page) {
break;
case 3:
al_hold_bitmap_drawing(true);
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), game->viewportWidth*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), game->viewportWidth*0.5, 0, 0);
al_draw_bitmap_region(data->table_bitmap, al_get_bitmap_width(data->table_bitmap)/2, 0, al_get_bitmap_width(data->table_bitmap)/2, al_get_bitmap_height(data->table_bitmap), game->viewport.width*0, 0, 0);
al_draw_bitmap_region(data->table_bitmap, al_get_bitmap_width(data->table_bitmap)/2, 0, al_get_bitmap_width(data->table_bitmap)/2, al_get_bitmap_height(data->table_bitmap), game->viewport.width*0.5, 0, 0);
al_hold_bitmap_drawing(false);
al_hold_bitmap_drawing(true);
draw_text(3, "This small amount of chaos was not");
@ -101,8 +104,8 @@ void FillPage(struct Game *game, int page) {
break;
case 4:
al_hold_bitmap_drawing(true);
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), game->viewportWidth*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), game->viewportWidth*0.5, 0, 0);
al_draw_bitmap_region(data->table_bitmap, al_get_bitmap_width(data->table_bitmap)/2, 0, al_get_bitmap_width(data->table_bitmap)/2, al_get_bitmap_height(data->table_bitmap), game->viewport.width*0, 0, 0);
al_draw_bitmap_region(data->table_bitmap, al_get_bitmap_width(data->table_bitmap)/2, 0, al_get_bitmap_width(data->table_bitmap)/2, al_get_bitmap_height(data->table_bitmap), game->viewport.width*0.5, 0, 0);
al_hold_bitmap_drawing(false);
al_hold_bitmap_drawing(true);
draw_text(4, "Discord, learning from his last failure,");
@ -116,8 +119,8 @@ void FillPage(struct Game *game, int page) {
break;
case 5:
al_hold_bitmap_drawing(true);
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), game->viewportWidth*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), game->viewportWidth*0.5, 0, 0);
al_draw_bitmap_region(data->table_bitmap, al_get_bitmap_width(data->table_bitmap)/2, 0, al_get_bitmap_width(data->table_bitmap)/2, al_get_bitmap_height(data->table_bitmap), game->viewport.width*0, 0, 0);
al_draw_bitmap_region(data->table_bitmap, al_get_bitmap_width(data->table_bitmap)/2, 0, al_get_bitmap_width(data->table_bitmap)/2, al_get_bitmap_height(data->table_bitmap), game->viewport.width*0.5, 0, 0);
al_hold_bitmap_drawing(false);
al_hold_bitmap_drawing(true);
draw_text(5, "Who can defeat Discord without");
@ -131,145 +134,134 @@ void FillPage(struct Game *game, int page) {
}
DrawPage(page);
ALLEGRO_BITMAP* second = al_create_bitmap(game->viewportWidth, game->viewportHeight);
ALLEGRO_BITMAP* second = al_create_bitmap(game->viewport.width, game->viewport.height);
al_set_target_bitmap(second);
DrawPage(page+1);
al_set_target_bitmap(game->intro.table);
al_draw_bitmap(second, game->viewportWidth, 0, 0);
al_set_target_bitmap(data->table);
al_draw_bitmap(second, game->viewport.width, 0, 0);
al_set_target_bitmap(al_get_backbuffer(game->display));
al_destroy_bitmap(second);
}
void Intro_Logic(struct Game *game) {
game->intro.anim += 1.0/20.0;
if (game->intro.in_animation) {
int old = game->intro.position%game->viewportWidth;
game->intro.position -= 10;
if (game->intro.position%game->viewportWidth>old) {
game->intro.in_animation = false;
FillPage(game, game->intro.page+1);
void Gamestate_Logic(struct Game *game, struct IntroResources* data) {
data->anim += 1.0/20.0;
if (data->in_animation) {
int old = data->position%game->viewport.width;
data->position -= 10;
if (data->position%game->viewport.width>old) {
data->in_animation = false;
FillPage(game, data, data->page+1);
PrintConsole(game, "Animation finished.");
al_set_audio_stream_playing(game->intro.audiostream, true);
al_set_audio_stream_playing(data->audiostream, true);
}
}
}
void Intro_Draw(struct Game *game) {
void Gamestate_Draw(struct Game *game, struct IntroResources* data) {
al_clear_to_color(al_map_rgb(0,0,0));
if (game->intro.in_animation) {
al_draw_bitmap(game->intro.table, -1*game->viewportWidth + (cos(((-1*((game->intro.position)%game->viewportWidth))/(float)game->viewportWidth)*(ALLEGRO_PI))/2.0)*game->viewportWidth + game->viewportWidth/2.0, 0, 0);
AnimPage(game, game->intro.page, al_map_rgba_f(1,1,1,1));
if (data->in_animation) {
al_draw_bitmap(data->table, -1*game->viewport.width + (cos(((-1*((data->position)%game->viewport.width))/(float)game->viewport.width)*(ALLEGRO_PI))/2.0)*game->viewport.width + game->viewport.width/2.0, 0, 0);
AnimPage(game, data, data->page, al_map_rgba_f(1,1,1,1));
}
else {
al_draw_bitmap(game->intro.table, 0, 0, 0);
AnimPage(game, game->intro.page+1, al_map_rgba_f(1,1,1,1));
al_draw_bitmap(data->table, 0, 0, 0);
AnimPage(game, data, data->page+1, al_map_rgba_f(1,1,1,1));
}
al_draw_text_with_shadow(game->intro.font, al_map_rgb(255,255,255), game->viewportWidth/2, game->viewportHeight*0.88, ALLEGRO_ALIGN_CENTRE, "Press any key to continue or escape to skip...");
al_draw_bitmap(game->intro.frame, 0, 0, 0);
DrawTextWithShadow(data->font, al_map_rgb(255,255,255), game->viewport.width/2, game->viewport.height*0.88, ALLEGRO_ALIGN_CENTRE, "Press any key to continue or escape to skip...");
al_draw_bitmap(data->frame, 0, 0, 0);
/*PrintConsole(game, "drawing");*/
if (game->intro.in_animation && game->intro.position<=-4*game->viewportWidth) {
if (data->in_animation && data->position<=-4*game->viewport.width) {
PrintConsole(game, "This was the last page.");
game->intro.in_animation = false;
game->intro.page--;
UnloadGameState(game);
game->loadstate = GAMESTATE_MAP;
PrintConsole(game, "Chainloading GAMESTATE_MAP...");
LoadGameState(game);
data->in_animation = false;
data->page--;
SwitchGamestate(game, "intro", "map");
}
}
void Intro_Load(struct Game *game) {
al_play_sample_instance(game->intro.music);
FadeGameState(game, true);
al_set_audio_stream_playing(game->intro.audiostream, true);
void Gamestate_Start(struct Game *game, struct IntroResources* data) {
al_play_sample_instance(data->music);
FadeGamestate(game, true);
al_set_audio_stream_playing(data->audiostream, true);
}
int Intro_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
void Gamestate_ProcessEvent(struct Game *game, struct IntroResources* data, ALLEGRO_EVENT *ev) {
if (ev->type != ALLEGRO_EVENT_KEY_DOWN) return;
if (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
UnloadGameState(game);
game->loadstate = GAMESTATE_MAP;
PrintConsole(game, "Chainloading GAMESTATE_MAP...");
LoadGameState(game);
return 0;
SwitchGamestate(game, "intro", "map");
return;
}
if (!game->intro.in_animation) {
if (game->intro.audiostream) {
al_set_audio_stream_playing(game->intro.audiostream, false);
al_destroy_audio_stream(game->intro.audiostream);
game->intro.audiostream=NULL;
if (!data->in_animation) {
if (data->audiostream) {
al_set_audio_stream_playing(data->audiostream, false);
al_destroy_audio_stream(data->audiostream);
data->audiostream=NULL;
}
PrintConsole(game, "Animate page (was on %d)...", ++game->intro.page);
game->intro.in_animation = true;
PrintConsole(game, "Animate page (was on %d)...", ++data->page);
data->in_animation = true;
}
return 0;
}
void Intro_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
PROGRESS_INIT(16);
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
struct IntroResources *data = malloc(sizeof(struct IntroResources));
game->intro.audiostream = NULL;
game->intro.position = 0;
game->intro.page = 0;
game->intro.in_animation = false;
game->intro.anim = 0;
data->audiostream = NULL;
data->position = 0;
data->page = 0;
data->in_animation = false;
data->anim = 0;
game->intro.animsprites[0] = LoadScaledBitmap("intro/1.png", (int)(game->viewportHeight*1.6*0.3125)*2, game->viewportHeight*0.63*2);
PROGRESS;
game->intro.animsprites[1] = LoadScaledBitmap("intro/2.png", (int)(game->viewportHeight*1.6*0.3125)*4, game->viewportHeight*0.63*3);
PROGRESS;
game->intro.animsprites[2] = LoadScaledBitmap("intro/3.png", (int)(game->viewportHeight*1.6*0.3125)*3, game->viewportHeight*0.63*3);
PROGRESS;
game->intro.animsprites[3] = LoadScaledBitmap("intro/4.png", (int)(game->viewportHeight*1.6*0.3125)*2, game->viewportHeight*0.63*2);
PROGRESS;
game->intro.animsprites[4] = LoadScaledBitmap("intro/5.png", (int)(game->viewportHeight*1.6*0.3125)*5, game->viewportHeight*0.63*3);
PROGRESS;
data->animsprites[0] = LoadScaledBitmap(game, "intro/1.png", (int)(game->viewport.height*1.6*0.3125)*2, game->viewport.height*0.63*2);
data->animsprites[1] = LoadScaledBitmap(game, "intro/2.png", (int)(game->viewport.height*1.6*0.3125)*4, game->viewport.height*0.63*3);
data->animsprites[2] = LoadScaledBitmap(game, "intro/3.png", (int)(game->viewport.height*1.6*0.3125)*3, game->viewport.height*0.63*3);
data->animsprites[3] = LoadScaledBitmap(game, "intro/4.png", (int)(game->viewport.height*1.6*0.3125)*2, game->viewport.height*0.63*2);
data->animsprites[4] = LoadScaledBitmap(game, "intro/5.png", (int)(game->viewport.height*1.6*0.3125)*5, game->viewport.height*0.63*3);
game->intro.table_bitmap =LoadScaledBitmap("intro/paper.png", game->viewportWidth, game->viewportHeight);
PROGRESS;
game->intro.frame =LoadScaledBitmap("intro/frame.png", game->viewportWidth, game->viewportHeight);
PROGRESS;
data->table_bitmap =LoadScaledBitmap(game, "intro/paper.png", game->viewport.width, game->viewport.height);
data->frame =LoadScaledBitmap(game, "intro/frame.png", game->viewport.width, game->viewport.height);
game->intro.sample = al_load_sample( GetDataFilePath("intro/intro.flac") );
PROGRESS;
data->sample = al_load_sample( GetDataFilePath("intro/intro.flac") );
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_gain(game->intro.music, 0.75);
al_set_sample_instance_playmode(game->intro.music, ALLEGRO_PLAYMODE_LOOP);
data->music = al_create_sample_instance(data->sample);
al_attach_sample_instance_to_mixer(data->music, game->audio.music);
al_set_sample_instance_gain(data->music, 0.75);
al_set_sample_instance_playmode(data->music, ALLEGRO_PLAYMODE_LOOP);
if (!game->intro.sample){
if (!data->sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
game->intro.table = al_create_bitmap(game->viewportWidth*2, game->viewportHeight);
data->table = al_create_bitmap(game->viewport.width*2, game->viewport.height);
game->intro.font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.04,0 );
data->font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.04,0 );
FillPage(game, 1);
PROGRESS;
FillPage(game, data, 1);
al_set_target_bitmap(al_get_backbuffer(game->display));
PrintConsole(game, "Chainpreloading GAMESTATE_MAP...");
PROGRESS;
void MapProgress(struct Game* game, float p) {
if (progress) (*progress)(game, load_p+=1/load_a);
}
Map_Preload(game, &MapProgress);
return data;
}
void Intro_Unload(struct Game *game) {
FadeGameState(game, false);
if (game->intro.audiostream) {
al_set_audio_stream_playing(game->intro.audiostream, false);
al_destroy_audio_stream(game->intro.audiostream);
void Gamestate_Unload(struct Game *game, struct IntroResources* data) {
if (data->audiostream) {
al_destroy_audio_stream(data->audiostream);
}
al_destroy_bitmap(game->intro.frame);
al_destroy_bitmap(game->intro.table);
al_destroy_bitmap(data->frame);
al_destroy_bitmap(data->table);
int i;
for (i=0; i<5; i++) {
al_destroy_bitmap(game->intro.animsprites[i]);
al_destroy_bitmap(data->animsprites[i]);
}
al_destroy_font(game->intro.font);
al_destroy_sample_instance(game->intro.music);
al_destroy_sample(game->intro.sample);
al_destroy_bitmap(game->intro.table_bitmap);
al_destroy_font(data->font);
al_destroy_sample_instance(data->music);
al_destroy_sample(data->sample);
al_destroy_bitmap(data->table_bitmap);
}
void Gamestate_Stop(struct Game *game, struct IntroResources* data) {
FadeGamestate(game, false);
if (data->audiostream) {
al_set_audio_stream_playing(data->audiostream, false);
}
}
void Gamestate_Pause(struct Game *game, struct IntroResources* data) {}
void Gamestate_Resume(struct Game *game, struct IntroResources* data) {}
void Gamestate_Reload(struct Game *game, struct IntroResources* data) {}

View file

@ -18,11 +18,23 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "../main.h"
void Intro_Draw(struct Game *game);
void Intro_Logic(struct Game *game);
void Intro_Preload(struct Game *game, void (*progress)(struct Game*, float));
void Intro_Unload(struct Game *game);
void Intro_Load(struct Game *game);
int Intro_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_audio.h>
/*! \brief Resources used by Intro state. */
struct IntroResources {
int position; /*!< Position of the page. */
int page; /*!< Current page number. */
bool in_animation; /*!< Animation as in page transition animation. */
float anim; /*!< Counter used for spritesheet animations. */
ALLEGRO_BITMAP *table; /*!< Background paper bitmap, two pages long. */
ALLEGRO_BITMAP *table_bitmap; /*!< Unscaled background paper bitmap. */
ALLEGRO_BITMAP *frame; /*!< Bitmap with frame around the screen. */
ALLEGRO_BITMAP *animsprites[5]; /*!< Array with spritesheet bitmaps. */
ALLEGRO_FONT *font; /*!< Font used for text. */
ALLEGRO_SAMPLE *sample; /*!< Background music sample. */
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
ALLEGRO_AUDIO_STREAM *audiostream; /*!< Audiostream used for Celestia voice. */
};

View file

@ -28,6 +28,9 @@
#include <locale.h>
#include <signal.h>
#include <dlfcn.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_ttf.h>
#include "utils.h"
#include "config.h"
#include "main.h"

View file

@ -25,10 +25,8 @@
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include "gamestate.h"
struct Gamestate;

View file

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <allegro5/allegro_primitives.h>
#include "stdio.h"
#include "config.h"
#include "math.h"

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
#include "main.h"