From 9a75800f10e745beca6fddbace5e3689f6ba6463 Mon Sep 17 00:00:00 2001 From: kdx Date: Sun, 19 Mar 2023 06:16:10 +0000 Subject: spinny player --- src/exit.c | 7 ++++--- src/player.c | 27 ++++++++++++++++----------- src/player.h | 2 ++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/exit.c b/src/exit.c index 1e23908..9efa7d8 100644 --- a/src/exit.c +++ b/src/exit.c @@ -1,13 +1,14 @@ #include "entityimpl.h" +#include "rotrect.h" IMPL_UPDATE() { } IMPL_END IMPL_DRAW() { LZY_DrawSetColor(BLACK); - LZY_DrawRect(this->pos[0] - this->width / 2, - this->pos[1] - this->height / 2, - this->width, this->height); + rotrect(this->pos[0] - this->width / 2.0, + this->pos[1] - this->height / 2.0, + this->width, this->height, 0.2); } IMPL_END IMPL_INIT(exit) { diff --git a/src/player.c b/src/player.c index 070d6a9..3298b52 100644 --- a/src/player.c +++ b/src/player.c @@ -3,6 +3,7 @@ #include "entityimpl.h" #include "game.h" #include "input.h" +#include "rotrect.h" #include IMPL_UPDATE() { @@ -16,24 +17,31 @@ IMPL_UPDATE() { if (fabs(this->player.scale_x - 1.0) < 0.05) this->player.scale_x = 1.01; if (fabs(this->player.scale_y - 1.0) < 0.05) this->player.scale_y = 1.01; + if (on_ground) { + this->player.rot_speed = 0.0; + this->player.angle = 0.0; + } else { + this->player.angle += this->player.rot_speed; + this->player.rot_speed *= 0.95; + } + if (on_ground && input_pressed(K_O)) { const int diry = input_down(K_UP) - input_down(K_DOWN); switch (diry) { case -1: this->vel[1] = -2.8; - this->player.scale_y = 1.40; + this->player.rot_speed = 0.3 * this->player.dirx; break; default: case 0: this->vel[1] = -3.8; - this->player.scale_y = 1.60; + this->player.rot_speed = 0.4 * this->player.dirx; break; case 1: this->vel[1] = -4.8; - this->player.scale_y = 2.0; + this->player.rot_speed = 0.5 * this->player.dirx; break; } - this->player.scale_x = 1.0 / this->player.scale_y; } else if (on_ground && input_down(K_X)) { extern double tick; this->vel[0] *= 3; @@ -66,13 +74,10 @@ IMPL_UPDATE() { IMPL_DRAW() { LZY_DrawSetColor(BLACK); - int width = (int)(this->width / 2 + 1) * this->player.scale_x; - int height = (int)(this->height / 2 + 1) * this->player.scale_y; - width *= 2; - height *= 2; - LZY_DrawRect(this->pos[0] - width / 2, - this->pos[1] - height / 2, - width, height); + const double width = this->width * this->player.scale_x + 2; + const double height = this->height * this->player.scale_y + 2; + rotrect(this->pos[0] - 1, this->pos[1] - 1, + width, height, this->player.angle); } IMPL_END IMPL_INIT(player) { diff --git a/src/player.h b/src/player.h index 1e25883..381fe46 100644 --- a/src/player.h +++ b/src/player.h @@ -6,6 +6,8 @@ typedef struct { double scale_x; double scale_y; + double rot_speed; + double angle; int dirx; } Player; -- cgit v1.2.3