1
1
Fork 0
Browse Source

custom rng for platform uniformity

emscriptem
alistair 4 years ago
parent
commit
917fc9bb34
  1. 2
      src/basic-lib.c
  2. 8
      src/draw.c
  3. 18
      src/environment.c
  4. 34
      src/game.c
  5. 2
      src/game.h

2
src/basic-lib.c

@ -96,5 +96,3 @@ void get_time(void) { @@ -96,5 +96,3 @@ void get_time(void) {
}

8
src/draw.c

@ -282,11 +282,9 @@ void new_update_viewport(Body const * const pl) { @@ -282,11 +282,9 @@ void new_update_viewport(Body const * const pl) {
if (last_plpos.x == 0 && last_plpos.y == 0)
last_plpos = player.physics->position;
printf("%f %f\n", pl->vel.x, pl->vel.y);
static Vect lmove = {};
Vect iv = in_view(pl->position);
printf("player pos: %f %f\n", pl->position.x, pl->position.y);
Vect left_pos = {0, 2 * height / 4};
left_pos = vect_add(pl->position, vect_scalar(left_pos, -1));
@ -309,10 +307,8 @@ void new_update_viewport(Body const * const pl) { @@ -309,10 +307,8 @@ void new_update_viewport(Body const * const pl) {
if (true || (recover) //|| vect_mag((Vect){pl->vel.x, 0}) > 0.4
|| (dist_change > width / 100)) {
if (iv.x < width / 6) {
printf("RIGHT\n");
target = right_pos;
} else {
printf("LEFT\n");
target = left_pos;
}
lmove = target;
@ -343,8 +339,6 @@ void new_update_viewport(Body const * const pl) { @@ -343,8 +339,6 @@ void new_update_viewport(Body const * const pl) {
/*}*/
//target.y = pl->position.y - height/2; // + y;
printf("viewport pos: %f %f\n", iv.x, iv.y);
printf("target pos: %f %f\n", target.x, iv.y);
/*}*/
/*}*/
@ -360,12 +354,10 @@ void new_update_viewport(Body const * const pl) { @@ -360,12 +354,10 @@ void new_update_viewport(Body const * const pl) {
// move towards target a set proportion
Vect urgency = vect_add(target, vect_scalar(player.physics->position, -1));
Vect p = vect_add(target, vect_scalar(viewport_pos, -1));
printf("drawtime: %f", time_delta);
double proportion = (sigmoid(time_delta) / 100);
proportion = 2 * player.physics->vel.x / (width);
proportion = proportion < 0 ? -proportion : proportion;
printf("prop: %f", proportion);
proportion > 0.4 ? proportion = 0.4 : 0;
proportion < 0 ? proportion = 0.000001 : 0;

18
src/environment.c

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include "environment.h"
#include "game.h"
double linear_interpolate(double a0, double a1, double w) {
return (1.0f - w) * a0 + w * a1;
@ -53,8 +54,15 @@ double perlin(Vect coordinate) { @@ -53,8 +54,15 @@ double perlin(Vect coordinate) {
struct colour_pallete get_pallete (int seed) {
struct colour base = get_random_color(seed);
struct colour base;
int red = get_rand(0) % 255;
int blue = get_rand(0) % 255;
int green = get_rand(0) % 255;
base.r = red;
base.g = green;
base.b = blue;
struct colour c1 = get_hsv(base);
c1 = get_hsv(base);
@ -115,7 +123,7 @@ struct environment get_scene_at(Vect coordinate, int seed) { @@ -115,7 +123,7 @@ struct environment get_scene_at(Vect coordinate, int seed) {
bit.y = 100 * seed;
Vect pos;
srand(seed);
get_rand(seed);
Vect node;
node.y = 0;
@ -125,9 +133,9 @@ struct environment get_scene_at(Vect coordinate, int seed) { @@ -125,9 +133,9 @@ struct environment get_scene_at(Vect coordinate, int seed) {
bit.y = seed;
node.x = bit.x;
int r1 = 1.5*(rand() % 500) - (rand() % 100);
int r2 = 1.5*(rand() % 200) - (rand() % 200);
int r3 = (rand() % 100) - (rand() % 500);
int r1 = 1.5*(get_rand(0) % 500) - (get_rand(0) % 100);
int r2 = 1.5*(get_rand(0) % 200) - (get_rand(0) % 200);
int r3 = (get_rand(0) % 100) - (get_rand(0) % 500);
int r4 = 50;
int r[4] = {r1, r2, r3, r4};

34
src/game.c

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include "game.h"
#include <SDL2/SDL_scancode.h>
#include <SDL2/SDL_timer.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mutex.h>
@ -111,8 +112,8 @@ FloorPoly* generate_floor_simple(int num_polys, bool extend_down, int st_height) @@ -111,8 +112,8 @@ FloorPoly* generate_floor_simple(int num_polys, bool extend_down, int st_height)
last.y = st_height;
for (int i = 0; i < num_polys; i++) {
double run = (rand() % 900);
double rise = (rand() % 100) - (rand() % 100);
double run = (get_rand(0) % 900);
double rise = (get_rand(0) % 100) - (get_rand(0) % 100);
next.x = last.x + run;
next.y = last.y + rise;
@ -578,7 +579,7 @@ void next_level() { @@ -578,7 +579,7 @@ void next_level() {
destroy_physics_collection(&world.uniques_index[ROOM_W]->room->floor);
destroy_environment(&world.uniques_index[ROOM_W]->room->env);
level++;
level+= 31;;
get_floor_ceiling();
v = world.uniques_index[ROOM_W]->room->ceil.items[2]->collision_poly[0];
@ -1374,7 +1375,6 @@ void add_to_world(world_thing thing) { @@ -1374,7 +1375,6 @@ void add_to_world(world_thing thing) {
world.uniques_index[thing.kind] = ref;
}
printf("Added to world: %d\n", thing.kind);
}
/* Send a projectile from body in direction dir (in degrees) with the force of
@ -1434,7 +1434,7 @@ void startgame(SDL_Renderer * ren) { @@ -1434,7 +1434,7 @@ void startgame(SDL_Renderer * ren) {
debug_ren = ren;
level = 113;
level = 31;
world = create_world();
@ -1505,6 +1505,9 @@ void handle_input_event(SDL_Event event) { @@ -1505,6 +1505,9 @@ void handle_input_event(SDL_Event event) {
} if (sc == input_map.player_pull_rope) {
stop_pull_rope();
}
if (event.key.keysym.scancode == SDL_SCANCODE_F10) {
next_level();
}
break;
case SDL_MOUSEBUTTONDOWN:
add_rope(event.button.x, event.button.y);
@ -1527,6 +1530,24 @@ void handle_input_event(SDL_Event event) { @@ -1527,6 +1530,24 @@ void handle_input_event(SDL_Event event) {
}
}
int get_rand(int seed) {
const unsigned c = 11;
const unsigned m = (1 << 31) - 1;
const unsigned initial_n = 1;
const unsigned a = 48271;
static unsigned n = initial_n;
if (seed != 0) {
n = seed ;
}
n = (a * n + c) % m;
return n;
}
void step(int interval) {
if (player.physics->position.x > world.uniques_index[ROOM_W]->room
@ -1538,3 +1559,6 @@ void step(int interval) { @@ -1538,3 +1559,6 @@ void step(int interval) {
advance_things();
}

2
src/game.h

@ -20,6 +20,8 @@ void add_motor(Body *thing, double x, double y); @@ -20,6 +20,8 @@ void add_motor(Body *thing, double x, double y);
bool get_motor_active(Body *thing, int i);
int get_rand(int seed);
/* array of all the things in the world and their kinds */
extern void startgame(SDL_Renderer * ren) ;
extern void process_keydown(SDL_Keysym key);

Loading…
Cancel
Save