pause music on pause :D

This commit is contained in:
Sebastian Krzyszkowiak 2012-03-02 17:47:02 +01:00
parent cc82a7d9d7
commit bad5c07f7f
4 changed files with 19 additions and 1 deletions

2
TODO
View file

@ -1,6 +1,8 @@
- check if every gamestate is stable on every platform
- moar documentation
- rewrite music handling into mixers
- control settings
- video settings
- rewrite config handling to allegro
- playable levels :D

View file

@ -8,6 +8,10 @@
#include "level.h"
void Level_Draw(struct Game *game) {
if (!al_get_sample_instance_playing(game->level.music) && (game->loadstate==GAMESTATE_LEVEL)) {
al_set_sample_instance_playing(game->level.music, true);
al_set_sample_instance_position(game->level.music, game->level.music_pos);
}
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);
@ -36,7 +40,8 @@ void Level_Draw(struct Game *game) {
}
void Level_Load(struct Game *game) {
if (game->music) al_play_sample(game->level.sample, 0.75, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
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)){
@ -55,6 +60,8 @@ int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
game->loadstate = GAMESTATE_MENU;
LoadGameState(game);
} else if (ev->keyboard.keycode==ALLEGRO_KEY_P) {
game->level.music_pos = al_get_sample_instance_position(game->level.music);
al_set_sample_instance_playing(game->level.music, false);
game->gamestate = GAMESTATE_PAUSE;
game->loadstate = GAMESTATE_LEVEL;
Pause_Load(game);
@ -77,6 +84,11 @@ void Level_Preload(struct Game *game) {
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
game->level.music = al_create_sample_instance(game->level.sample);
al_attach_sample_instance_to_mixer(game->level.music, al_get_default_mixer());
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);

View file

@ -32,6 +32,8 @@ struct Level {
ALLEGRO_BITMAP *derpy_walkcycle; /*!< Derpy walk cycle spritesheet. */
ALLEGRO_BITMAP *derpy; /*!< Derpy sprite. */
ALLEGRO_SAMPLE *sample; /*!< Sample with background music. */
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
unsigned int music_pos; /*!< Position of sample instance. Used when pausing game. */
int current_level; /*!< Level number. */
int derpy_frame; /*!< Current frame of Derpy animation. */
int derpy_frame_tmp; /*!< Counter used to slow down Derpy animation. */

View file

@ -15,7 +15,9 @@ int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
void Pause_Load(struct Game* game) {
game->gamestate=game->loadstate;
game->loadstate=GAMESTATE_PAUSE;
DrawGameState(game);
game->loadstate=game->gamestate;
game->gamestate=GAMESTATE_PAUSE;
ALLEGRO_BITMAP *fade = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(fade);