diff --git a/README.md b/README.md index 9189464..f4df062 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ A ce stade, on a déjà implémenté : - [ ] Fontes de caractères - [ ] Interaction - [ ] NPC -- [ ] Changement de map durant le jeu (en cours) +- [x] Changement de map durant le jeu ## Crédits @@ -28,4 +28,4 @@ Les tiles sont issues de Game Boy Top-down RPG Fantasy Tileset (FREE) Converties en niveau de gris avec Gimp Une version 1-bit (N&B) à été réalisée par Shadow15510 -Et une version couleur CG à été réalisée par Fcalva +Et une version couleur CG (palette EGA64) à été réalisée par Fcalva diff --git a/src/main.c b/src/main.c index 3d8cfd4..7a84413 100644 --- a/src/main.c +++ b/src/main.c @@ -32,11 +32,11 @@ extern Map *worldRPG[]; /* Game data (defined in "game.h")*/ Game game = { NULL, - {10*PXSIZE, 48*PXSIZE, 0, 0, 10*PXSIZE, 48*PXSIZE, 100, SPEED}, + {12*PXSIZE, 36*PXSIZE, 0, 0, 10*PXSIZE, 48*PXSIZE, 100, SPEED}, false, false, false, 0 /* debug variables*/ - , false, true + , false, false }; /* screen capture management code */ @@ -108,13 +108,13 @@ int main(void) { dgray(DGRAY_ON); #endif - +/* showtext_dialog(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, true); int in = showtext_dialog_ask(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, false, "Lorem\0Ipsum\0Dolor", 3, 0); if(in==2) showtext_dialog(&game, &player_face_img, "You choosed Dolor", false, true); else if(in==1) showtext_dialog(&game, &player_face_img, "You choosed Ipsum", false, true); else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true); - +*/ do{ /* clear screen */ diff --git a/src/player.c b/src/player.c index d495c1b..3cb1efc 100644 --- a/src/player.c +++ b/src/player.c @@ -115,6 +115,12 @@ bool player_collision(Game *game, Direction direction, Map *map = get_map_for_coordinates(game, worldX, worldY ); if (map!=NULL && map!=game->map_level) { + Map *backupmap = game->map_level; + int backupx = player->x; + int backupy = player->y; + int backupwx = player->wx; + int backupwy = player->wy; + game->map_level = map; player->wx = worldX * PXSIZE; @@ -123,6 +129,24 @@ bool player_collision(Game *game, Direction direction, player->x = (worldX - map->xmin ) * PXSIZE; player->y = (worldY - map->ymin ) * PXSIZE; + int on_walkable = get_walkable(game, player->x/T_WIDTH, + player->y/T_HEIGHT); + + int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX) ? + walkable_speed[on_walkable] : 0; + + /* if he's on a hard tile and we need to revert the changes as */ + /* tile on the next side of the border is not walkable */ + + if(!speed){ + game->map_level = backupmap; + player->x = backupx; + player->y = backupy; + player->wx = backupwx; + player->wy = backupwy; + return true; /* He will collide with it. */ + } + return false; } }