added a verification on walkability of the target tile on next map

This commit is contained in:
SlyVTT 2023-08-14 21:15:38 +02:00
parent f895171e40
commit 217221cd6c
3 changed files with 30 additions and 6 deletions

View file

@ -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

View file

@ -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 */

View file

@ -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;
}
}