|
|
|
@ -1,13 +1,12 @@
@@ -1,13 +1,12 @@
|
|
|
|
|
#include "game.h" |
|
|
|
|
#define FLOOR_THICKNESS 200 |
|
|
|
|
|
|
|
|
|
GlobWorld world; |
|
|
|
|
|
|
|
|
|
player_st *glob_player; |
|
|
|
|
|
|
|
|
|
/* array of all the things in the world and their kinds */ |
|
|
|
|
world_thing *world; |
|
|
|
|
|
|
|
|
|
int things_in_world; |
|
|
|
|
int world_size; |
|
|
|
|
//world_thing *world;
|
|
|
|
|
|
|
|
|
|
void startgame(SDL_Renderer * ren) ; |
|
|
|
|
|
|
|
|
@ -72,7 +71,6 @@ void default_motor_curve(Motor *motor) {
@@ -72,7 +71,6 @@ void default_motor_curve(Motor *motor) {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FloorPoly* generate_floor_simple(int num_polys, bool extend_down, int st_height) { |
|
|
|
|
FloorPoly *floor = calloc(num_polys, sizeof(FloorPoly)); |
|
|
|
|
Vect last, next; |
|
|
|
@ -376,7 +374,6 @@ bool sat_collision_check(Body *one, Body *two, Vect *translation) {
@@ -376,7 +374,6 @@ bool sat_collision_check(Body *one, Body *two, Vect *translation) {
|
|
|
|
|
|
|
|
|
|
if ((proj_one[0] >= proj_two[1])
|
|
|
|
|
|| (proj_two[0] >= proj_one[1])) { |
|
|
|
|
logwrite(INFO, "No collision"); |
|
|
|
|
free(axes); |
|
|
|
|
free(proj_one); |
|
|
|
|
free(proj_two); |
|
|
|
@ -390,7 +387,6 @@ bool sat_collision_check(Body *one, Body *two, Vect *translation) {
@@ -390,7 +387,6 @@ bool sat_collision_check(Body *one, Body *two, Vect *translation) {
|
|
|
|
|
// one of the shapes is contained
|
|
|
|
|
if ((overlap > (proj_one[1] - proj_one[0]) |
|
|
|
|
|| (overlap > (proj_two[1] - proj_two[0])))) { |
|
|
|
|
logwrite(INFO, "Contained collision"); |
|
|
|
|
|
|
|
|
|
double min = proj_one[0] - proj_two[0]; |
|
|
|
|
double max = proj_one[1] - proj_two[1]; |
|
|
|
@ -647,10 +643,37 @@ void add_rope(void) {
@@ -647,10 +643,37 @@ void add_rope(void) {
|
|
|
|
|
if (player.physics->strings[0].attached) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Vect end_pt; |
|
|
|
|
end_pt.x = player.physics->position.x + 100;
|
|
|
|
|
end_pt.y = player.physics->position.y - 100;
|
|
|
|
|
player.physics->strings[0].set_end_point(player.physics->strings, &end_pt); |
|
|
|
|
|
|
|
|
|
Vect start = player.physics->position; |
|
|
|
|
Vect end; |
|
|
|
|
end.x = start.x + 300 * player.physics->vel.x; |
|
|
|
|
if (end.x - start.x < 30) { |
|
|
|
|
end.x = start.x + 90; |
|
|
|
|
} |
|
|
|
|
end.y = 0; |
|
|
|
|
|
|
|
|
|
Floor *ceiling = world.uniques_index[CEILING]->floor; |
|
|
|
|
|
|
|
|
|
int y = 0; |
|
|
|
|
for (int i = 0; i < ceiling->numPolys; i++) { |
|
|
|
|
if (ceiling->polys[i].right.x > end.x) { |
|
|
|
|
double width = ceiling->polys[i].right.x - ceiling->polys[i].left.x; |
|
|
|
|
double m = (double)(ceiling->polys[i].right.y - ceiling->polys[i].left.y)
|
|
|
|
|
/ width; |
|
|
|
|
|
|
|
|
|
double delt = ceiling->polys[i].right.x - end.x; |
|
|
|
|
end.y = ceiling->polys[i].right.y - (int)(m * delt); |
|
|
|
|
|
|
|
|
|
printf("ROPEJASHD: %f, %f\n", end.y, delt); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Vect rop = vect_add(end, vect_scalar(start, -1)); |
|
|
|
|
|
|
|
|
|
player.physics->strings[0].max_length = vect_mag(rop); |
|
|
|
|
|
|
|
|
|
player.physics->strings[0].set_end_point(player.physics->strings, &end); |
|
|
|
|
player.physics->strings[0].attached = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -667,29 +690,29 @@ int process_collisions(Body *thing, Vect *trans) {
@@ -667,29 +690,29 @@ int process_collisions(Body *thing, Vect *trans) {
|
|
|
|
|
int num_cols = 0; |
|
|
|
|
int num = 0; |
|
|
|
|
|
|
|
|
|
for (int k = 0; k < things_in_world; k++) { |
|
|
|
|
if (world[k].kind == STATIC_WALL_W
|
|
|
|
|
&& world[k].wall->physics->uid != thing->uid) { |
|
|
|
|
if ((world[k].wall->physics->position.x - viewport_pos.x) > (width * 2)
|
|
|
|
|
|| world[k].wall->physics->position.x - viewport_pos.x < 0) { |
|
|
|
|
for (int k = 0; k < world.size; k++) { |
|
|
|
|
if (world.things[k].kind == STATIC_WALL_W
|
|
|
|
|
&& world.things[k].wall->physics->uid != thing->uid) { |
|
|
|
|
if ((world.things[k].wall->physics->position.x - viewport_pos.x) > (width * 2)
|
|
|
|
|
|| world.things[k].wall->physics->position.x - viewport_pos.x < 0) { |
|
|
|
|
continue; |
|
|
|
|
} else { |
|
|
|
|
num++; |
|
|
|
|
} |
|
|
|
|
if (check_collision(world[k].wall->physics, thing, &temptrans)) { |
|
|
|
|
if (check_collision(world.things[k].wall->physics, thing, &temptrans)) { |
|
|
|
|
num++; |
|
|
|
|
thing->colliding = true; |
|
|
|
|
translation = vect_add(translation, temptrans); |
|
|
|
|
} |
|
|
|
|
} else if (world[k].kind == FLOOR || world[k].kind == CEILING) { |
|
|
|
|
for (int i = 0; i < world[k].floor->numPolys; i++) { |
|
|
|
|
if ((world[k].floor->polys[i].physics->position.x - viewport_pos.x) > (2 *width)
|
|
|
|
|
|| (world[k].floor->polys[i].physics->position.x - viewport_pos.x) < -width) {
|
|
|
|
|
} else if (world.things[k].kind == FLOOR || world.things[k].kind == CEILING) { |
|
|
|
|
for (int i = 0; i < world.things[k].floor->numPolys; i++) { |
|
|
|
|
if ((world.things[k].floor->polys[i].physics->position.x - viewport_pos.x) > (2 *width)
|
|
|
|
|
|| (world.things[k].floor->polys[i].physics->position.x - viewport_pos.x) < -width) {
|
|
|
|
|
continue; |
|
|
|
|
} else { |
|
|
|
|
num++; |
|
|
|
|
} |
|
|
|
|
if (check_collision(world[k].floor->polys[i].physics, thing, &temptrans)) { |
|
|
|
|
if (check_collision(world.things[k].floor->polys[i].physics, thing, &temptrans)) { |
|
|
|
|
num_cols++; |
|
|
|
|
thing->colliding = true; |
|
|
|
|
translation = vect_add(translation, temptrans); |
|
|
|
@ -802,7 +825,8 @@ void advance_thing(Body * thing) {
@@ -802,7 +825,8 @@ void advance_thing(Body * thing) {
|
|
|
|
|
double st_len = vect_distance(thing->next_position, thing->strings[i].end_point); |
|
|
|
|
double max_len = thing->strings[i].max_length; |
|
|
|
|
printf("STRING len: %f, %f\n", st_len, max_len); |
|
|
|
|
printf("strendpoint: %f:%f\n\n", thing->strings[i].end_point.x, thing->strings[i].end_point.y); |
|
|
|
|
printf("strendpoint: %f:%f\n\n", thing->strings[i].end_point.x,
|
|
|
|
|
thing->strings[i].end_point.y); |
|
|
|
|
if (st_len > max_len) { |
|
|
|
|
Vect string_end = thing->strings[i].end_point; |
|
|
|
|
Vect thing_position = thing->next_position; |
|
|
|
@ -936,47 +960,61 @@ void get_projectile(Projectile** proj) {
@@ -936,47 +960,61 @@ void get_projectile(Projectile** proj) {
|
|
|
|
|
void advance_things(void) { |
|
|
|
|
int numcols; |
|
|
|
|
Vect translation; |
|
|
|
|
for (int i = 0; i < things_in_world; i++) { |
|
|
|
|
switch (world[i].kind) { |
|
|
|
|
for (int i = 0; i < world.size; i++) { |
|
|
|
|
switch (world.things[i].kind) { |
|
|
|
|
case PLAYER_W : |
|
|
|
|
logwrite(INFO, "ADVANCE PLAYER\n"); |
|
|
|
|
advance_thing((world[i].player->physics)); |
|
|
|
|
advance_thing((world.things[i].player->physics)); |
|
|
|
|
break; |
|
|
|
|
case STATIC_WALL_W: |
|
|
|
|
logwrite(INFO, "ADVANCE WALL\n"); |
|
|
|
|
advance_thing(world[i].wall->physics); |
|
|
|
|
advance_thing(world.things[i].wall->physics); |
|
|
|
|
break; |
|
|
|
|
case FLOOR: |
|
|
|
|
for (int k = 0; k < world[i].floor->numPolys; k++) { |
|
|
|
|
advance_thing(world[i].floor->polys[k].physics); |
|
|
|
|
for (int k = 0; k < world.things[i].floor->numPolys; k++) { |
|
|
|
|
advance_thing(world.things[i].floor->polys[k].physics); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case CEILING: |
|
|
|
|
for (int k = 0; k < world[i].floor->numPolys; k++) { |
|
|
|
|
advance_thing(world[i].floor->polys[k].physics); |
|
|
|
|
for (int k = 0; k < world.things[i].floor->numPolys; k++) { |
|
|
|
|
advance_thing(world.things[i].floor->polys[k].physics); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case PROJECTILE: |
|
|
|
|
if ((numcols = process_collisions(world[i].projectile->physics, |
|
|
|
|
if ((numcols = process_collisions(world.things[i].projectile->physics, |
|
|
|
|
&translation))) { |
|
|
|
|
world[i].projectile->on_collision(world[i].projectile); |
|
|
|
|
world.things[i].projectile->on_collision(world.things[i].projectile); |
|
|
|
|
} |
|
|
|
|
world[i].projectile->on_step(world[i].projectile); |
|
|
|
|
world.things[i].projectile->on_step(world.things[i].projectile); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool unique_world_kind(enum world_thing_kind k) { |
|
|
|
|
switch (k) { |
|
|
|
|
case PLAYER_W: |
|
|
|
|
case FLOOR: |
|
|
|
|
case CEILING: |
|
|
|
|
return true; |
|
|
|
|
default: |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// grow array of world things if needed
|
|
|
|
|
void add_to_world(world_thing thing) { |
|
|
|
|
if (things_in_world == world_size) { |
|
|
|
|
if (world.size == world.capacity) { |
|
|
|
|
logwrite(INFO, "Increased world size."); |
|
|
|
|
world = realloc(world, sizeof(world_thing) * (world_size*=2)); |
|
|
|
|
world.things = realloc(world.things, sizeof(world_thing) * (world.size*=2)); |
|
|
|
|
if (unique_world_kind(thing.kind)) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
thing.nid = things_in_world; |
|
|
|
|
memcpy(world + things_in_world, &thing, sizeof(world_thing)); |
|
|
|
|
thing.nid = world.size; |
|
|
|
|
memcpy(world.things + world.size, &thing, sizeof(world_thing)); |
|
|
|
|
world.uniques_index[thing.kind] = world.things + world.size; |
|
|
|
|
|
|
|
|
|
things_in_world += 1; |
|
|
|
|
world.size++; |
|
|
|
|
//printf("Added to world: %d\n", thing.kind);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1020,13 +1058,23 @@ void get_room(void) {
@@ -1020,13 +1058,23 @@ void get_room(void) {
|
|
|
|
|
add_to_world(floorthing); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GlobWorld create_world() { |
|
|
|
|
GlobWorld c; |
|
|
|
|
c.things = malloc(sizeof(world_thing) * 100); |
|
|
|
|
memset(c.things, 0, sizeof(world_thing) * 100); |
|
|
|
|
c.capacity = 100; |
|
|
|
|
c.size = 0; |
|
|
|
|
c.uniques_index = calloc(3, sizeof(world_thing*)); |
|
|
|
|
return c; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void startgame(SDL_Renderer * ren) { |
|
|
|
|
logwrite(INFO, "STARTGAME"); |
|
|
|
|
get_input_map(); |
|
|
|
|
things_in_world = 0; |
|
|
|
|
world_size = 100; |
|
|
|
|
world = malloc(sizeof(world_thing) * 100); |
|
|
|
|
memset(world, 0, sizeof(world_thing) * 100); |
|
|
|
|
|
|
|
|
|
world = create_world(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SDL_GetRendererOutputSize(ren, &width, &height); |
|
|
|
|
|
|
|
|
|
player = get_player(200,300); |
|
|
|
|