summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defs.h6
-rw-r--r--src/player.c71
2 files changed, 66 insertions, 11 deletions
diff --git a/src/defs.h b/src/defs.h
index e455281..e170f57 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -45,6 +45,8 @@
#define MF_PLAYER_SPEED 2
#define MF_PLAYER_TURN_TIME 15
#define MF_PLAYER_P 2
+#define MF_PLAYER_SMILE_Y 0.25
+#define MF_PLAYER_SMILE_R 0.5
/* Colors */
#define MF_COLOR_BACK_R 0xAF /* Background color */
@@ -79,5 +81,9 @@
#define MF_COLOR_PLYR_G 0xAF
#define MF_COLOR_PLYR_B 0x7F
#define MF_COLOR_PLYR_A 0xFF
+#define MF_COLOR_PSML_R 0xDF /* Player smile color */
+#define MF_COLOR_PSML_G 0xDF
+#define MF_COLOR_PSML_B 0xDF
+#define MF_COLOR_PSML_A 0xFF
#endif /* MF_DEFS_H_ */
diff --git a/src/player.c b/src/player.c
index 9ababd4..f5d8f4c 100644
--- a/src/player.c
+++ b/src/player.c
@@ -176,10 +176,30 @@ mf_player_render(struct mf_player *p, SDL_Renderer *renderer)
int e = 0;
int cx;
int cy;
+ int fx;
int r;
int x;
int y;
int i;
+ int oy;
+ int fr;
+ int hy;
+
+ 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_: cy -= p->travel; fx = 2; break;
+ case MF_PLAYER_DIR_D_: cy += p->travel; fx = 0; break;
+ case MF_PLAYER_DIR_L_: cx -= p->travel; fx = -1; break;
+ case MF_PLAYER_DIR_R_: cx += p->travel; fx = 1; break;
+ default: fx = 0; break;
+ }
+ r = p->cell_width / 2 - MF_PLAYER_P;
+ fx *= (0.0 + MF_PLAYER_TURN_TIME-p->turning) / MF_PLAYER_TURN_TIME * r;
+
+ /*
+ * Head
+ */
if (SDL_SetRenderDrawColor(renderer,
MF_COLOR_PLYR_R, MF_COLOR_PLYR_G,
@@ -190,17 +210,6 @@ mf_player_render(struct mf_player *p, SDL_Renderer *renderer)
e = -1;
}
- 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_: 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;
- }
- r = p->cell_width / 2 - MF_PLAYER_P;
-
#define _mf_player_px(X, Y) \
do { \
if (SDL_RenderDrawPoint(renderer, cx + X, cy + Y) < 0) { \
@@ -226,6 +235,46 @@ mf_player_render(struct mf_player *p, SDL_Renderer *renderer)
#undef _mf_player_px
+ /*
+ * Smile
+ */
+
+ if (SDL_SetRenderDrawColor(renderer,
+ MF_COLOR_PSML_R, MF_COLOR_PSML_G,
+ MF_COLOR_PSML_B, MF_COLOR_PSML_A) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render player: %s",
+ SDL_GetError());
+ e = -1;
+ }
+
+ oy = r * MF_PLAYER_SMILE_Y;
+ fr = r * MF_PLAYER_SMILE_R;
+
+#define _mf_player_px(X, Y) \
+ do { \
+ hy = round(sqrt((r-0.5)*(r-0.5) - \
+ (X+fx-0.5)*(X+fx-0.5)) + 0.5); \
+ if (Y + oy < 0-hy || Y + oy > hy) continue; \
+ if (SDL_RenderDrawPoint(renderer, cx + fx + 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 <= y; ++i) _mf_player_px(0-x, i);
+ for (i = 0; i <= y; ++i) _mf_player_px( i, x);
+ for (i = 0; i >= 0-y; --i) _mf_player_px( i, x);
+ }
+
+#undef _mf_player_px
+
return e;
}