remove image cache, cleanup

This commit is contained in:
Sebastian Krzyszkowiak 2012-03-04 15:57:23 +01:00
parent b0b3fbc59e
commit 87dbd1f04b
9 changed files with 62 additions and 195 deletions

View file

@ -23,7 +23,7 @@
void About_Draw(struct Game *game) {
al_draw_scaled_bitmap(game->about.image,0,0,al_get_bitmap_width(game->about.image),al_get_bitmap_height(game->about.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_scaled_bitmap(game->about.letter_bitmap,0,0,al_get_bitmap_width(game->about.letter_bitmap),al_get_bitmap_height(game->about.letter_bitmap),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_scaled_bitmap(game->about.letter,0,0,al_get_bitmap_width(game->about.letter),al_get_bitmap_height(game->about.letter),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
float x = game->about.x;
if (x<0) x=0;
al_draw_bitmap_region(game->about.text_bitmap, 0, x*al_get_bitmap_height(game->about.text_bitmap), al_get_bitmap_width(game->about.text_bitmap), al_get_display_height(game->display)*0.8, al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.1, 0);
@ -59,11 +59,8 @@ int About_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
}
void About_Preload(struct Game *game) {
game->about.image =LoadFromCache(game, "table.png", al_get_display_width(game->display), al_get_display_height(game->display));
//game->about.image = al_load_bitmap( "data/table.png" );
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
game->about.letter = al_load_bitmap( "data/letter.png" );
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
game->about.image =LoadScaledBitmap("table.png", al_get_display_width(game->display), al_get_display_height(game->display));
game->about.letter = LoadScaledBitmap("letter.png", al_get_display_width(game->display), al_get_display_height(game->display) );
game->about.sample = al_load_sample( "data/about.flac" );
game->about.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",al_get_display_height(game->display)*0.035,0 );
@ -131,18 +128,10 @@ void About_Preload(struct Game *game) {
draw_text("or its associates.");
game->about.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
game->about.letter_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->about.letter_bitmap);
ScaleBitmap(game->about.letter, al_get_display_width(game->display), al_get_display_height(game->display));
al_destroy_bitmap(game->about.letter);
al_set_target_bitmap(game->about.fade_bitmap);
al_draw_bitmap(game->about.image, 0, 0, 0);
al_draw_bitmap(game->about.letter_bitmap, 0, 0, 0);
//al_draw_scaled_bitmap(game->about.image,0,0,al_get_bitmap_width(game->about.image),al_get_bitmap_height(game->about.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
//ScaleBitmap(game->about.letter, al_get_display_width(game->display), al_get_display_height(game->display), 0.75);
//al_draw_scaled_bitmap(game->about.letter,0,0,al_get_bitmap_width(game->about.letter),al_get_bitmap_height(game->about.letter),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_bitmap(game->about.letter, 0, 0, 0);
al_draw_bitmap_region(game->about.text_bitmap, 0, 0, al_get_bitmap_width(game->about.text_bitmap), al_get_display_height(game->display)*0.8, al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.1, 0);
al_set_target_bitmap(al_get_backbuffer(game->display));
@ -154,7 +143,7 @@ void About_Unload(struct Game *game) {
game->about.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->about.fade_bitmap);
al_draw_scaled_bitmap(game->about.image,0,0,al_get_bitmap_width(game->about.image),al_get_bitmap_height(game->about.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_scaled_bitmap(game->about.letter_bitmap,0,0,al_get_bitmap_width(game->about.letter_bitmap),al_get_bitmap_height(game->about.letter_bitmap),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_scaled_bitmap(game->about.letter,0,0,al_get_bitmap_width(game->about.letter),al_get_bitmap_height(game->about.letter),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_bitmap_region(game->about.text_bitmap, 0, game->about.x*al_get_bitmap_height(game->about.text_bitmap), al_get_bitmap_width(game->about.text_bitmap), al_get_display_height(game->display)*0.8, al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.1, 0);
al_set_target_bitmap(al_get_backbuffer(game->display));
int fadeloop;
@ -165,7 +154,7 @@ void About_Unload(struct Game *game) {
al_flip_display();
}
al_destroy_bitmap(game->about.image);
al_destroy_bitmap(game->about.letter_bitmap);
al_destroy_bitmap(game->about.letter);
al_destroy_bitmap(game->about.fade_bitmap);
al_destroy_bitmap(game->about.text_bitmap);
al_destroy_sample(game->about.sample);

View file

@ -97,16 +97,10 @@ void FillPage(struct Game *game, int page) {
void Intro_Draw(struct Game *game) {
al_clear_to_color(al_map_rgb(0,0,0));
//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)
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))*(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
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); */
if (game->intro.in_animation)
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);
else
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);
//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!");
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...");
//PrintConsole(game, "drawing");
if (game->intro.in_animation) {
@ -118,12 +112,8 @@ void Intro_Draw(struct Game *game) {
//DrawConsole(game);
//al_flip_display();
game->intro.in_animation = false;
//al_set_target_bitmap(game->intro.table);
//al_draw_bitmap(game->intro.table_whole, (-1)*game->intro.page*al_get_display_width(game->display), 0, 0);
//al_set_target_bitmap(al_get_backbuffer(game->display));
FillPage(game, game->intro.page+1);
PrintConsole(game, "Animation finished.");
//al_draw_bitmap(game->intro.table, 0, 0, 0);
}
else if (game->intro.position<=-4*al_get_display_width(game->display)) {
PrintConsole(game, "This was the last page.");
@ -168,25 +158,19 @@ void Intro_Preload(struct Game *game) {
game->intro.page = 0;
game->intro.in_animation = false;
game->intro.table_bitmap =LoadFromCache(game, "paper.png", al_get_display_width(game->display), al_get_display_height(game->display));
game->intro.table_bitmap =LoadScaledBitmap("paper.png", al_get_display_width(game->display), al_get_display_height(game->display));
//game->intro.table_bitmap = al_load_bitmap( "data/paper.png" );
game->intro.sample = al_load_sample( "data/intro.flac" );
if (!game->intro.sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
//al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
//game->intro.table_whole = al_create_bitmap(al_get_display_width(game->display)*5, al_get_display_height(game->display));
//al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
game->intro.table = al_create_bitmap(al_get_display_width(game->display)*2, al_get_display_height(game->display));
game->intro.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",al_get_display_height(game->display)*0.04,0 );
FillPage(game, 1);
//al_set_target_bitmap(game->intro.table);
//al_draw_bitmap(game->intro.table, 0, 0, 0);
al_set_target_bitmap(al_get_backbuffer(game->display));
PrintConsole(game, "Chainpreloading GAMESTATE_MAP...");
Map_Preload(game);
@ -201,7 +185,6 @@ void Intro_Unload(struct Game *game) {
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);
else
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);
//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();
}

View file

@ -31,9 +31,6 @@ void Level_Draw(struct Game *game) {
al_set_target_bitmap(game->level.derpy);
al_clear_to_color(al_map_rgba(0,0,0,0));
al_draw_bitmap_region(game->level.derpy_walkcycle,al_get_bitmap_width(game->level.derpy)*(game->level.derpy_frame%6),al_get_bitmap_height(game->level.derpy)*(game->level.derpy_frame/6),al_get_bitmap_width(game->level.derpy), al_get_bitmap_height(game->level.derpy),0,0,0);
//al_set_target_bitmap(game->level.derpy);
//al_clear_to_color(al_map_rgba(0,0,0,0));
//al_draw_scaled_bitmap(game->level.derpytmp, 0, 0, al_get_bitmap_width(game->level.derpytmp),al_get_bitmap_height(game->level.derpytmp), 0, 0, al_get_bitmap_width(game->level.derpy),al_get_bitmap_height(game->level.derpy), 0);
al_set_target_bitmap(al_get_backbuffer(game->display));
game->level.derpy_pos=game->level.derpy_pos+tps(game, 60*0.00092);
@ -57,7 +54,6 @@ void Level_Draw(struct Game *game) {
void Level_Load(struct Game *game) {
if (game->music) al_play_sample_instance(game->level.music);
//al_play_sample(game->level.sample, 0.75, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
ALLEGRO_EVENT ev;
int fadeloop;
for(fadeloop=0; fadeloop<256; fadeloop+=tps(game, 600)){
@ -86,11 +82,9 @@ void Level_Preload(struct Game *game) {
game->level.derpy_frame_tmp = 0;
game->level.derpy_pos = -0.2;
PrintConsole(game, "Initializing level %d...", game->level.current_level);
//game->level.image = al_load_bitmap( "data/table.png" );
game->level.image =LoadFromCache(game, "table.png", al_get_display_width(game->display), al_get_display_height(game->display));
game->level.image =LoadScaledBitmap("table.png", al_get_display_width(game->display), al_get_display_height(game->display));
game->level.sample = al_load_sample( "data/moonwalk.flac" );
//game->level.derpy_walkcycle = al_load_bitmap( "data/derpcycle.png" );
game->level.derpy_walkcycle =LoadFromCache(game, "derpcycle.png", al_get_display_width(game->display)*0.1953125*6, al_get_display_height(game->display)*0.25*4);
game->level.derpy_walkcycle = LoadScaledBitmap("derpcycle.png", al_get_display_width(game->display)*0.1953125*6, al_get_display_height(game->display)*0.25*4);
if (!game->level.sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
@ -102,7 +96,6 @@ void Level_Preload(struct Game *game) {
al_set_sample_instance_playmode(game->level.music, ALLEGRO_PLAYMODE_LOOP);
game->level.derpy = al_create_bitmap(al_get_display_width(game->display)*0.1953125, al_get_display_height(game->display)*0.25);
//game->level.derpytmp = al_create_bitmap(500, 400);
game->level.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->level.fade_bitmap);

View file

@ -59,49 +59,10 @@ void Loading_Load(struct Game *game) {
game->loading.loading_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
/* void GenerateLoadingBitmap() {
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
game->loading.image = al_load_bitmap( "data/loading.png" );
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
game->loading.image = LoadScaledBitmap("loading.png", al_get_display_width(game->display), al_get_display_height(game->display));
int width = al_get_display_width(game->display);
int height = al_get_display_height(game->display);
int x, y;
for (y = 0; y < height; y++) {
float pixy = ((float)y / height) * al_get_bitmap_height(game->loading.image);
for (x = 0; x < width; x++) {
float pixx = ((float)x / width) * al_get_bitmap_width(game->loading.image);
ALLEGRO_COLOR a = al_get_pixel(game->loading.image, pixx-0.25, pixy-0.25);
ALLEGRO_COLOR b = al_get_pixel(game->loading.image, pixx+0.25, pixy-0.25);
ALLEGRO_COLOR c = al_get_pixel(game->loading.image, pixx-0.25, pixy+0.25);
ALLEGRO_COLOR d = al_get_pixel(game->loading.image, pixx+0.25, pixy+0.25);
ALLEGRO_COLOR result = al_map_rgba_f(
(a.r+b.r+c.r+d.r) / 4,
(a.g+b.b+c.g+d.g) / 4,
(a.b+b.g+c.b+d.b) / 4,
(a.a+b.a+c.a+d.a) / 4
);
al_put_pixel(x, y, result);
}
}
al_save_bitmap("data/cache/loading.png", game->loading.loading_bitmap);
PrintConsole(game, "Cache bitmap generated.");
}
game->loading.image = al_load_bitmap( "data/cache/loading.png");
if (game->loading.image) {
if ((al_get_bitmap_width(game->loading.image)!=al_get_display_width(game->display)) || (al_get_bitmap_height(game->loading.image)!=al_get_display_height(game->display)))
GenerateLoadingBitmap();
else al_draw_bitmap(game->loading.image, 0, 0, 0);
} else GenerateLoadingBitmap();
*/
//game->loading.image = al_load_bitmap( "data/loading.png");
game->loading.image = LoadFromCache(game, "loading.png", al_get_display_width(game->display), al_get_display_height(game->display));
// Scale "Loading" bitmap
al_set_target_bitmap(game->loading.loading_bitmap);
//al_draw_bitmap(game->loading.image, 0, 0, 0);
al_draw_scaled_bitmap(game->loading.image,0, 0, al_get_bitmap_width(game->loading.image), al_get_bitmap_height(game->loading.image), 0, 0, al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_bitmap(game->loading.image, 0, 0, 0);
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.0234, al_get_display_height(game->display)*0.85, ALLEGRO_ALIGN_LEFT, "Loading...");
al_set_target_bitmap(al_get_backbuffer(game->display));
al_destroy_bitmap(game->loading.image);

View file

@ -204,14 +204,14 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height) {
al_unlock_bitmap(source);
}
ALLEGRO_BITMAP* LoadFromCache(struct Game *game, char* filename, int width, int height) {
ALLEGRO_BITMAP* LoadScaledBitmap(char* filename, int width, int height) {
ALLEGRO_BITMAP *source, *target = al_create_bitmap(width, height);
al_set_target_bitmap(target);
al_clear_to_color(al_map_rgba(0,0,0,0));
char origfn[255] = "data/";
char cachefn[255] = "data/cache/";
//char cachefn[255] = "data/cache/";
strcat(origfn, filename);
strcat(cachefn, filename);
//strcat(cachefn, filename);
void GenerateBitmap() {
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
@ -219,20 +219,21 @@ ALLEGRO_BITMAP* LoadFromCache(struct Game *game, char* filename, int width, int
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
ScaleBitmap(source, width, height);
al_save_bitmap(cachefn, target);
PrintConsole(game, "Cache bitmap %s generated.", filename);
//al_save_bitmap(cachefn, target);
//PrintConsole(game, "Cache bitmap %s generated.", filename);
al_destroy_bitmap(source);
}
source = al_load_bitmap( cachefn );
if (source) {
if ((al_get_bitmap_width(source)!=width) || (al_get_bitmap_height(source)!=height)) {
al_destroy_bitmap(source);
//source = al_load_bitmap( cachefn );
//if (source) {
// if ((al_get_bitmap_width(source)!=width) || (al_get_bitmap_height(source)!=height)) {
// al_destroy_bitmap(source);
GenerateBitmap();
return target;
}
return source;
} else GenerateBitmap();
return target;
// }
// return source;
//} else GenerateBitmap();
//return target;
}
float tps(struct Game *game, float t) {

View file

@ -58,21 +58,16 @@ struct Level {
/*! \brief Resources used by Menu state. */
struct Menu {
ALLEGRO_BITMAP *menu_bitmap;
ALLEGRO_BITMAP *menu_fade_bitmap;
ALLEGRO_BITMAP *image;
ALLEGRO_BITMAP *cloud_bitmap;
ALLEGRO_BITMAP *cloud;
ALLEGRO_BITMAP *cloud2_bitmap;
ALLEGRO_BITMAP *cloud2;
ALLEGRO_BITMAP *pie;
ALLEGRO_BITMAP *pie_bitmap;
ALLEGRO_BITMAP *pinkcloud_bitmap;
ALLEGRO_BITMAP *pinkcloud_scaled;
ALLEGRO_BITMAP *pinkcloud;
ALLEGRO_BITMAP *rain;
ALLEGRO_BITMAP *rain_bitmap;
ALLEGRO_BITMAP *mountain_bitmap;
ALLEGRO_BITMAP *mountain;
float cloud_position;
float cloud2_position;
@ -110,7 +105,6 @@ struct About {
ALLEGRO_BITMAP *image;
ALLEGRO_BITMAP *text_bitmap;
ALLEGRO_BITMAP *letter;
ALLEGRO_BITMAP *letter_bitmap;
ALLEGRO_SAMPLE *sample;
ALLEGRO_FONT *font;
float x;
@ -196,8 +190,8 @@ void PrintConsole(struct Game *game, char* format, ...);
/*! \brief Draws console bitmap on screen. */
void DrawConsole(struct Game *game);
void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);
ALLEGRO_BITMAP* LoadFromCache(struct Game *game, char* filename, int width, int height);
//void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);
ALLEGRO_BITMAP* LoadScaledBitmap(char* filename, int width, int height);
float tps(struct Game *game, float t);
void DrawGameState(struct Game *game);

View file

@ -103,14 +103,11 @@ void Map_Preload(struct Game *game) {
game->map.selected = game->map.available;
PrintConsole(game, "Last level available: %d", game->map.selected);
game->map.arrowpos = 0;
game->map.map = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
//game->map.background = al_load_bitmap( "data/table.png" );
game->map.map_bg = al_load_bitmap( "data/map/background.png" );
game->map.map_bg = LoadScaledBitmap("map/background.png", al_get_display_width(game->display), al_get_display_height(game->display));
char filename[30] = { };
sprintf(filename, "data/map/highlight%d.png", game->map.available);
game->map.highlight = al_load_bitmap( filename );
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
sprintf(filename, "map/highlight%d.png", game->map.available);
game->map.highlight = LoadScaledBitmap(filename, al_get_display_width(game->display), al_get_display_height(game->display));
game->map.arrow = al_load_bitmap( "data/arrow.png" );
game->map.click_sample = al_load_sample( "data/click.flac" );
@ -125,22 +122,10 @@ void Map_Preload(struct Game *game) {
exit(-1);
}
ALLEGRO_BITMAP *scaled =LoadFromCache(game, "table.png", al_get_display_width(game->display), al_get_display_height(game->display));
game->map.map = LoadScaledBitmap("table.png", al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->map.map);
al_draw_bitmap(scaled, 0, 0 ,0);
//ScaleBitmap(game->map.background, al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(scaled);
ScaleBitmap(game->map.map_bg, al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->map.map);
al_draw_bitmap(scaled, 0, 0 ,0);
al_set_target_bitmap(scaled);
ScaleBitmap(game->map.highlight, al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->map.map);
al_draw_bitmap(scaled, 0, 0 ,0);
al_destroy_bitmap(scaled);
//al_draw_scaled_bitmap(game->map.background,0,0,al_get_bitmap_width(game->map.background),al_get_bitmap_height(game->map.background),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
//al_draw_scaled_bitmap(game->map.map_bg,0,0,al_get_bitmap_width(game->map.map_bg),al_get_bitmap_height(game->map.map_bg),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
//al_draw_scaled_bitmap(game->map.highlight,0,0,al_get_bitmap_width(game->map.highlight),al_get_bitmap_height(game->map.highlight),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_bitmap(game->map.map_bg, 0, 0 ,0);
al_draw_bitmap(game->map.highlight, 0, 0 ,0);
al_set_target_bitmap(al_get_backbuffer(game->display));
}

View file

@ -25,7 +25,6 @@
void Menu_Draw(struct Game *game) {
//game->menu.pinkcloud_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.33125, al_get_display_height(game->display)); //*0.8122);
al_set_target_bitmap(game->menu.pinkcloud_bitmap);
al_clear_to_color(al_map_rgba(0,0,0,0));
float x = 1.5;//*(rand() / (float)RAND_MAX);
@ -35,18 +34,18 @@ void Menu_Draw(struct Game *game) {
al_draw_bitmap(game->menu.rain_bitmap, fmod(minus*game->menu.cloud_position,3)*x*3+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/3.1, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.78+(fmod(-2.8*(game->menu.cloud_position+80), 4))/18.0), 0);
al_draw_scaled_bitmap(game->menu.rain_bitmap, 0, 0, al_get_bitmap_width(game->menu.rain_bitmap), al_get_bitmap_height(game->menu.rain_bitmap), fmod(minus*game->menu.cloud_position,3)*x*6+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/2.1, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.87+(fmod(-4.9*(game->menu.cloud_position+80), 8))/26.0), al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.4, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.08, 0);
//al_draw_scaled_bitmap(game->menu.rain, 0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), fmod(minus*game->menu.cloud_position,3)*x*6+al_get_bitmap_width(game->menu.pinkcloud_bitmap)/2.4, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*(0.9+(fmod(-5*(game->menu.cloud_position+86), 8))/20.0), al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.35, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.07, 0);
al_draw_bitmap(game->menu.pinkcloud_scaled, 0, 0, 0);
al_draw_bitmap(game->menu.pinkcloud, 0, 0, 0);
al_set_target_bitmap(al_get_backbuffer(game->display));
al_clear_to_color(al_map_rgb(183,234,193));
float tint = (sin((game->menu.cloud_position-80)/15)+1)/2;
if (tint < 0.000004) { PrintConsole(game, "random tint %f", tint); game->menu.mountain_position = (al_get_display_width(game->display)*(rand()/(float)RAND_MAX)/2)+al_get_display_width(game->display)/2; }
al_draw_tinted_bitmap(game->menu.mountain_bitmap,al_map_rgba_f(tint,tint,tint,tint),game->menu.mountain_position, 0,0);
al_draw_scaled_bitmap(game->menu.cloud_bitmap,0,0,al_get_bitmap_width(game->menu.cloud_bitmap), al_get_bitmap_height(game->menu.cloud_bitmap), al_get_display_width(game->display)*(sin((game->menu.cloud_position/40)-4.5)-0.3), al_get_display_height(game->display)*0.35, al_get_bitmap_width(game->menu.cloud_bitmap)/2, al_get_bitmap_height(game->menu.cloud_bitmap)/2,0);
al_draw_bitmap(game->menu.cloud2_bitmap,al_get_display_width(game->display)*(game->menu.cloud2_position/100.0), al_get_display_height(game->display)/1.5,0);
al_draw_bitmap(game->menu.menu_bitmap,0, al_get_display_height(game->display)*0.55,0);
al_draw_tinted_bitmap(game->menu.mountain,al_map_rgba_f(tint,tint,tint,tint),game->menu.mountain_position, 0,0);
al_draw_scaled_bitmap(game->menu.cloud,0,0,al_get_bitmap_width(game->menu.cloud), al_get_bitmap_height(game->menu.cloud), al_get_display_width(game->display)*(sin((game->menu.cloud_position/40)-4.5)-0.3), al_get_display_height(game->display)*0.35, al_get_bitmap_width(game->menu.cloud)/2, al_get_bitmap_height(game->menu.cloud)/2,0);
al_draw_bitmap(game->menu.cloud2,al_get_display_width(game->display)*(game->menu.cloud2_position/100.0), al_get_display_height(game->display)/1.5,0);
al_draw_bitmap(game->menu.image,0, al_get_display_height(game->display)*0.55,0);
al_draw_bitmap(game->menu.pinkcloud_bitmap,(al_get_display_width(game->display)*0.12) + (cos((game->menu.cloud_position/25+80)*1.74444))*40, 0,0);
al_draw_bitmap(game->menu.cloud_bitmap,al_get_display_width(game->display)*game->menu.cloud_position/100, 30,0);
al_draw_bitmap(game->menu.cloud,al_get_display_width(game->display)*game->menu.cloud_position/100, 30,0);
al_draw_bitmap(game->menu.pie_bitmap, al_get_display_width(game->display)/2, al_get_display_height(game->display)*(game->menu.cloud_position)/10,0);
@ -84,21 +83,18 @@ void Menu_Draw(struct Game *game) {
}
void Menu_Preload(struct Game *game) {
PrintConsole(game, "menu preload");
game->menu.loaded = true;
//game->menu.image = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
//al_destroy_bitmap(game->menu.image); // ugh...
game->menu.image = LoadScaledBitmap( "menu.png", al_get_display_width(game->display), al_get_display_height(game->display)*0.45);
game->menu.mountain = LoadScaledBitmap( "mountain.png", al_get_display_width(game->display)*0.055, al_get_display_height(game->display)/9 );
game->menu.cloud = LoadScaledBitmap( "cloud.png", al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.25 );
game->menu.cloud2 = LoadScaledBitmap( "cloud2.png", al_get_display_width(game->display)*0.2, al_get_display_height(game->display)*0.1 );
game->menu.pinkcloud = LoadScaledBitmap( "pinkcloud.png", al_get_display_width(game->display)*0.33125, al_get_display_height(game->display)*0.8122);
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
game->menu.image = al_load_bitmap( "data/menu.png" );
game->menu.mountain = al_load_bitmap( "data/mountain.png" );
game->menu.cloud = al_load_bitmap( "data/cloud.png" );
game->menu.cloud2 = al_load_bitmap( "data/cloud2.png" );
game->menu.rain = al_load_bitmap( "data/rain.png" );
game->menu.pie = al_load_bitmap( "data/pie.png" );
game->menu.pinkcloud = al_load_bitmap( "data/pinkcloud.png" );
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
//game->menu.menu_bitmap = LoadFromCache(game, "menu.png", al_get_display_width(game->display), al_get_display_height(game->display));
game->menu.sample = al_load_sample( "data/menu.flac" );
game->menu.rain_sample = al_load_sample( "data/rain.flac" );
game->menu.click_sample = al_load_sample( "data/click.flac" );
@ -124,35 +120,7 @@ void Menu_Preload(struct Game *game) {
exit(-1);
}
// Scale menu bitmap
game->menu.menu_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)*0.45);
al_set_target_bitmap(game->menu.menu_bitmap);
al_clear_to_color(al_map_rgba(0,0,0,0));
ScaleBitmap(game->menu.image, al_get_display_width(game->display), al_get_display_height(game->display)*0.45);
//al_draw_scaled_bitmap(game->menu.image,0, 0, al_get_bitmap_width(game->menu.image), al_get_bitmap_height(game->menu.image), 0, 0, al_get_display_width(game->display), al_get_display_height(game->display),0);
al_destroy_bitmap(game->menu.image);
// Cloud menu bitmap
game->menu.cloud_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.25);
al_set_target_bitmap(game->menu.cloud_bitmap);
al_clear_to_color(al_map_rgba(0,0,0,0));
ScaleBitmap(game->menu.cloud, al_get_bitmap_width(game->menu.cloud_bitmap), al_get_bitmap_height(game->menu.cloud_bitmap));
//al_draw_scaled_bitmap(game->menu.cloud,0, 0, al_get_bitmap_width(game->menu.cloud), al_get_bitmap_height(game->menu.cloud), 0, 0, al_get_bitmap_width(game->menu.cloud_bitmap), al_get_bitmap_height(game->menu.cloud_bitmap),0);
al_destroy_bitmap(game->menu.cloud);
game->menu.cloud2_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.2, al_get_display_height(game->display)*0.1);
al_set_target_bitmap(game->menu.cloud2_bitmap);
al_clear_to_color(al_map_rgba(0,0,0,0));
ScaleBitmap(game->menu.cloud2, al_get_bitmap_width(game->menu.cloud2_bitmap), al_get_bitmap_height(game->menu.cloud2_bitmap));
//al_draw_scaled_bitmap(game->menu.cloud2,0, 0, al_get_bitmap_width(game->menu.cloud2), al_get_bitmap_height(game->menu.cloud2), 0, 0, al_get_bitmap_width(game->menu.cloud2_bitmap), al_get_bitmap_height(game->menu.cloud2_bitmap),0);
al_destroy_bitmap(game->menu.cloud2);
game->menu.pinkcloud_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.33125, al_get_display_height(game->display)); //*0.8122);
game->menu.pinkcloud_scaled = al_create_bitmap(al_get_bitmap_width(game->menu.pinkcloud_bitmap), al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.8122);
al_set_target_bitmap(game->menu.pinkcloud_scaled);
ScaleBitmap(game->menu.pinkcloud, al_get_bitmap_width(game->menu.pinkcloud_scaled), al_get_bitmap_height(game->menu.pinkcloud_scaled));
//al_draw_scaled_bitmap(game->menu.pinkcloud,0, 0, al_get_bitmap_width(game->menu.pinkcloud), al_get_bitmap_height(game->menu.pinkcloud), 0, 0, al_get_bitmap_width(game->menu.pinkcloud_scaled), al_get_bitmap_height(game->menu.pinkcloud_scaled),0);
al_destroy_bitmap(game->menu.pinkcloud);
game->menu.pinkcloud_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.33125, al_get_display_height(game->display)); // *0.8122);
game->menu.pie_bitmap = al_create_bitmap(al_get_display_width(game->display)/2, al_get_display_height(game->display)); //*0.8122);
al_set_target_bitmap(game->menu.pie_bitmap);
@ -162,13 +130,6 @@ void Menu_Preload(struct Game *game) {
al_draw_scaled_bitmap(game->menu.pie, 0, 0, al_get_bitmap_width(game->menu.pie), al_get_bitmap_height(game->menu.pie), al_get_bitmap_width(game->menu.pie_bitmap)*0.3, al_get_bitmap_height(game->menu.pie_bitmap)*0.6, al_get_display_width(game->display)*0.13, al_get_display_height(game->display)*0.1, 0);
al_destroy_bitmap(game->menu.pie);
game->menu.mountain_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.055, al_get_display_height(game->display)/9);
al_set_target_bitmap(game->menu.mountain_bitmap);
al_clear_to_color(al_map_rgba(0,0,0,0));
ScaleBitmap(game->menu.mountain, al_get_bitmap_width(game->menu.mountain_bitmap), al_get_bitmap_height(game->menu.mountain_bitmap));
//al_draw_scaled_bitmap(game->menu.mountain,0, 0, al_get_bitmap_width(game->menu.mountain), al_get_bitmap_height(game->menu.mountain), 0, 0, al_get_bitmap_width(game->menu.mountain_bitmap), al_get_bitmap_height(game->menu.mountain_bitmap),0);
al_destroy_bitmap(game->menu.mountain);
al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
game->menu.rain_bitmap = al_create_bitmap(al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.5, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.1);
al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
@ -197,15 +158,15 @@ void Menu_Stop(struct Game* game) {
}
void Menu_Unload(struct Game *game) {
Menu_Stop(game);
if (game->gamestate==GAMESTATE_MENU) Menu_Stop(game);
al_destroy_bitmap(game->menu.menu_fade_bitmap);
al_destroy_bitmap(game->menu.pinkcloud_scaled);
al_destroy_bitmap(game->menu.menu_bitmap);
al_destroy_bitmap(game->menu.cloud_bitmap);
al_destroy_bitmap(game->menu.cloud2_bitmap);
al_destroy_bitmap(game->menu.pinkcloud);
al_destroy_bitmap(game->menu.image);
al_destroy_bitmap(game->menu.cloud);
al_destroy_bitmap(game->menu.cloud2);
al_destroy_bitmap(game->menu.pinkcloud_bitmap);
al_destroy_bitmap(game->menu.rain_bitmap);
al_destroy_bitmap(game->menu.mountain_bitmap);
al_destroy_bitmap(game->menu.mountain);
al_destroy_bitmap(game->menu.pie_bitmap);
al_destroy_font(game->menu.font_title);
al_destroy_font(game->menu.font_subtitle);
@ -222,7 +183,6 @@ void play_samples(struct Game *game) {
}
void Menu_Load(struct Game *game) {
//game->menu.draw_while_fading = atoi(GetConfigOptionDefault("[MuffinAttack]", "menu_draw_while_fading", "1"));
game->menu.cloud_position = 100;
game->menu.cloud2_position = 100;
game->menu.options = false;
@ -236,11 +196,6 @@ void Menu_Load(struct Game *game) {
ALLEGRO_EVENT ev;
float fadeloop;
for(fadeloop=255; fadeloop>=0; fadeloop-=tps(game, 600)){
//if ((game->menu.draw_while_fading) || (fadeloop==0)) {
// al_set_target_bitmap(game->menu.menu_fade_bitmap);
// al_draw_bitmap(al_get_backbuffer(game->display), 0, 0, 0);
// al_set_target_bitmap(al_get_backbuffer(game->display));
//}
al_wait_for_event(game->event_queue, &ev);
Menu_Draw(game);
al_draw_tinted_bitmap(game->menu.menu_fade_bitmap,al_map_rgba_f(1,1,1,fadeloop/255.0),0,0,0);

View file

@ -21,10 +21,11 @@
#include <stdio.h>
#include "config.h"
#include "pause.h"
#include "menu.h"
int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
if ((ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->pause.options==0) && (game->pause.selected==0))) {
al_destroy_bitmap(game->pause.bitmap);
Pause_Unload_Real(game);
game->gamestate = game->loadstate;
}
else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->pause.options==0) && (game->pause.selected==1)) {
@ -61,7 +62,8 @@ int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
void Pause_Preload(struct Game* game) {
game->pause.bitmap = NULL;
game->pause.derpy = al_create_bitmap(al_get_display_width(game->display)*0.53, al_get_display_height(game->display)*0.604);
game->pause.derpy = LoadScaledBitmap("derpy_pause.png", al_get_display_width(game->display)*0.53, al_get_display_height(game->display)*0.604);
/*(game->pause.derpy = al_create_bitmap(al_get_display_width(game->display)*0.53, al_get_display_height(game->display)*0.604);
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
ALLEGRO_BITMAP *derpy = al_load_bitmap( "data/derpy_pause.png" );
@ -71,10 +73,11 @@ void Pause_Preload(struct Game* game) {
ScaleBitmap(derpy, al_get_display_width(game->display)*0.53, al_get_display_height(game->display)*0.604);
al_set_target_bitmap(al_get_backbuffer(game->display));
al_destroy_bitmap(derpy);
al_destroy_bitmap(derpy);*/
}
void Pause_Load(struct Game* game) {
PrintConsole(game,"Pause loaded.");
game->gamestate=game->loadstate;
game->loadstate=GAMESTATE_PAUSE;
DrawGameState(game);
@ -129,6 +132,7 @@ void Pause_Draw(struct Game* game) {
}
void Pause_Unload_Real(struct Game* game) {
PrintConsole(game,"Pause unloaded.");
if (game->pause.bitmap) al_destroy_bitmap(game->pause.bitmap);
al_destroy_bitmap(game->pause.derpy);
}
@ -136,4 +140,6 @@ void Pause_Unload_Real(struct Game* game) {
void Pause_Unload(struct Game* game) {
game->gamestate=game->loadstate;
UnloadGameState(game);
PrintConsole(game, "Pause: Unloading GAMESTATE_MENU...");
Menu_Unload(game);
}