mirror of
https://github.com/FunKey-Project/Bibi.git
synced 2025-12-12 09:48:51 +01:00
menu displayed with pollEvent and FPS handling, faster KeyReapeat detection during game
This commit is contained in:
parent
7b143fd775
commit
dfc5c53d43
@ -63,6 +63,8 @@ t_game game_new(int nb_joueur, int niveau, int mode, int kill_bomb) {
|
||||
bomb_explose = FSOUND_Sample_Load(FSOUND_FREE, "audio/bomb.wav", 0, 0, 0);
|
||||
#elif defined(SOUND_SDL_ACTIVATED)
|
||||
bomb_explose = Mix_LoadWAV("audio/bomb.wav");
|
||||
//Mix_VolumeChunk(bomb_explose, MIX_MAX_VOLUME/2);
|
||||
Mix_VolumeChunk(bomb_explose, 20);
|
||||
#endif //SOUND_FMOD_ACTIVATED
|
||||
|
||||
return &the_game;
|
||||
@ -1177,7 +1179,6 @@ void game_display(t_game game, SDL_Surface *screen) {
|
||||
|
||||
/** Flip screen */
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
|
||||
36
src/main.c
36
src/main.c
@ -198,11 +198,12 @@ int main_game(SDL_Surface *screen, int nb_joueur, int niveau, int mode, int kill
|
||||
t_game game = game_new(nb_joueur,niveau,mode, kill_bomb); //on lance le jeu
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, SIZE_BLOC * map_get_width(game_the_map(game)),
|
||||
SIZE_BLOC * map_get_height(game_the_map(game)), WINDOW_BPP,
|
||||
0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
#else
|
||||
screen = SDL_SetVideoMode(SIZE_BLOC * map_get_width(game_the_map(game)),
|
||||
SIZE_BLOC * map_get_height(game_the_map(game)), WINDOW_BPP,
|
||||
SDL_HWSURFACE);
|
||||
@ -222,7 +223,8 @@ int main_game(SDL_Surface *screen, int nb_joueur, int niveau, int mode, int kill
|
||||
if (nb_joueur == 2)
|
||||
player2 = game_get_player2(game);
|
||||
|
||||
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_INTERVAL, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
|
||||
if (nb_joueur==1){ // boucle principale d'un jeu à 1 joueur:
|
||||
while (done==0 && player_get_dead(player1)!=0) {
|
||||
@ -310,6 +312,7 @@ int main_game(SDL_Surface *screen, int nb_joueur, int niveau, int mode, int kill
|
||||
}
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 480,480, WINDOW_BPP, 0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
@ -375,7 +378,6 @@ int main_game(SDL_Surface *screen, int nb_joueur, int niveau, int mode, int kill
|
||||
}
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
@ -495,13 +497,14 @@ int main(int argc, char *argv[]) {
|
||||
Mix_Music *musique_p_e = NULL;
|
||||
|
||||
//if(Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 640)==-1){
|
||||
if(Mix_OpenAudio(44100, AUDIO_S16, 1, 4096) < 0){
|
||||
//if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024)==-1){
|
||||
//if(Mix_OpenAudio(44100, AUDIO_S16, 1, 4096) < 0){
|
||||
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024)==-1){
|
||||
printf("Mix_OpenAudio: %s\n", Mix_GetError());
|
||||
//exit(2);
|
||||
}
|
||||
else{
|
||||
audio_init_ok = true;
|
||||
//Mix_Volume(1,MIX_MAX_VOLUME);
|
||||
const char *music_file;
|
||||
music_file = "audio/mm2titl2.ogg";
|
||||
musique_menu_p = Mix_LoadMUS(music_file);
|
||||
@ -557,9 +560,10 @@ int main(int argc, char *argv[]) {
|
||||
//3:editeur, 4:jouer aux niveaux edités, 5: options, 6: quitter)
|
||||
int game_over=NB_DECES;
|
||||
int resize=0; //Si resize=1 on remet l'écran à la taille 700*500
|
||||
|
||||
bool menu_change = true;
|
||||
int play_music=1;
|
||||
int audio=1;
|
||||
int prev_time_ms = 0;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
@ -577,7 +581,8 @@ int main(int argc, char *argv[]) {
|
||||
play_music=0;
|
||||
}
|
||||
|
||||
SDL_WaitEvent(&event);
|
||||
//SDL_WaitEvent(&event);
|
||||
while (SDL_PollEvent(&event));
|
||||
switch(event.type)
|
||||
{
|
||||
|
||||
@ -631,6 +636,7 @@ int main(int argc, char *argv[]) {
|
||||
choix_actuel=5;
|
||||
break;
|
||||
}
|
||||
menu_change = true;
|
||||
break;
|
||||
|
||||
case SDLK_DOWN:
|
||||
@ -661,6 +667,7 @@ int main(int argc, char *argv[]) {
|
||||
choix_actuel=1;
|
||||
break;
|
||||
}
|
||||
menu_change = true;
|
||||
break;
|
||||
|
||||
case SDLK_RETURN:
|
||||
@ -933,6 +940,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (resize==1){
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 700,500, WINDOW_BPP, 0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
@ -946,11 +954,13 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// Effacement de l'écran
|
||||
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
if(menu_change){
|
||||
//SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
SDL_BlitSurface(menu, NULL, screen, &positionMenu);
|
||||
menu_change = false;
|
||||
}
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
@ -959,6 +969,14 @@ int main(int argc, char *argv[]) {
|
||||
SDL_Flip(screen);
|
||||
#endif //HW_SCREEN_RESIZE
|
||||
|
||||
/** FPS handling */
|
||||
#define FPS_MENU 30
|
||||
int cur_time_ms = SDL_GetTicks();
|
||||
int wait_time_ms = 1000/FPS_MENU - (cur_time_ms-prev_time_ms);
|
||||
if(wait_time_ms > 0){
|
||||
SDL_Delay(wait_time_ms);
|
||||
}
|
||||
prev_time_ms = SDL_GetTicks();
|
||||
}
|
||||
|
||||
if(audio_init_ok){
|
||||
|
||||
12
src/niveau.c
12
src/niveau.c
@ -18,6 +18,7 @@ int niveau_1_joueur(SDL_Surface *screen, int niveau){
|
||||
SDL_Rect positionMenu;
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
//if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 480,480, WINDOW_BPP, 0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
@ -99,7 +100,6 @@ int niveau_1_joueur(SDL_Surface *screen, int niveau){
|
||||
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
SDL_BlitSurface(menu, NULL, screen, &positionMenu);
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
@ -115,6 +115,7 @@ int niveau_1_joueur(SDL_Surface *screen, int niveau){
|
||||
int niveau_2_joueur(SDL_Surface *screen, int choix_niveau){
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
//if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 480,480, WINDOW_BPP, 0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
@ -240,7 +241,6 @@ int niveau_2_joueur(SDL_Surface *screen, int choix_niveau){
|
||||
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
SDL_BlitSurface(menu, NULL, screen, &positionMenu);
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
@ -256,6 +256,7 @@ int niveau_2_joueur(SDL_Surface *screen, int choix_niveau){
|
||||
int editeur_choix_niveau(SDL_Surface *screen){
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
//if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 480,480, WINDOW_BPP, 0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
@ -361,7 +362,6 @@ int editeur_choix_niveau(SDL_Surface *screen){
|
||||
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
SDL_BlitSurface(menu, NULL, screen, &positionMenu);
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
@ -383,6 +383,7 @@ int are_you_sure(SDL_Surface *screen){
|
||||
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
//if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 480,480, WINDOW_BPP, 0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
@ -461,7 +462,6 @@ int are_you_sure(SDL_Surface *screen){
|
||||
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
SDL_BlitSurface(menu, NULL, screen, &positionMenu);
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
@ -477,6 +477,7 @@ int are_you_sure(SDL_Surface *screen){
|
||||
int choix_nb_joueurs(SDL_Surface *screen){
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
//if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 480,480, WINDOW_BPP, 0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
@ -550,7 +551,6 @@ int choix_nb_joueurs(SDL_Surface *screen){
|
||||
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
SDL_BlitSurface(menu, NULL, screen, &positionMenu);
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
@ -566,6 +566,7 @@ int choix_nb_joueurs(SDL_Surface *screen){
|
||||
int options(SDL_Surface *screen){
|
||||
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
//if(screen != NULL) SDL_FreeSurface(screen);
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 480,480, WINDOW_BPP, 0, 0, 0, 0);
|
||||
#else //HW_SCREEN_RESIZE
|
||||
@ -697,7 +698,6 @@ int options(SDL_Surface *screen){
|
||||
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
SDL_BlitSurface(menu, NULL, screen, &positionMenu);
|
||||
#ifdef HW_SCREEN_RESIZE
|
||||
SDL_FillRect(hw_screen, NULL, 0x000000);
|
||||
flip_NNOptimized_AllowOutOfScreen(screen, hw_screen,
|
||||
HW_SCREEN_WIDTH,
|
||||
MIN(screen->h*HW_SCREEN_WIDTH/screen->w, HW_SCREEN_HEIGHT));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user