1
1
Fork 0
Browse Source

fix bg colour order

thread-physics
alistair 4 years ago
parent
commit
6039ad749b
  1. 29
      draw.c
  2. 26
      environment.c
  3. 40
      game.c

29
draw.c

@ -274,16 +274,11 @@ void update_viewport(double x, double y) { @@ -274,16 +274,11 @@ void update_viewport(double x, double y) {
double interpolate_h(Vect left, Vect right, double x) {
static Vect v;
static Vect l;
static Vect r;
if (!(l.x == left.x && r.x == right.x
&& l.y == left.y && r.y == right.y)) {
l = left;
r = right;
v.x = (double)(right.y - left.y) / (double)(right.x - left.x);
v.y = (double)left.y - ((double)left.x * v.x);
}
return x * v.x + v.y;
double m = (double)(right.y - left.y) / (double)(right.x - left.x);
double c = (double)left.y - ((double)left.x * m);
return x * m + c;
}
void draw_environment(SDL_Renderer * ren, struct environment *scene) {
@ -336,7 +331,6 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) { @@ -336,7 +331,6 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) {
if (x - viewport_pos.x < 0) {
continue;
}
int blob = i;
left = arlst_get(&scene->ceil, i);
right = arlst_get(&scene->ceil, i+1);
@ -359,9 +353,13 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) { @@ -359,9 +353,13 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) {
int y3 = interpolate_h(*left, *right, x) - viewport_pos.y;
x = x - viewport_pos.x;
printf("x: %d, ", x);
printf("y: %d %d %d %d\n", y0, y1, y2, y3);
/*printf("x: %d, ", x);*/
/*printf("y: %d %d %d %d\n", y0, y1, y2, y3);*/
// 3. bg2 to floor
SDL_SetRenderDrawColor(ren, c4.r, c4.g, c4.b, 255);
SDL_RenderDrawLine(ren, x, y2, x, y3);
// 1. ceil to bg1
SDL_SetRenderDrawColor(ren, c2.r, c2.g, c2.b, 255);
SDL_RenderDrawLine(ren, x, y0, x, y1);
@ -369,10 +367,9 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) { @@ -369,10 +367,9 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) {
// 2. bg1 to bg2
SDL_SetRenderDrawColor(ren, c3.r, c3.g, c3.b, 255);
SDL_RenderDrawLine(ren, x, y1, x, y2);
// 3. bg2 to floor
SDL_SetRenderDrawColor(ren, c4.r, c4.g, c4.b, 255);
SDL_RenderDrawLine(ren, x, y2, x, y3);
}
}
}

26
environment.c

