summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-08 00:59:38 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-08 02:38:50 (EDT)
commitc97b90494b626011aa562ae55ee7cfde8867feca (patch)
treeab8bd46636ad379cab52093dba4915c31e1df332 /src
parentaf5967c92418dbaf3a4ca440e10c6567cfe78d2f (diff)
downloadmazefight-c97b90494b626011aa562ae55ee7cfde8867feca.zip
mazefight-c97b90494b626011aa562ae55ee7cfde8867feca.tar.gz
mazefight-c97b90494b626011aa562ae55ee7cfde8867feca.tar.bz2
player: Render circle
Diffstat (limited to 'src')
-rw-r--r--src/defs.h5
-rw-r--r--src/player.c48
2 files changed, 43 insertions, 10 deletions
diff --git a/src/defs.h b/src/defs.h
index 501bbb2..e455281 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -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