mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-28 04:23:42 +01:00
Small improvement
This commit is contained in:
parent
2ca939430d
commit
5eb1d18ea7
7 changed files with 75 additions and 77 deletions
|
@ -2,7 +2,6 @@ BasedOnStyle: LLVM
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
PointerAlignment: Right
|
PointerAlignment: Right
|
||||||
SpaceBeforeAssignmentOperators: true
|
SpaceBeforeAssignmentOperators: true
|
||||||
BreakBeforeBinaryOperators: true
|
|
||||||
SpaceBeforeRangeBasedForLoopColon: false
|
SpaceBeforeRangeBasedForLoopColon: false
|
||||||
SpaceInEmptyBlock: false
|
SpaceInEmptyBlock: false
|
||||||
SpaceInEmptyParentheses: false
|
SpaceInEmptyParentheses: false
|
||||||
|
@ -10,3 +9,4 @@ SpaceBeforeParens: Never
|
||||||
IndentCaseBlocks: true
|
IndentCaseBlocks: true
|
||||||
IncludeBlocks: Regroup
|
IncludeBlocks: Regroup
|
||||||
AllowShortBlocksOnASingleLine: Empty
|
AllowShortBlocksOnASingleLine: Empty
|
||||||
|
ColumnLimit: 80
|
||||||
|
|
|
@ -45,8 +45,8 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text,
|
||||||
dfont(&FONT_USED);
|
dfont(&FONT_USED);
|
||||||
unsigned int i, n, y = PXSIZE, l = 0;
|
unsigned int i, n, y = PXSIZE, l = 0;
|
||||||
int line_max_chars, return_int = 0;
|
int line_max_chars, return_int = 0;
|
||||||
unsigned int max_lines_amount
|
unsigned int max_lines_amount =
|
||||||
= (BOX_HEIGHT - 2) * PXSIZE / (FONT_USED.line_height + PXSIZE);
|
(BOX_HEIGHT - 2) * PXSIZE / (FONT_USED.line_height + PXSIZE);
|
||||||
const char *c;
|
const char *c;
|
||||||
if(start_anim) {
|
if(start_anim) {
|
||||||
/* Run a little fancy animation. */
|
/* Run a little fancy animation. */
|
||||||
|
@ -145,11 +145,10 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text,
|
||||||
/* If we drew one entire screen. */
|
/* If we drew one entire screen. */
|
||||||
/* Wait that the SHIFT key is pressed if we should. */
|
/* Wait that the SHIFT key is pressed if we should. */
|
||||||
if(wait_continue) {
|
if(wait_continue) {
|
||||||
while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT
|
while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT &
|
||||||
& ~GETKEY_MOD_ALPHA,
|
~GETKEY_MOD_ALPHA,
|
||||||
NULL)
|
NULL)
|
||||||
.key
|
.key != KEY_SHIFT) {
|
||||||
!= KEY_SHIFT) {
|
|
||||||
sleep();
|
sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,11 +179,10 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text,
|
||||||
if(update_screen)
|
if(update_screen)
|
||||||
blit();
|
blit();
|
||||||
if(wait_continue) {
|
if(wait_continue) {
|
||||||
while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT
|
while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT &
|
||||||
& ~GETKEY_MOD_ALPHA,
|
~GETKEY_MOD_ALPHA,
|
||||||
NULL)
|
NULL)
|
||||||
.key
|
.key != KEY_SHIFT) {
|
||||||
!= KEY_SHIFT) {
|
|
||||||
sleep();
|
sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ int _op_mod(int a, int b) {
|
||||||
return a % b;
|
return a % b;
|
||||||
}
|
}
|
||||||
|
|
||||||
int (*_operations[OP_AMOUNT])(int, int)
|
int (*_operations[OP_AMOUNT])(int, int) = {_op_null, _op_set, _op_add, _op_sub,
|
||||||
= {_op_null, _op_set, _op_add, _op_sub, _op_div, _op_mul, _op_mod};
|
_op_div, _op_mul, _op_mod};
|
||||||
|
|
||||||
#define MIN(a, b) a < b ? a : b
|
#define MIN(a, b) a < b ? a : b
|
||||||
|
|
||||||
|
|
24
src/game.c
24
src/game.c
|
@ -26,13 +26,13 @@ void game_logic(Game *game) {
|
||||||
for(uint32_t i = 0; i < game->map_level->nbextradata; i++) {
|
for(uint32_t i = 0; i < game->map_level->nbextradata; i++) {
|
||||||
/* simple distance check along X and Y axis */
|
/* simple distance check along X and Y axis */
|
||||||
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
||||||
if((abs((int)game->player.wx
|
if((abs((int)game->player.wx -
|
||||||
- (int)game->map_level->extradata[i].x * PXSIZE)
|
(int)game->map_level->extradata[i].x * PXSIZE) <
|
||||||
< MAX_INTERACTION_DISTANCE * PXSIZE)
|
MAX_INTERACTION_DISTANCE * PXSIZE) &&
|
||||||
&& (abs((int)game->player.wy
|
(abs((int)game->player.wy -
|
||||||
- (int)game->map_level->extradata[i].y * PXSIZE)
|
(int)game->map_level->extradata[i].y * PXSIZE) <
|
||||||
< MAX_INTERACTION_DISTANCE * PXSIZE)
|
MAX_INTERACTION_DISTANCE * PXSIZE) &&
|
||||||
&& strcmp(game->map_level->extradata[i].type, "NPC") != 0) {
|
strcmp(game->map_level->extradata[i].type, "NPC") != 0) {
|
||||||
/* the player can do something */
|
/* the player can do something */
|
||||||
game->player.canDoSomething = true;
|
game->player.canDoSomething = true;
|
||||||
/* we mark the action for futur treatment in player_action() */
|
/* we mark the action for futur treatment in player_action() */
|
||||||
|
@ -46,11 +46,11 @@ void game_logic(Game *game) {
|
||||||
for(uint32_t i = 0; i < nbNPC; i++) {
|
for(uint32_t i = 0; i < nbNPC; i++) {
|
||||||
/* simple distance check along X and Y axis */
|
/* simple distance check along X and Y axis */
|
||||||
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
||||||
if((abs((int)game->player.wx - (int)npcRPG[i].curx * PXSIZE)
|
if((abs((int)game->player.wx - (int)npcRPG[i].curx * PXSIZE) <
|
||||||
< MAX_INTERACTION_DISTANCE * PXSIZE)
|
MAX_INTERACTION_DISTANCE * PXSIZE) &&
|
||||||
&& (abs((int)game->player.wy - (int)npcRPG[i].cury * PXSIZE)
|
(abs((int)game->player.wy - (int)npcRPG[i].cury * PXSIZE) <
|
||||||
< MAX_INTERACTION_DISTANCE * PXSIZE)
|
MAX_INTERACTION_DISTANCE * PXSIZE) &&
|
||||||
&& strcmp(game->map_level->extradata[i].type, "NPC") != 0) {
|
strcmp(game->map_level->extradata[i].type, "NPC") != 0) {
|
||||||
/* the player can do something */
|
/* the player can do something */
|
||||||
game->player.canDoSomething = true;
|
game->player.canDoSomething = true;
|
||||||
/* we mark the action for futur treatment in player_action() */
|
/* we mark the action for futur treatment in player_action() */
|
||||||
|
|
16
src/map.c
16
src/map.c
|
@ -81,8 +81,8 @@ void map_render(Game *game) {
|
||||||
for(x = 0; x < dw; x++) {
|
for(x = 0; x < dw; x++) {
|
||||||
/* I get the tile number if his position is inside the map. Then
|
/* I get the tile number if his position is inside the map. Then
|
||||||
* I draw it. */
|
* I draw it. */
|
||||||
if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0
|
if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0 &&
|
||||||
&& ty + y < map_level->h) {
|
ty + y < map_level->h) {
|
||||||
/* index of the current tile */
|
/* index of the current tile */
|
||||||
current_index = (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
|
/* we get the ID of the tile in the current drawable layers
|
||||||
|
@ -173,8 +173,8 @@ void map_render_by_layer(Game *game, int layer) {
|
||||||
for(x = 0; x < dw; x++) {
|
for(x = 0; x < dw; x++) {
|
||||||
/* I get the tile number if his position is inside the map. Then
|
/* I get the tile number if his position is inside the map. Then
|
||||||
* I draw it. */
|
* I draw it. */
|
||||||
if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0
|
if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0 &&
|
||||||
&& ty + y < map_level->h) {
|
ty + y < map_level->h) {
|
||||||
/* index of the current tile */
|
/* index of the current tile */
|
||||||
int currentIndex = (y + ty) * map_level->w + tx + x;
|
int currentIndex = (y + ty) * map_level->w + tx + x;
|
||||||
/* we get the ID of the tile in the current drawable layers
|
/* we get the ID of the tile in the current drawable layers
|
||||||
|
@ -220,8 +220,8 @@ short int map_get_walkable(Game *game, int x, int y) {
|
||||||
/* return the pointer to the map containing the given position */
|
/* return the pointer to the map containing the given position */
|
||||||
Map *map_get_for_coordinates(Game *game, int x, int y) {
|
Map *map_get_for_coordinates(Game *game, int x, int y) {
|
||||||
/* check if the current map contains the point */
|
/* check if the current map contains the point */
|
||||||
if(x >= (int)game->map_level->xmin && x < (int)game->map_level->xmax
|
if(x >= (int)game->map_level->xmin && x < (int)game->map_level->xmax &&
|
||||||
&& y >= (int)game->map_level->ymin && y < (int)game->map_level->ymax) {
|
y >= (int)game->map_level->ymin && y < (int)game->map_level->ymax) {
|
||||||
return game->map_level;
|
return game->map_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,8 +229,8 @@ Map *map_get_for_coordinates(Game *game, int x, int y) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Map *current = worldRPG[i];
|
Map *current = worldRPG[i];
|
||||||
do {
|
do {
|
||||||
if(x >= (int)current->xmin && x < (int)current->xmax
|
if(x >= (int)current->xmin && x < (int)current->xmax &&
|
||||||
&& y >= (int)current->ymin && y < (int)current->ymax)
|
y >= (int)current->ymin && y < (int)current->ymax)
|
||||||
return current;
|
return current;
|
||||||
i++;
|
i++;
|
||||||
current = worldRPG[i];
|
current = worldRPG[i];
|
||||||
|
|
72
src/npc.c
72
src/npc.c
|
@ -186,8 +186,8 @@ int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) {
|
||||||
if(att_score < gscore[j * w + i]) {
|
if(att_score < gscore[j * w + i]) {
|
||||||
came_from[j * w + i] = by * w + bx;
|
came_from[j * w + i] = by * w + bx;
|
||||||
gscore[j * w + i] = att_score;
|
gscore[j * w + i] = att_score;
|
||||||
fscore[j * w + i]
|
fscore[j * w + i] =
|
||||||
= att_score + round(length(dest_x - i, dest_y - j));
|
att_score + round(length(dest_x - i, dest_y - j));
|
||||||
if(visited[j * w + i])
|
if(visited[j * w + i])
|
||||||
visited[j * w + i] = 0;
|
visited[j * w + i] = 0;
|
||||||
}
|
}
|
||||||
|
@ -315,20 +315,20 @@ void npc_draw(Game *game) {
|
||||||
int NbPoints = Data->path_length + 1;
|
int NbPoints = Data->path_length + 1;
|
||||||
for(int v = 0; v < NbPoints; v++) {
|
for(int v = 0; v < NbPoints; v++) {
|
||||||
|
|
||||||
int16_t deltaX1
|
int16_t deltaX1 =
|
||||||
= ((int16_t)(Data->x + Data->xpath[v % NbPoints]) * PXSIZE)
|
((int16_t)(Data->x + Data->xpath[v % NbPoints]) * PXSIZE) -
|
||||||
- (int16_t)pl->wx;
|
(int16_t)pl->wx;
|
||||||
int16_t deltaY1
|
int16_t deltaY1 =
|
||||||
= ((int16_t)(Data->y + Data->ypath[v % NbPoints]) * PXSIZE)
|
((int16_t)(Data->y + Data->ypath[v % NbPoints]) * PXSIZE) -
|
||||||
- (int16_t)pl->wy;
|
(int16_t)pl->wy;
|
||||||
int16_t deltaX2
|
int16_t deltaX2 =
|
||||||
= ((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints])
|
((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints]) *
|
||||||
* PXSIZE)
|
PXSIZE) -
|
||||||
- (int16_t)pl->wx;
|
(int16_t)pl->wx;
|
||||||
int16_t deltaY2
|
int16_t deltaY2 =
|
||||||
= ((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints])
|
((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints]) *
|
||||||
* PXSIZE)
|
PXSIZE) -
|
||||||
- (int16_t)pl->wy;
|
(int16_t)pl->wy;
|
||||||
|
|
||||||
dline(pl->px + deltaX1, pl->py + deltaY1, pl->px + deltaX2,
|
dline(pl->px + deltaX1, pl->py + deltaY1, pl->px + deltaX2,
|
||||||
pl->py + deltaY2, PATH_COLOR);
|
pl->py + deltaY2, PATH_COLOR);
|
||||||
|
@ -369,23 +369,23 @@ void OLD_npc_draw(Game *game) {
|
||||||
int NbPoints = Data->path_length + 1;
|
int NbPoints = Data->path_length + 1;
|
||||||
for(int v = 0; v < NbPoints; v++) {
|
for(int v = 0; v < NbPoints; v++) {
|
||||||
|
|
||||||
int16_t deltaX1
|
int16_t deltaX1 =
|
||||||
= ((int16_t)(Data->x + Data->xpath[v % NbPoints])
|
((int16_t)(Data->x + Data->xpath[v % NbPoints]) *
|
||||||
* PXSIZE)
|
PXSIZE) -
|
||||||
- (int16_t)player->wx;
|
(int16_t)player->wx;
|
||||||
int16_t deltaY1
|
int16_t deltaY1 =
|
||||||
= ((int16_t)(Data->y + Data->ypath[v % NbPoints])
|
((int16_t)(Data->y + Data->ypath[v % NbPoints]) *
|
||||||
* PXSIZE)
|
PXSIZE) -
|
||||||
- (int16_t)player->wy;
|
(int16_t)player->wy;
|
||||||
|
|
||||||
int16_t deltaX2
|
int16_t deltaX2 =
|
||||||
= ((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints])
|
((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints]) *
|
||||||
* PXSIZE)
|
PXSIZE) -
|
||||||
- (int16_t)player->wx;
|
(int16_t)player->wx;
|
||||||
int16_t deltaY2
|
int16_t deltaY2 =
|
||||||
= ((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints])
|
((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints]) *
|
||||||
* PXSIZE)
|
PXSIZE) -
|
||||||
- (int16_t)player->wy;
|
(int16_t)player->wy;
|
||||||
|
|
||||||
dline(player->px + deltaX1, player->py + deltaY1,
|
dline(player->px + deltaX1, player->py + deltaY1,
|
||||||
player->px + deltaX2, player->py + deltaY2,
|
player->px + deltaX2, player->py + deltaY2,
|
||||||
|
@ -395,10 +395,10 @@ void OLD_npc_draw(Game *game) {
|
||||||
|
|
||||||
#endif // DEBUGMODE
|
#endif // DEBUGMODE
|
||||||
|
|
||||||
int16_t deltaX
|
int16_t deltaX =
|
||||||
= ((int16_t)(Data->x * PXSIZE)) - (int16_t)player->wx;
|
((int16_t)(Data->x * PXSIZE)) - (int16_t)player->wx;
|
||||||
int16_t deltaY
|
int16_t deltaY =
|
||||||
= ((int16_t)(Data->y * PXSIZE)) - (int16_t)player->wy;
|
((int16_t)(Data->y * PXSIZE)) - (int16_t)player->wy;
|
||||||
dimage(player->px - P_WIDTH / 2 + deltaX,
|
dimage(player->px - P_WIDTH / 2 + deltaX,
|
||||||
player->py - P_HEIGHT / 2 + deltaY, &tiny_npc_male);
|
player->py - P_HEIGHT / 2 + deltaY, &tiny_npc_male);
|
||||||
}
|
}
|
||||||
|
|
16
src/player.c
16
src/player.c
|
@ -67,8 +67,8 @@ void player_move(Game *game, Direction direction) {
|
||||||
|
|
||||||
player_fix_position(game, dx, dy);
|
player_fix_position(game, dx, dy);
|
||||||
} else {
|
} else {
|
||||||
if(player_collision(game, direction, P_RIGHTDOWN)
|
if(player_collision(game, direction, P_RIGHTDOWN) ||
|
||||||
|| player_collision(game, direction, P_LEFTUP)) {
|
player_collision(game, direction, P_LEFTUP)) {
|
||||||
|
|
||||||
/* If the will collide with the edges of the player. */
|
/* If the will collide with the edges of the player. */
|
||||||
/* I fix his position so he won't be partially in the tile. */
|
/* I fix his position so he won't be partially in the tile. */
|
||||||
|
@ -104,8 +104,8 @@ void player_action(Game *game) {
|
||||||
/* we indicate that the player is occupied */
|
/* we indicate that the player is occupied */
|
||||||
game->player.isDoingAction = true;
|
game->player.isDoingAction = true;
|
||||||
|
|
||||||
ExtraData *currentData
|
ExtraData *currentData =
|
||||||
= &game->map_level->extradata[game->player.whichAction];
|
&game->map_level->extradata[game->player.whichAction];
|
||||||
|
|
||||||
/* we use the correct image as per the class of the item */
|
/* we use the correct image as per the class of the item */
|
||||||
|
|
||||||
|
@ -137,8 +137,8 @@ void player_action(Game *game) {
|
||||||
|
|
||||||
/* when done we release the occupied status of the player */
|
/* when done we release the occupied status of the player */
|
||||||
game->player.isDoingAction = false;
|
game->player.isDoingAction = false;
|
||||||
} else if(game->player.canDoSomething
|
} else if(game->player.canDoSomething &&
|
||||||
&& game->player.isInteractingWithNPC) {
|
game->player.isInteractingWithNPC) {
|
||||||
/* we can do something (action IS with an NPC) */
|
/* we can do something (action IS with an NPC) */
|
||||||
/* we indicate that the player is occupied */
|
/* we indicate that the player is occupied */
|
||||||
game->player.isDoingAction = true;
|
game->player.isDoingAction = true;
|
||||||
|
@ -147,8 +147,8 @@ void player_action(Game *game) {
|
||||||
|
|
||||||
/* we use the correct image as per the class of the item */
|
/* we use the correct image as per the class of the item */
|
||||||
|
|
||||||
ExtraData *currentData
|
ExtraData *currentData =
|
||||||
= &game->map_level->extradata[game->player.whichAction];
|
&game->map_level->extradata[game->player.whichAction];
|
||||||
bopti_image_t *face = &npc_male;
|
bopti_image_t *face = &npc_male;
|
||||||
/* It's a NPC */
|
/* It's a NPC */
|
||||||
/* (Mibi88) TODO: Use string hash + strcmp if the hashes match for
|
/* (Mibi88) TODO: Use string hash + strcmp if the hashes match for
|
||||||
|
|
Loading…
Reference in a new issue