aboutsummaryrefslogtreecommitdiff
path: root/standard.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-03 07:32:34 +1000
committerquou <quou@disroot.org>2023-05-03 07:32:34 +1000
commit199a5e6e9ddb13af0bb557b6ebbb2c4b8f4ce873 (patch)
tree2253af9926b3d0d1e3065d910cf16db957b2eedf /standard.c
parent65fa1051585f5345c3270db73ab53b7a0dbbaa50 (diff)
Basic player movement.
Diffstat (limited to 'standard.c')
-rw-r--r--standard.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/standard.c b/standard.c
index 801777c..5e464f6 100644
--- a/standard.c
+++ b/standard.c
@@ -135,6 +135,44 @@ int flerp(int a, int b, int t) {
return a + ((t * (b - a)) >> fbits);
}
+void vec_nrmise(int* x, int* y) {
+ int l;
+
+ l = ((*x * *x) >> fbits) + ((*y * *y) >> fbits);
+ *x = (*x << fbits) / l;
+ *y = (*y << fbits) / l;
+}
+
+static unsigned rng_seed, n;
+
+void seed_rng(unsigned seed) {
+ rng_seed = seed;
+ n = seed;
+}
+
+unsigned get_seed() {
+ return rng_seed;
+}
+
+unsigned rng() {
+ int a;
+ unsigned r;
+
+ n++;
+
+ a = n * 15485863;
+ r = (a * a * a % 2038074743);
+ return r;
+}
+
+int rand_range(int a, int b) {
+ return a + (int)(rng() % ((unsigned)(b - a) + 1));
+}
+
+int randf() {
+ return (int)(rng() % ((1 << fbits) + 1));
+}
+
int int_to_buf(int n, char* buf) {
int i, sign, t;
unsigned n1;