Index: game.c ================================================================== --- game.c +++ game.c @@ -64,19 +64,30 @@ draw_text(8,32,buf,0xF0,0xFD); draw_text(24,32,"x",0xF0,0xF5); SDL_UnlockSurface(screen); SDL_Flip(screen); } + +static void begin_level(int id) { + const char*t; + t=load_level(id)?:init_level(); + if(t) { + gameover=-1; + screen_message(t); + } else { + gameover=0; + } +} static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) { switch(cmd) { case '\' ': // Play a move return number; case '^E': // Edit return -2; case '^L': // Select level - load_level(number); + begin_level(number); return 1; case '^Q': // Quit return -1; default: return prev; @@ -104,11 +115,11 @@ void run_game(void) { int i; SDL_Event ev; set_caption(); - load_level(level_id); + begin_level(level_id); redraw_game(); while(SDL_WaitEvent(&ev)) { switch(ev.type) { case SDL_VIDEOEXPOSE: redraw_game(); Index: heromesh.h ================================================================== --- heromesh.h +++ heromesh.h @@ -87,10 +87,11 @@ void draw_picture(int x,int y,Uint16 img); void draw_text(int x,int y,const unsigned char*t,int bg,int fg); void draw_cell(int x,int y); const char*screen_prompt(const char*txt); +int screen_message(const char*txt); void load_pictures(void); int scrollbar(int*cur,int page,int max,SDL_Event*ev,SDL_Rect*re); // == class == Index: picture.c ================================================================== --- picture.c +++ picture.c @@ -197,31 +197,46 @@ draw_text(n<<3,8,"\xB1",0xF1,0xFB); SDL_UnlockSurface(screen); SDL_Flip(screen); } } + return 0; } -void screen_message(const char*txt) { - SDL_Rect r; +int screen_message(const char*txt) { + int n=0; + SDL_Rect r={0,0,screen->w,16}; SDL_Event ev; - + SDL_FillRect(screen,&r,0xF4); + r.y=16; + r.h=1; + SDL_FillRect(screen,&r,0xF8); + SDL_LockSurface(screen); + draw_text(0,0,txt,0xF4,0xFE); + draw_text(0,8,"",0xF4,0xF7); + SDL_UnlockSurface(screen); set_cursor(XC_iron_cross); SDL_Flip(screen); + r.y=8; + r.h=8; while(SDL_WaitEvent(&ev)) { switch(ev.type) { case SDL_QUIT: SDL_PushEvent(&ev); - return; + return -1; case SDL_KEYDOWN: - - return; - case SDL_MOUSEBUTTONDOWN: - - return; + switch(ev.key.keysym.sym) { + case SDLK_RETURN: case SDLK_KP_ENTER: + r.y=0; + r.h=17; + SDL_FillRect(screen,&r,0xF0); + return 0; + } + break; } } + return -1; } static Uint16 decide_picture_size(int nwantsize,const Uint8*wantsize,const Uint16*havesize,int n) { int i,j; if(!nwantsize) fatal("Unable to determine what picture size is wanted\n");