From 199a5e6e9ddb13af0bb557b6ebbb2c4b8f4ce873 Mon Sep 17 00:00:00 2001 From: quou Date: Wed, 3 May 2023 07:32:34 +1000 Subject: Basic player movement. --- standard.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'standard.c') 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; -- cgit v1.2.3-54-g00ecf