summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-17 17:00:47 +0100
committerkdx <kikoodx@paranoici.org>2023-03-17 17:00:47 +0100
commit4d17f417ebdd3f161138530120c459a35c90ea5f (patch)
tree85b8ef73eb7fd977c90ef27ca406dc9d8fcf4533
parent066760bd7abbcc973ca46ab306f1e24481d3280c (diff)
downloadhyperultra-4d17f417ebdd3f161138530120c459a35c90ea5f.tar.gz
bounce on walls
-rw-r--r--res/font.pngbin3702 -> 68 bytes
-rw-r--r--res/tset.pngbin500 -> 68 bytes
-rw-r--r--src/player.c6
-rw-r--r--src/player.h5
4 files changed, 8 insertions, 3 deletions
diff --git a/res/font.png b/res/font.png
index 6c06089..af367b9 100644
--- a/res/font.png
+++ b/res/font.png
Binary files differ
diff --git a/res/tset.png b/res/tset.png
index 5b920e1..af367b9 100644
--- a/res/tset.png
+++ b/res/tset.png
Binary files differ
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;