diff options
author | quou <quou@disroot.org> | 2023-05-03 07:32:34 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-03 07:32:34 +1000 |
commit | 199a5e6e9ddb13af0bb557b6ebbb2c4b8f4ce873 (patch) | |
tree | 2253af9926b3d0d1e3065d910cf16db957b2eedf /standard.c | |
parent | 65fa1051585f5345c3270db73ab53b7a0dbbaa50 (diff) |
Basic player movement.
Diffstat (limited to 'standard.c')
-rw-r--r-- | standard.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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; |