summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-08 04:04:32 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-08 04:04:32 (EDT)
commitcd91a87b765364afd543dc8de8ccb1d4f8fe41a1 (patch)
tree571de92aa06f3e6de8ec9adc837364186d5b888d /src
parente27efee6bdfc46c3af87ff07d161ebd1a2a8a2b1 (diff)
downloadmazefight-cd91a87b765364afd543dc8de8ccb1d4f8fe41a1.zip
mazefight-cd91a87b765364afd543dc8de8ccb1d4f8fe41a1.tar.gz
mazefight-cd91a87b765364afd543dc8de8ccb1d4f8fe41a1.tar.bz2
player: Add eyes (WIP)
Diffstat (limited to 'src')
-rw-r--r--src/defs.h7
-rw-r--r--src/player.c60
2 files changed, 67 insertions, 0 deletions
diff --git a/src/defs.h b/src/defs.h
index e170f57..a200ad1 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -47,6 +47,9 @@
#define MF_PLAYER_P 2
#define MF_PLAYER_SMILE_Y 0.25
#define MF_PLAYER_SMILE_R 0.5
+#define MF_PLAYER_EYE_X 0.5
+#define MF_PLAYER_EYE_Y 0.375
+#define MF_PLAYER_EYE_R 0.125
/* Colors */
#define MF_COLOR_BACK_R 0xAF /* Background color */
@@ -85,5 +88,9 @@
#define MF_COLOR_PSML_G 0xDF
#define MF_COLOR_PSML_B 0xDF
#define MF_COLOR_PSML_A 0xFF
+#define MF_COLOR_PEYE_R 0xDF /* Player eye color */
+#define MF_COLOR_PEYE_G 0xDF
+#define MF_COLOR_PEYE_B 0xDF
+#define MF_COLOR_PEYE_A 0xFF
#endif /* MF_DEFS_H_ */
diff --git a/src/player.c b/src/player.c
index f5d8f4c..1ec7795 100644
--- a/src/player.c
+++ b/src/player.c
@@ -184,6 +184,7 @@ mf_player_render(struct mf_player *p, SDL_Renderer *renderer)
int oy;
int fr;
int hy;
+ int ox;
cx = p->cur_x * p->cell_width + p->cell_width / 2;
cy = p->cur_y * p->cell_width + p->cell_width / 2;
@@ -275,6 +276,65 @@ mf_player_render(struct mf_player *p, SDL_Renderer *renderer)
#undef _mf_player_px
+ /*
+ * Eyes
+ */
+
+ if (SDL_SetRenderDrawColor(renderer,
+ MF_COLOR_PEYE_R, MF_COLOR_PEYE_G,
+ MF_COLOR_PEYE_B, MF_COLOR_PEYE_A) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render player: %s",
+ SDL_GetError());
+ e = -1;
+ }
+
+ ox = r * MF_PLAYER_EYE_X;
+ oy = r * MF_PLAYER_EYE_Y;
+ fr = r * MF_PLAYER_EYE_R;
+
+#define _mf_player_px(X, Y) \
+ do { \
+ hy = round(sqrt((r-0.5)*(r-0.5) - \
+ (X+fx-ox-0.5)*(X+fx-ox-0.5)) + 0.5); \
+ if (Y - oy >= 0-hy || Y - oy <= hy) { \
+ if (SDL_RenderDrawPoint(renderer, \
+ cx + fx - ox + X, cy - oy + Y) \
+ < 0) { \
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
+ "Couldn't render widget: %s", \
+ SDL_GetError()); \
+ e = -1; \
+ } \
+ } \
+ hy = round(sqrt((r-0.5)*(r-0.5) - \
+ (X+fx+ox-0.5)*(X+fx+ox-0.5)) + 0.5); \
+ if (Y - oy >= 0-hy || Y - oy <= hy) { \
+ if (SDL_RenderDrawPoint(renderer, \
+ cx + fx + ox + X, cy - oy + Y) \
+ < 0) { \
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
+ "Couldn't render widget: %s", \
+ SDL_GetError()); \
+ e = -1; \
+ } \
+ } \
+ } while (0)
+
+ for (x = 0, y = fr; y > x; ++x) {
+ y = round(sqrt((fr-0.5)*(fr-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;
}