diff options
Diffstat (limited to 'src/player.c')
-rw-r--r-- | src/player.c | 27 |
1 files changed, 16 insertions, 11 deletions
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 <math.h> 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) { |