summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-17 16:54:07 +0100
committerkdx <kikoodx@paranoici.org>2023-03-17 16:54:07 +0100
commit066760bd7abbcc973ca46ab306f1e24481d3280c (patch)
treed43ef6940b1cdb2f1de9ba61bbacb454a1caca6b
parent0d8386099bb5febeaa0e6c31e68b308109080428 (diff)
downloadhyperultra-066760bd7abbcc973ca46ab306f1e24481d3280c.tar.gz
squishy jump
-rw-r--r--src/player.c28
-rw-r--r--src/player.h3
2 files changed, 24 insertions, 7 deletions
diff --git a/src/player.c b/src/player.c
index 3787a80..9d02ce0 100644
--- a/src/player.c
+++ b/src/player.c
@@ -14,19 +14,29 @@ player_update(Entity *this, Game *g)
this->vel[0] = 2.0;
this->vel[1] *= 0.99;
this->vel[1] += 0.2;
+ this->player.scale_x += 0.1 * (1.0 - this->player.scale_x);
+ this->player.scale_y += 0.1 * (1.0 - this->player.scale_y);
+ 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 && 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_x = 0.75;
+ this->player.scale_y = 1.25;
break;
default:
case 0:
this->vel[1] = -3.8;
+ this->player.scale_x = 0.66;
+ this->player.scale_y = 1.33;
break;
case 1:
this->vel[1] = -4.8;
+ this->player.scale_x = 0.5;
+ this->player.scale_y = 1.5;
break;
}
}
@@ -39,12 +49,16 @@ player_draw(Entity *this, Game *g)
{
(void)g;
LZY_DrawSetColor(BLACK);
- LZY_DrawRect(this->pos[0] - this->width / 2,
- this->pos[1] - this->height / 2,
- this->width, this->height);
- LZY_DrawRect(this->pos[0] - this->width / 2 + 1,
- this->pos[1] - this->height / 2 + 1,
- this->width - 2, this->height - 2);
+ int width = (int)(this->width / 2) * this->player.scale_x;
+ int height = (int)(this->height / 2) * this->player.scale_y;
+ width *= 2;
+ height *= 2;
+ LZY_DrawRect(this->pos[0] - width / 2,
+ this->pos[1] - height / 2,
+ width, height);
+ LZY_DrawRect(this->pos[0] - width / 2 + 1,
+ this->pos[1] - height / 2 + 1,
+ width - 2, height - 2);
}
void
@@ -58,4 +72,6 @@ player_init(Entity *this)
this->draw = player_draw;
this->width = 12;
this->height = 12;
+ this->player.scale_x = 1.0;
+ this->player.scale_y = 1.0;
}
diff --git a/src/player.h b/src/player.h
index a6fe6c9..8ea8e52 100644
--- a/src/player.h
+++ b/src/player.h
@@ -1,7 +1,8 @@
#pragma once
typedef struct {
- int _;
+ float scale_x;
+ float scale_y;
} Player;
struct Entity;