mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +01:00
implementation of map change during gameplay by crossing map borders
This commit is contained in:
parent
272d60b0aa
commit
cb24bee3f8
3 changed files with 34 additions and 8 deletions
|
@ -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, 0, 0, 100, SPEED},
|
{10*PXSIZE, 48*PXSIZE, 0, 0, 10*PXSIZE, 48*PXSIZE, 100, SPEED},
|
||||||
false, false, false, 0
|
false, false, false, 0
|
||||||
|
|
||||||
/* debug variables*/
|
/* debug variables*/
|
||||||
, false, false
|
, false, true
|
||||||
};
|
};
|
||||||
|
|
||||||
/* screen capture management code */
|
/* screen capture management code */
|
||||||
|
@ -93,7 +93,7 @@ int main(void) {
|
||||||
}
|
}
|
||||||
timer_start(timer);
|
timer_start(timer);
|
||||||
|
|
||||||
game.map_level = worldRPG[2];
|
game.map_level = worldRPG[0];
|
||||||
|
|
||||||
|
|
||||||
#if USB_FEATURE
|
#if USB_FEATURE
|
||||||
|
|
|
@ -199,7 +199,7 @@ short int get_tile(Game *game, int x, int y, int l) {
|
||||||
|
|
||||||
/* Get the tile at (x, y) on layer l. Returns the tile ID or MAP_OUTSIDE if
|
/* Get the tile at (x, y) on layer l. Returns the tile ID or MAP_OUTSIDE if
|
||||||
* she's not found. */
|
* she's not found. */
|
||||||
return x>=0 && x < map_level->w && y>=0 && y < map_level->h ?
|
return (x>=0 && x < map_level->w && y>=0 && y < map_level->h) ?
|
||||||
map_level->layers[l][y * map_level->w + x] : MAP_OUTSIDE;
|
map_level->layers[l][y * map_level->w + x] : MAP_OUTSIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ short int get_walkable(Game *game, int x, int y) {
|
||||||
Map *map_level = game->map_level;
|
Map *map_level = game->map_level;
|
||||||
/* Get the tile at (x, y). Returns the tile ID or MAP_OUTSIDE if she's not
|
/* Get the tile at (x, y). Returns the tile ID or MAP_OUTSIDE if she's not
|
||||||
* found. */
|
* found. */
|
||||||
return x>=0 && x < map_level->w && y>=0 && y < map_level->h ?
|
return (x>=0 && x < map_level->w && y>=0 && y < map_level->h) ?
|
||||||
map_level->walkable[y * map_level->w + x] : MAP_OUTSIDE;
|
map_level->walkable[y * map_level->w + x] : MAP_OUTSIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ Map *get_map_for_coordinates( Game *game, int x, int y )
|
||||||
i++;
|
i++;
|
||||||
current = worldRPG[i];
|
current = worldRPG[i];
|
||||||
}
|
}
|
||||||
while (current!=NULL)
|
while (current!=NULL);
|
||||||
|
|
||||||
/* else we return NULL cause the point is a not within a map */
|
/* else we return NULL cause the point is a not within a map */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
30
src/player.c
30
src/player.c
|
@ -41,6 +41,7 @@ void player_move(Game *game, Direction direction) {
|
||||||
|
|
||||||
/* If the player will collide with a hard tile or if the will go outside of
|
/* If the player will collide with a hard tile or if the will go outside of
|
||||||
* the map. */
|
* the map. */
|
||||||
|
|
||||||
if(player_collision(game, direction, P_CENTER)){
|
if(player_collision(game, direction, P_CENTER)){
|
||||||
|
|
||||||
/* If the will collide with the center of the player. */
|
/* If the will collide with the center of the player. */
|
||||||
|
@ -102,7 +103,32 @@ bool player_collision(Game *game, Direction direction,
|
||||||
int player_tile_x = player->x+dx;
|
int player_tile_x = player->x+dx;
|
||||||
int player_tile_y = player->y+dy;
|
int player_tile_y = player->y+dy;
|
||||||
|
|
||||||
/* Handle a negative position diffrently than a positive one. */
|
/* check where the player is expected to go on the next move */
|
||||||
|
/* if outside the map, we check if there is a map on the other */
|
||||||
|
/* side of the current map*/
|
||||||
|
if (get_walkable(game, player_tile_x, player_tile_y) == MAP_OUTSIDE)
|
||||||
|
{
|
||||||
|
// we compute the expected world coordinates accordingly
|
||||||
|
// while taking care of the scaling between fx and cg models (PXSIZE)
|
||||||
|
int worldX = (player->wx+dx) / PXSIZE;
|
||||||
|
int worldY = (player->wy+dy) / PXSIZE;
|
||||||
|
Map *map = get_map_for_coordinates(game, worldX, worldY );
|
||||||
|
if (map!=NULL && map!=game->map_level)
|
||||||
|
{
|
||||||
|
game->map_level = map;
|
||||||
|
|
||||||
|
player->wx = worldX * PXSIZE;
|
||||||
|
player->wy = worldY * PXSIZE;
|
||||||
|
|
||||||
|
player->x = (worldX - map->xmin ) * PXSIZE;
|
||||||
|
player->y = (worldY - map->ymin ) * PXSIZE;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Handle a negative position differently than a positive one. */
|
||||||
if(player_tile_x < 0) player_tile_x = player_tile_x/T_WIDTH-1;
|
if(player_tile_x < 0) player_tile_x = player_tile_x/T_WIDTH-1;
|
||||||
else player_tile_x = player_tile_x/T_WIDTH;
|
else player_tile_x = player_tile_x/T_WIDTH;
|
||||||
|
|
||||||
|
@ -111,7 +137,7 @@ bool player_collision(Game *game, Direction direction,
|
||||||
|
|
||||||
int on_walkable = get_walkable(game, player_tile_x, player_tile_y);
|
int on_walkable = get_walkable(game, player_tile_x, player_tile_y);
|
||||||
|
|
||||||
int speed = on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX ?
|
int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX) ?
|
||||||
walkable_speed[on_walkable] : 0;
|
walkable_speed[on_walkable] : 0;
|
||||||
|
|
||||||
/* if he's on a hard tile */
|
/* if he's on a hard tile */
|
||||||
|
|
Loading…
Reference in a new issue