00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "menu.h"
00030
00031 Uint32 callback(Uint32 interval){
00032 return 20;
00033 }
00034
00035
00036 Menu::Menu(Screen &scr, Sound *snd){
00037 int i,j;
00038 for(i=0; i<num_menu_choices; i++){
00039 for(j=0; j<2; j++){
00040 menu_choices[i][j] = new SDL_Surface;
00041 }
00042 }
00043 title = NULL;
00044 char_image = NULL;
00045 current_selection = 0;
00046 current_alpha = 255;
00047 alpha_direction = 0;
00048 sfx = "data/sounds/shot.wav";
00049 bgm = "data/sounds/abibeat.mod";
00050 screen = scr;
00051 sound = snd;
00052 }
00053
00054 Menu::~Menu(){
00055 }
00056
00057 void Menu::load_menu_data(){
00058 if(MENU_DEBUG) printf("loading menu data Start\n");
00059 if( (menu_choices[0][0] = IMG_Load("data/menu/menu_new_1.gif")) == NULL){
00060 cerr << "Couldn't load tile data/menu/menu_new_1.gif: " << SDL_GetError() << endl;
00061 return;
00062 }
00063 if( (menu_choices[0][1] = IMG_Load("data/menu/menu_new_2.gif")) == NULL){
00064 cerr << "Couldn't load tile data/menu/menu_new_2.gif: " << SDL_GetError() << endl;
00065 return;
00066 }
00067 if( (menu_choices[1][0] = IMG_Load("data/menu/menu_options_1.gif")) == NULL){
00068 cerr << "Couldn't load tile data/menu/menu_options_1.gif: " << SDL_GetError() << endl;
00069 return;
00070 }
00071 if( (menu_choices[1][1] = IMG_Load("data/menu/menu_options_2.gif")) == NULL){
00072 cerr << "Couldn't load tile data/menu/menu_options_2.gif: " << SDL_GetError() << endl;
00073 return;
00074 }
00075 if( (menu_choices[2][0] = IMG_Load("data/menu/menu_quit_1.gif")) == NULL){
00076 cerr << "Couldn't load tile data/menu/menu_quit_1.gif: " << SDL_GetError() << endl;
00077 return;
00078 }
00079 if( (menu_choices[2][1] = IMG_Load("data/menu/menu_quit_2.gif")) == NULL){
00080 cerr << "Couldn't load tile data/menu/menu_quit_2.gif: " << SDL_GetError() << endl;
00081 return;
00082 }
00083 if( (title = IMG_Load("data/menu/title.gif")) == NULL){
00084 cerr << "Couldn't load tile data/menu/title.gif: " << SDL_GetError() << endl;
00085 return;
00086 }
00087 if( (char_image = IMG_Load("data/menu/paul.gif")) == NULL){
00088 cerr << "Couldn't load tile data/menu/paul.gif: " << SDL_GetError() << endl;
00089 return;
00090 }
00091 if(MENU_DEBUG) printf("loading menu data .5\n");
00092 SDL_SetColorKey(char_image, (SDL_SRCCOLORKEY|SDL_RLEACCEL),
00093 *((Uint8 *)char_image->pixels));
00094 choice_rects[0] = makerect(300, 50, menu_choices[0][1]->w, menu_choices[0][1]->h);
00095 choice_rects[1] = makerect(300, 150, menu_choices[1][1]->w, menu_choices[1][1]->h);
00096 choice_rects[2] = makerect(300, 250, menu_choices[2][1]->w, menu_choices[2][1]->h);
00097 sound->load_bgm(bgm);
00098
00099
00100
00101 if(MENU_DEBUG) cerr << "loading menu data Done!\n";
00102 }
00103
00104 int Menu::run(){
00105 if(MENU_DEBUG) cerr << "Menu::run\n";
00106 int done_flag = 0;
00107 load_menu_data();
00108 screen.blank(makerect(0,0,screen.get_width(), screen.get_height()));
00109 screen.blankblit(menu_choices[0][1], choice_rects[0]);
00110
00111 screen.blankblit(menu_choices[1][0], choice_rects[1]);
00112 screen.blankblit(menu_choices[2][0], choice_rects[2]);
00113 screen.blankblit(title, makerect(25,50,title->w, title->h));
00114 screen.blankblit(char_image, makerect(25, 175, char_image->w, char_image->h));
00115 screen.write("Copyright 2000. David Foster", 40, 20, 0xFF00, 1);
00116 screen.update_screen();
00117 SDL_EventState(SDL_KEYUP, SDL_IGNORE);
00118 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
00119 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
00120 SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
00121 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
00122 sound->play_bgm();
00123 current_selection = 0;
00124
00125 while(!done_flag){
00126 if(SDL_PollEvent(&event)){
00127 switch(event.type){
00128 case SDL_KEYDOWN:
00129
00130 if(!strcmp(SDL_GetKeyName(event.key.keysym.sym),"down")){
00131
00132 if(current_selection != (num_menu_choices - 1)){
00133 current_selection++;
00134 }
00135 screen.blankblit(menu_choices[0][0], choice_rects[0]);
00136 screen.blankblit(menu_choices[1][0], choice_rects[1]);
00137 screen.blankblit(menu_choices[2][0], choice_rects[2]);
00138 screen.update_screen();
00139 sound->play_sample_name(sfx);
00140 }
00141 if(!strcmp(SDL_GetKeyName(event.key.keysym.sym), "up")){
00142
00143 if(current_selection != 0){
00144 current_selection--;
00145 }
00146 screen.blankblit(menu_choices[0][0], choice_rects[0]);
00147 screen.blankblit(menu_choices[1][0], choice_rects[1]);
00148 screen.blankblit(menu_choices[2][0], choice_rects[2]);
00149 screen.update_screen();
00150 sound->play_sample_name(sfx);
00151 }
00152 if(!strcmp(SDL_GetKeyName(event.key.keysym.sym), "return")){
00153
00154 done_flag = 1;
00155 }
00156 if(!strcmp(SDL_GetKeyName(event.key.keysym.sym), "escape")){
00157
00158 exit(0);
00159 }
00160 break;
00161 case SDL_QUIT:
00162 exit(0);
00163 break;
00164 default:
00165 break;
00166 }
00167 }
00168
00169 SDL_SetAlpha(menu_choices[current_selection][1], SDL_SRCALPHA, current_alpha);
00170 screen.blankblit(menu_choices[current_selection][1], choice_rects[current_selection]);
00171 if(alpha_direction == 1){
00172 current_alpha += 10;
00173 if(current_alpha > 245){
00174 current_alpha -= 10;
00175 alpha_direction = 0;
00176 }
00177 }else{
00178 current_alpha -= 10;
00179 if(current_alpha < 150){
00180 current_alpha += 10;
00181 alpha_direction = 1;
00182 }
00183 }
00184
00185 screen.update_rect(choice_rects[current_selection]);
00186 SDL_Delay(40);
00187 }
00188 sound->stop_all();
00189
00190 return(current_selection);
00191 }
00192
00193 void Menu::play_menu_music(){
00194
00195 }
00196
00197
00198