|
|
|
@ -1,10 +1,13 @@
@@ -1,10 +1,13 @@
|
|
|
|
|
#include "game.h" |
|
|
|
|
#include "environment.h" |
|
|
|
|
#define FLOOR_THICKNESS 200 |
|
|
|
|
|
|
|
|
|
GlobWorld world; |
|
|
|
|
|
|
|
|
|
player_st *glob_player; |
|
|
|
|
|
|
|
|
|
int level; |
|
|
|
|
|
|
|
|
|
/* array of all the things in the world and their kinds */ |
|
|
|
|
//world_thing *world;
|
|
|
|
|
|
|
|
|
@ -13,6 +16,7 @@ void startgame(SDL_Renderer * ren) ;
@@ -13,6 +16,7 @@ void startgame(SDL_Renderer * ren) ;
|
|
|
|
|
void process_keydown(SDL_Keysym key); |
|
|
|
|
void process_keyup(SDL_Keysym key); |
|
|
|
|
|
|
|
|
|
void add_to_world(world_thing thing);
|
|
|
|
|
void step(int interval); |
|
|
|
|
|
|
|
|
|
player_st player; |
|
|
|
@ -71,6 +75,7 @@ void default_motor_curve(Motor *motor) {
@@ -71,6 +75,7 @@ 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; |
|
|
|
@ -492,6 +497,93 @@ bool check_collision(Body *one, Body *two, Vect *translation) {
@@ -492,6 +497,93 @@ bool check_collision(Body *one, Body *two, Vect *translation) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void next_level() { |
|
|
|
|
Vect v; |
|
|
|
|
v.x = 0; |
|
|
|
|
v.y = 0; |
|
|
|
|
player.physics->vel = v; |
|
|
|
|
player.physics->acc = v; |
|
|
|
|
player.physics->position.x = 0; |
|
|
|
|
player.physics->position.y = 0; |
|
|
|
|
player.physics->position = v; |
|
|
|
|
player.physics->next_position = v; |
|
|
|
|
level++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int get_floor_ceiling() { |
|
|
|
|
struct environment e = get_scene_at(viewport_pos, level); |
|
|
|
|
struct physics_collection floor; |
|
|
|
|
struct physics_collection ceil; |
|
|
|
|
|
|
|
|
|
floor.items = calloc(e.floor.size, sizeof(Body*)); |
|
|
|
|
ceil.items = calloc(e.floor.size, sizeof(Body*)); |
|
|
|
|
floor.numItems = e.floor.size - 1; |
|
|
|
|
ceil.numItems = e.floor.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]; |
|
|
|
|
|
|
|
|
|
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->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); |
|
|
|
|
Vect cnext= *(Vect *)arlst_get(&e.ceil, i); |
|
|
|
|
|
|
|
|
|
double frise = fnext.y - fthis.y; |
|
|
|
|
double frun = fnext.x - fthis.y; |
|
|
|
|
|
|
|
|
|
double crise = cnext.y - cthis.y; |
|
|
|
|
double crun = cnext.x - cthis.y; |
|
|
|
|
|
|
|
|
|
fseg->collision_shape[0].x = 0; |
|
|
|
|
fseg->collision_shape[0].y = 0; |
|
|
|
|
|
|
|
|
|
fseg->collision_shape[1].x = frun; |
|
|
|
|
fseg->collision_shape[1].y = frise; |
|
|
|
|
|
|
|
|
|
fseg->collision_shape[2].x = frun; |
|
|
|
|
fseg->collision_shape[2].y = frise + FLOOR_THICKNESS; |
|
|
|
|
|
|
|
|
|
fseg->collision_shape[3].x = 0; |
|
|
|
|
fseg->collision_shape[3].y = frise + FLOOR_THICKNESS; |
|
|
|
|
|
|
|
|
|
cseg->collision_shape[0].x = 0; |
|
|
|
|
cseg->collision_shape[0].y = 0; |
|
|
|
|
|
|
|
|
|
cseg->collision_shape[1].x = crun; |
|
|
|
|
cseg->collision_shape[1].y = crise; |
|
|
|
|
|
|
|
|
|
cseg->collision_shape[2].x = crun; |
|
|
|
|
cseg->collision_shape[2].y = crise - FLOOR_THICKNESS; |
|
|
|
|
|
|
|
|
|
cseg->collision_shape[3].x = 0; |
|
|
|
|
cseg->collision_shape[3].y = crise - FLOOR_THICKNESS; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
world_thing room_world; |
|
|
|
|
room_world.kind = ROOM_W; |
|
|
|
|
struct room* room = malloc(sizeof(struct room)); |
|
|
|
|
room->ceil = ceil; |
|
|
|
|
room->floor = floor; |
|
|
|
|
room_world.room = room; |
|
|
|
|
|
|
|
|
|
add_to_world(room_world); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Wall *get_long_wall(int numNodes, int *nodes) { |
|
|
|
|
Wall wall; |
|
|
|
|
memset(&wall, 0, sizeof(wall)); |
|
|
|
@ -1043,6 +1135,7 @@ bool unique_world_kind(enum world_thing_kind k) {
@@ -1043,6 +1135,7 @@ bool unique_world_kind(enum world_thing_kind k) {
|
|
|
|
|
case PLAYER_W: |
|
|
|
|
case FLOOR: |
|
|
|
|
case CEILING: |
|
|
|
|
case ROOM_W: |
|
|
|
|
return true; |
|
|
|
|
default: |
|
|
|
|
return false; |
|
|
|
@ -1054,6 +1147,7 @@ void add_to_world(world_thing thing) {
@@ -1054,6 +1147,7 @@ void add_to_world(world_thing thing) {
|
|
|
|
|
if (world.size == world.capacity) { |
|
|
|
|
logwrite(INFO, "Increased world size."); |
|
|
|
|
world.things = realloc(world.things, sizeof(world_thing) * (world.size*=2)); |
|
|
|
|
// man dodgy and unfinished
|
|
|
|
|
if (unique_world_kind(thing.kind)) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1124,6 +1218,8 @@ void startgame(SDL_Renderer * ren) {
@@ -1124,6 +1218,8 @@ void startgame(SDL_Renderer * ren) {
|
|
|
|
|
logwrite(INFO, "STARTGAME"); |
|
|
|
|
get_input_map(); |
|
|
|
|
|
|
|
|
|
level = 0; |
|
|
|
|
|
|
|
|
|
world = create_world(); |
|
|
|
|
|
|
|
|
|
SDL_GetRendererOutputSize(ren, &width, &height); |
|
|
|
@ -1143,7 +1239,8 @@ void startgame(SDL_Renderer * ren) {
@@ -1143,7 +1239,8 @@ void startgame(SDL_Renderer * ren) {
|
|
|
|
|
viewport_pos.x = 700; |
|
|
|
|
viewport_pos.y = 0; |
|
|
|
|
|
|
|
|
|
get_room(); |
|
|
|
|
get_floor_ceiling();
|
|
|
|
|
//get_room();
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double get_abs(double x,double y) { |
|
|
|
@ -1206,5 +1303,12 @@ void handle_input_event(SDL_Event event) {
@@ -1206,5 +1303,12 @@ void handle_input_event(SDL_Event event) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void step(int interval) {
|
|
|
|
|
if (player.physics->position.x > world.uniques_index[ROOM_W]->room |
|
|
|
|
->floor.items[world.uniques_index[ROOM_W]->room->floor.numItems - 1]->position.x) { |
|
|
|
|
next_level(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("%f %f", player.physics->position.x, 0.9 * world.uniques_index[ROOM_W]->room->floor.items[world.uniques_index[ROOM_W]->room->floor.numItems - 1]->position.x); |
|
|
|
|
|
|
|
|
|
advance_things(); |
|
|
|
|
} |
|
|
|
|