@ -69,7 +69,7 @@ struct colour_pallete get_pallete (int seed) { @@ -69,7 +69,7 @@ struct colour_pallete get_pallete (int seed) {
}
int comp(const void *one, const void *two) {
return *(int*)one > *(int*)two;
return *(int*)one >= *(int*)two;
}
struct environment get_scene_at(Vect coordinate, int seed) {
@ -119,34 +119,38 @@ struct environment get_scene_at(Vect coordinate, int seed) { @@ -119,34 +119,38 @@ struct environment get_scene_at(Vect coordinate, int seed) {
// r[0] == ceiling
// r[3] == floor
node.y += r[0];
//node.y += r[0];
int h[4] = {node.y,node.y,node.y,node.y};
h[0] += r[0];
h[1] = h[0] + r[1];
h[2] += h[0] + r[2];
h[3] += h[0] + r[3];
qsort(h, 4, sizeof(int), comp);
// node.y = fmod(perlin(bit), 3000);
Vect *z = malloc(sizeof(Vect));
*z = node;
printf("%f %f\n", bit.x, z->y);
z->y = h[0];
arlst_add(&e.floor, z);
z = malloc(sizeof(Vect));
*z = node;
z->y += r[1];
printf("%f %f\n", bit.x, z->y);
// z->y += r[1];
z->y = h[1];
arlst_add(&e.bg1, z);
z = malloc(sizeof(Vect));
*z = node;
z->y += r[2];
printf("%f %f\n", bit.x, z->y);
//z->y += r[2];
z->y = h[2];
arlst_add(&e.bg2, z);
z = malloc(sizeof(Vect));
*z = node;
z->y += r[3];
printf("%f %f\n", bit.x, z->y);
// z->y += r[3];
z->y = h[3];
arlst_add(&e.ceil, z);
}

40
game.c

@ -497,6 +497,15 @@ bool check_collision(Body *one, Body *two, Vect *translation) { @@ -497,6 +497,15 @@ bool check_collision(Body *one, Body *two, Vect *translation) {
}
}
void destroy_physics_collection(struct physics_collection *s) {
for (int i = 0; i < s->numItems; i++) {
free(s->items[i]);
}
free(s->items);
}
int get_floor_ceiling();
void next_level() {
Vect v;
v.x = 0;
@ -507,7 +516,15 @@ void next_level() { @@ -507,7 +516,15 @@ void next_level() {
player.physics->position.y = 0;
player.physics->position = v;
player.physics->next_position = v;
// destroy_physics_collection(&world.uniques_index[ROOM_W]->room->ceil);
// destroy_physics_collection(&world.uniques_index[ROOM_W]->room->floor);
// still need to free world object
level++;
get_floor_ceiling();
}
int get_floor_ceiling() {
@ -519,26 +536,27 @@ int get_floor_ceiling() { @@ -519,26 +536,27 @@ int get_floor_ceiling() {
ceil.items = calloc(e.ceil.size - 1, sizeof(Body*));
floor.numItems = e.floor.size - 1;
ceil.numItems = e.floor.size - 1;
ceil.numItems = e.ceil.size - 1;
for (int i = 0; i < e.floor.size-1; i++) {
get_new_physics(&floor.items[i]);
get_new_physics(&ceil.items[i]);
Body *fseg = floor.items[i];
Body *cseg = floor.items[i];
Body *cseg = ceil.items[i];
fseg->position = *(Vect *)arlst_get(&e.floor, i);
cseg->position = *(Vect *)arlst_get(&e.ceil, i);
fseg->collision_poly_size = 4;
cseg->collision_poly_size = 4;
fseg->collision_poly = calloc(4, sizeof(Vect));
fseg->collision_shape = calloc(4, sizeof(Vect));
cseg->position = *(Vect *)arlst_get(&e.ceil, i);
cseg->collision_poly_size = 4;
cseg->collision_poly = calloc(4, sizeof(Vect));
cseg->collision_shape = calloc(4, sizeof(Vect));
Vect fthis = fseg->position;
Vect cthis = cseg->position;
Vect fnext = *(Vect *)arlst_get(&e.floor, i + 1);
Vect cnext= *(Vect *)arlst_get(&e.ceil, i + 1);
@ -548,8 +566,8 @@ int get_floor_ceiling() { @@ -548,8 +566,8 @@ int get_floor_ceiling() {
double crise = cnext.y - cthis.y;
double crun = cnext.x - cthis.x;
double fdepth = fabs(frise) * 2 + 100;
double cdepth = -fabs(crise) * 2 + 100;
double fdepth = -(fabs(frise) * 2 + 100);
double cdepth = fabs(crise) * 2 + 100;
fseg->collision_shape[0].x = 0;
fseg->collision_shape[0].y = 0;
@ -561,7 +579,7 @@ int get_floor_ceiling() { @@ -561,7 +579,7 @@ int get_floor_ceiling() {
fseg->collision_shape[2].y = frise + fdepth;
fseg->collision_shape[3].x = 0;
fseg->collision_shape[3].y = frise + cdepth;
fseg->collision_shape[3].y = frise + fdepth;
cseg->collision_shape[0].x = 0;
cseg->collision_shape[0].y = 0;
@ -570,10 +588,10 @@ int get_floor_ceiling() { @@ -570,10 +588,10 @@ int get_floor_ceiling() {
cseg->collision_shape[1].y = crise;
cseg->collision_shape[2].x = crun;
cseg->collision_shape[2].y = crise + fdepth;
cseg->collision_shape[2].y = crise + cdepth;
cseg->collision_shape[3].x = 0;
cseg->collision_shape[3].y = crise + fdepth;
cseg->collision_shape[3].y = crise + cdepth;
default_update_collision_poly(cseg);
default_update_collision_poly(fseg);
@ -1261,7 +1279,7 @@ void startgame(SDL_Renderer * ren) { @@ -1261,7 +1279,7 @@ void startgame(SDL_Renderer * ren) {
logwrite(INFO, "STARTGAME");
get_input_map();
level = 0;
level = 2;
world = create_world();

Loading…
Cancel
Save