mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +01:00
added a verification on walkability of the target tile on next map
This commit is contained in:
parent
f895171e40
commit
217221cd6c
3 changed files with 30 additions and 6 deletions
|
@ -17,7 +17,7 @@ A ce stade, on a déjà implémenté :
|
||||||
- [ ] Fontes de caractères
|
- [ ] Fontes de caractères
|
||||||
- [ ] Interaction
|
- [ ] Interaction
|
||||||
- [ ] NPC
|
- [ ] NPC
|
||||||
- [ ] Changement de map durant le jeu (en cours)
|
- [x] Changement de map durant le jeu
|
||||||
|
|
||||||
## Crédits
|
## 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
|
Converties en niveau de gris avec Gimp
|
||||||
|
|
||||||
Une version 1-bit (N&B) à été réalisée par Shadow15510
|
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
|
||||||
|
|
|
@ -32,11 +32,11 @@ extern Map *worldRPG[];
|
||||||
/* Game data (defined in "game.h")*/
|
/* Game data (defined in "game.h")*/
|
||||||
Game game = {
|
Game game = {
|
||||||
NULL,
|
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
|
false, false, false, 0
|
||||||
|
|
||||||
/* debug variables*/
|
/* debug variables*/
|
||||||
, false, true
|
, false, false
|
||||||
};
|
};
|
||||||
|
|
||||||
/* screen capture management code */
|
/* screen capture management code */
|
||||||
|
@ -108,13 +108,13 @@ int main(void) {
|
||||||
dgray(DGRAY_ON);
|
dgray(DGRAY_ON);
|
||||||
#endif
|
#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);
|
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);
|
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);
|
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 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);
|
else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true);
|
||||||
|
*/
|
||||||
|
|
||||||
do{
|
do{
|
||||||
/* clear screen */
|
/* clear screen */
|
||||||
|
|
24
src/player.c
24
src/player.c
|
@ -115,6 +115,12 @@ bool player_collision(Game *game, Direction direction,
|
||||||
Map *map = get_map_for_coordinates(game, worldX, worldY );
|
Map *map = get_map_for_coordinates(game, worldX, worldY );
|
||||||
if (map!=NULL && map!=game->map_level)
|
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;
|
game->map_level = map;
|
||||||
|
|
||||||
player->wx = worldX * PXSIZE;
|
player->wx = worldX * PXSIZE;
|
||||||
|
@ -123,6 +129,24 @@ bool player_collision(Game *game, Direction direction,
|
||||||
player->x = (worldX - map->xmin ) * PXSIZE;
|
player->x = (worldX - map->xmin ) * PXSIZE;
|
||||||
player->y = (worldY - map->ymin ) * 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue