diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-17 17:00:47 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-17 17:00:47 +0100 |
commit | 4d17f417ebdd3f161138530120c459a35c90ea5f (patch) | |
tree | 85b8ef73eb7fd977c90ef27ca406dc9d8fcf4533 | |
parent | 066760bd7abbcc973ca46ab306f1e24481d3280c (diff) | |
download | hyperultra-4d17f417ebdd3f161138530120c459a35c90ea5f.tar.gz |
bounce on walls
-rw-r--r-- | res/font.png | bin | 3702 -> 68 bytes | |||
-rw-r--r-- | res/tset.png | bin | 500 -> 68 bytes | |||
-rw-r--r-- | src/player.c | 6 | ||||
-rw-r--r-- | src/player.h | 5 |
4 files changed, 8 insertions, 3 deletions
diff --git a/res/font.png b/res/font.png Binary files differindex 6c06089..af367b9 100644 --- a/res/font.png +++ b/res/font.png diff --git a/res/tset.png b/res/tset.png Binary files differindex 5b920e1..af367b9 100644 --- a/res/tset.png +++ b/res/tset.png diff --git a/src/player.c b/src/player.c index 9d02ce0..b4765df 100644 --- a/src/player.c +++ b/src/player.c @@ -5,13 +5,14 @@ #include "cfg.h" #include "input.h" #include <string.h> +#include <math.h> static void player_update(Entity *this, Game *g) { const int on_ground = entity_collide(this, g, 0, 1); - this->vel[0] = 2.0; + this->vel[0] = 2.0 * this->player.dirx; this->vel[1] *= 0.99; this->vel[1] += 0.2; this->player.scale_x += 0.1 * (1.0 - this->player.scale_x); @@ -42,6 +43,8 @@ player_update(Entity *this, Game *g) } entity_move(this, g); + if (this->vel[0] == 0.0) + this->player.dirx *= -1; } static void @@ -74,4 +77,5 @@ player_init(Entity *this) this->height = 12; this->player.scale_x = 1.0; this->player.scale_y = 1.0; + this->player.dirx = 1; } diff --git a/src/player.h b/src/player.h index 8ea8e52..878b338 100644 --- a/src/player.h +++ b/src/player.h @@ -1,8 +1,9 @@ #pragma once typedef struct { - float scale_x; - float scale_y; + double scale_x; + double scale_y; + int dirx; } Player; struct Entity; |