diff --git a/CMakeLists.txt b/CMakeLists.txt index 75b29b7..d36cab6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ find_package(Gint 2.9 REQUIRED) find_package(LibProf 2.4 REQUIRED) #set the color mode either to 1b or 2b -set(COLORMODE_fx 1b) +set(COLORMODE_fx 2b) #set the color mode either to 2b or EGA64 set(COLORMODE_cg EGA64) diff --git a/README.md b/README.md index ed58c27..311003c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ A ce stade, on a déjà implémenté : - [x] Personnage - [ ] Dialogues - [ ] Fontes de caractères -- [ ] Interraction +- [ ] Interaction - [ ] NPC - [ ] Changement de map diff --git a/src/dialogs.c b/src/dialogs.c index ed176de..bb2a3e1 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -34,12 +34,11 @@ void blit() } -void showtext(Game *game, bopti_image_t *face, char *text) { - - +int showtext_opt(Game *game, bopti_image_t *face, char *text, + int call_before_end(void), bool start_anim, bool end_anim) { dfont(&FONT_USED); unsigned int i, n, y = PXSIZE, l = 0; - int line_max_chars; + int line_max_chars, return_int = 0; unsigned int max_lines_amount = (BOX_HEIGHT-2)*PXSIZE/ (FONT_USED.line_height+PXSIZE); const char *c; @@ -52,7 +51,7 @@ void showtext(Game *game, bopti_image_t *face, char *text) { dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, (i-8)*PXSIZE, DIMAGE_NONE); - blit(); + dupdate(); while(game->frame_duration < 20) sleep(); game->frame_duration = 0; @@ -87,7 +86,6 @@ void showtext(Game *game, bopti_image_t *face, char *text) { */ /* Make a little animation :). */ blit(); - while(game->frame_duration < 1000) sleep(); game->frame_duration = 0; /* Ask the user to press EXE to continue. */ @@ -95,7 +93,6 @@ void showtext(Game *game, bopti_image_t *face, char *text) { } /* Make a little animation :). */ blit(); - if(l>=max_lines_amount-1){ while(getkey().key != KEY_EXE) sleep(); /* Clear the screen. */ @@ -114,13 +111,14 @@ void showtext(Game *game, bopti_image_t *face, char *text) { /* If we have not filled everthing with text at the end. */ /* Make a little animation :). */ blit(); - while(game->frame_duration < 1000) sleep(); game->frame_duration = 0; /* Ask the user to press EXE to continue. */ dtext(1, y, C_BLACK, "[EXE] To continue ..."); + blit(); while(getkey().key != KEY_EXE) sleep(); } + if(call_before_end) return_int = call_before_end(); /* Run another little fancy animation. */ for(i=40;i>0;i--){ draw(game); @@ -129,9 +127,32 @@ void showtext(Game *game, bopti_image_t *face, char *text) { dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, (i-8)*PXSIZE, DIMAGE_NONE); - blit(); + dupdate(); while(game->frame_duration < 20) sleep(); game->frame_duration = 0; } + return return_int; +} + +void showtext(Game *game, bopti_image_t *face, char *text) { + showtext_opt(game, face, text, NULL, true, true); +} + +void showtext_dialog_start(Game *game, bopti_image_t *face, char *text) { + showtext_opt(game, face, text, NULL, true, false); +} + +void showtext_dialog_mid(Game *game, bopti_image_t *face, char *text) { + showtext_opt(game, face, text, NULL, false, false); +} + +void showtext_dialog_end(Game *game, bopti_image_t *face, char *text) { + showtext_opt(game, face, text, NULL, false, true); +} + +char **choices; + +void _choice_call_before_end(void) { + // } diff --git a/src/dialogs.h b/src/dialogs.h index 92cc96c..62c9a6e 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -9,6 +9,15 @@ #define F_WIDTH (32*PXSIZE) #define F_HEIGHT (32*PXSIZE) +int showtext_opt(Game *game, bopti_image_t *face, char *text, + int call_before_end(void), bool start_anim, bool end_anim); + void showtext(Game *game, bopti_image_t *face, char *text); +void showtext_dialog_start(Game *game, bopti_image_t *face, char *text); + +void showtext_dialog_mid(Game *game, bopti_image_t *face, char *text); + +void showtext_dialog_end(Game *game, bopti_image_t *face, char *text); + #endif diff --git a/src/map.c b/src/map.c index e80fe10..361e592 100644 --- a/src/map.c +++ b/src/map.c @@ -26,6 +26,8 @@ void render_map(Player *player, Map *map_level) { unsigned short int xtile, ytile; /* The layer we're drawing */ unsigned char l; + /* The index of the current tile we're drawing in the layer. */ + int current_index; /* Fix sx. */ if(player->xnblayers-1; l++){ /* Draw a layer of the map on screen. */ for(y=0;y=0 && tx+x < map_level->w && ty+y>=0 && ty+y < map_level->h){ /* index of the current tile */ - int currentIndex = (y+ty) * map_level->w + tx+x; + current_index = (y+ty) * map_level->w + tx+x; /* we get the ID of the tile in the current drawable layers */ - tile = map_level->layers[l][currentIndex]; + tile = map_level->layers[l][current_index]; /* tile == -1 means nothing to be drawn */ if(tile >= 0){ @@ -115,8 +116,6 @@ void render_map_by_layer(Player *player, Map *map_level, int layer) { unsigned short int sx, sy; /* The position of the tile in the tileset. */ unsigned short int xtile, ytile; - /* The layer we're drawing */ - unsigned char l; /* Fix sx. */ if(player->x=0 && tx+x < map_level->w && - ty+y>=0 && ty+y < map_level->h){ - /* index of the current tile */ - int currentIndex = (y+ty) * map_level->w + tx+x; - /* we get the ID of the tile in the current drawable layers - */ - tile = map_level->layers[layer][currentIndex]; - - /* tile == -1 means nothing to be drawn */ - if(tile >= 0){ - /* get x and y position in the tileset image */ - xtile = (tile % map_level->tileset_size) * T_WIDTH; - ytile = (tile / map_level->tileset_size) * T_HEIGHT; - /* render */ - dsubimage(x*T_WIDTH-mx, y*T_HEIGHT-my, - map_level->tileset, xtile, ytile, T_WIDTH, - T_HEIGHT, DIMAGE_NONE); - } + /* Draw a layer of the map on screen. */ + for(y=0;y=0 && tx+x < map_level->w && + ty+y>=0 && ty+y < map_level->h){ + /* index of the current tile */ + int currentIndex = (y+ty) * map_level->w + tx+x; + /* we get the ID of the tile in the current drawable layers + */ + tile = map_level->layers[layer][currentIndex]; + + /* tile == -1 means nothing to be drawn */ + if(tile >= 0){ + /* get x and y position in the tileset image */ + xtile = (tile % map_level->tileset_size) * T_WIDTH; + ytile = (tile / map_level->tileset_size) * T_HEIGHT; + /* render */ + dsubimage(x*T_WIDTH-mx, y*T_HEIGHT-my, + map_level->tileset, xtile, ytile, T_WIDTH, + T_HEIGHT, DIMAGE_NONE); } } } + } } diff --git a/src/map.h b/src/map.h index be18c01..37d3eef 100644 --- a/src/map.h +++ b/src/map.h @@ -28,7 +28,8 @@ /* Draws the map map on the entire screen to be viewed by the player player. */ void render_map(Player *player, Map *map_level); -/* Draws the map layer on the entire screen to be viewed by the player player. */ +/* Draws the map layer on the entire screen to be viewed by the player player. + */ void render_map_by_layer(Player *player, Map *map_level, int layer); /* Get the tile at (x, y) of the map map. If the tile is located outside of the @@ -39,4 +40,3 @@ short int get_tile(Map *map_level, int x, int y, int l); short int get_walkable(Map *map_level, int x, int y); #endif -