diff options
-rw-r--r-- | src/defs.h | 5 | ||||
-rw-r--r-- | src/player.c | 48 |
2 files changed, 43 insertions, 10 deletions
@@ -44,6 +44,7 @@ #define MF_PLAYER_SPEED 2 #define MF_PLAYER_TURN_TIME 15 +#define MF_PLAYER_P 2 /* Colors */ #define MF_COLOR_BACK_R 0xAF /* Background color */ @@ -75,8 +76,8 @@ #define MF_COLOR_CHKM_B 0x00 #define MF_COLOR_CHKM_A 0xFF #define MF_COLOR_PLYR_R 0x00 /* Player color */ -#define MF_COLOR_PLYR_G 0x00 -#define MF_COLOR_PLYR_B 0x00 +#define MF_COLOR_PLYR_G 0xAF +#define MF_COLOR_PLYR_B 0x7F #define MF_COLOR_PLYR_A 0xFF #endif /* MF_DEFS_H_ */ diff --git a/src/player.c b/src/player.c index 99fe45f..9ababd4 100644 --- a/src/player.c +++ b/src/player.c @@ -173,8 +173,13 @@ mf_player_update(struct mf_player *p) int mf_player_render(struct mf_player *p, SDL_Renderer *renderer) { + int e = 0; + int cx; + int cy; + int r; int x; int y; + int i; if (SDL_SetRenderDrawColor(renderer, MF_COLOR_PLYR_R, MF_COLOR_PLYR_G, @@ -182,19 +187,46 @@ mf_player_render(struct mf_player *p, SDL_Renderer *renderer) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't render player: %s", SDL_GetError()); - return -1; + e = -1; } - x = p->cur_x * p->cell_width + p->cell_width / 2; - y = p->cur_y * p->cell_width + p->cell_width / 2; + cx = p->cur_x * p->cell_width + p->cell_width / 2; + cy = p->cur_y * p->cell_width + p->cell_width / 2; switch (p->cur_dir) { - case MF_PLAYER_DIR_U_: y -= p->travel; break; - case MF_PLAYER_DIR_D_: y += p->travel; break; - case MF_PLAYER_DIR_L_: x -= p->travel; break; - case MF_PLAYER_DIR_R_: x += p->travel; break; + case MF_PLAYER_DIR_U_: cy -= p->travel; break; + case MF_PLAYER_DIR_D_: cy += p->travel; break; + case MF_PLAYER_DIR_L_: cx -= p->travel; break; + case MF_PLAYER_DIR_R_: cx += p->travel; break; default: break; } - return SDL_RenderDrawPoint(renderer, x, y); + r = p->cell_width / 2 - MF_PLAYER_P; + +#define _mf_player_px(X, Y) \ + do { \ + if (SDL_RenderDrawPoint(renderer, cx + X, cy + Y) < 0) { \ + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \ + "Couldn't render widget: %s", \ + SDL_GetError()); \ + e = -1; \ + } \ + } while (0) + + /* TODO: This is one pixel larger than it should be. */ + for (x = 0, y = r; y > x; ++x) { + y = round(sqrt((r-0.5)*(r-0.5) - (x-0.5)*(x-0.5)) + 0.5); + for (i = 0; i <= y; ++i) _mf_player_px( x, i); + for (i = 0; i >= 0-y; --i) _mf_player_px( x, i); + for (i = 0; i <= y; ++i) _mf_player_px(0-x, i); + for (i = 0; i >= 0-y; --i) _mf_player_px(0-x, i); + for (i = 0; i <= y; ++i) _mf_player_px( i, x); + for (i = 0; i <= y; ++i) _mf_player_px( i, 0-x); + for (i = 0; i >= 0-y; --i) _mf_player_px( i, x); + for (i = 0; i >= 0-y; --i) _mf_player_px( i, 0-x); + } + +#undef _mf_player_px + + return e; } void |