@ -1,9 +1,10 @@
@@ -1,9 +1,10 @@
# include "game.h"
# include "environment.h"
# define FLOOR_THICKNESS 200
# define BREAKPOINT *(int *)0 = 1;
# define MAX_ROPE_GRAB_LEN 800
# define BREAKPOINT *(int *)0 = 1;
GlobWorld world ;
player_st * glob_player ;
@ -80,6 +81,11 @@ void default_motor_curve(Motor *motor) {
@@ -80,6 +81,11 @@ void default_motor_curve(Motor *motor) {
return ;
}
world_thing world_getter ( int i ) {
world_thing * item = arlst_get ( & world . items , i ) ;
return * item ;
}
FloorPoly * generate_floor_simple ( int num_polys , bool extend_down , int st_height ) {
FloorPoly * floor = calloc ( num_polys , sizeof ( FloorPoly ) ) ;
@ -504,9 +510,25 @@ bool check_collision(Body *one, Body *two, Vect *translation) {
@@ -504,9 +510,25 @@ bool check_collision(Body *one, Body *two, Vect *translation) {
}
}
void destroy_physics_body ( Body * b ) {
// collisions
Vect * collision_poly ;
Vect * collision_shape ;
int collision_poly_size ;
int collision_shape_size ;
void ( * updateCollisionPoly ) ( struct BodyStruct * ) ;
// applying forces
int num_strings ;
int max_strings ;
String * strings ;
}
void destroy_physics_collection ( struct physics_collection * s ) {
for ( int i = 0 ; i < s - > numItems ; i + + ) {
free ( s - > items [ i ] ) ;
if ( s - > items [ i ] ) {
//free(s->items[i]);
}
}
free ( s - > items ) ;
@ -519,19 +541,33 @@ void next_level() {
@@ -519,19 +541,33 @@ void next_level() {
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 ;
// destroy_physics_collection(&world.uniques_index[ROOM_W]->room->ceil);
// destroy_physics_collection(&world.uniques_index[ROOM_W]->room->floor);
int d = - 1 ;
for ( int i = 0 ; i < world . items . size ; i + + ) {
if ( world . get ( i ) . kind = = ROOM_W ) {
d = i ;
break ;
}
}
// still need to free world object
if ( d ! = - 1 ) {
world_thing * w = arlst_del ( & world . items , d ) ;
}
destroy_physics_collection ( & world . uniques_index [ ROOM_W ] - > room - > ceil ) ;
destroy_physics_collection ( & world . uniques_index [ ROOM_W ] - > room - > floor ) ;
destroy_environment ( & world . uniques_index [ ROOM_W ] - > room - > env ) ;
level + + ;
get_floor_ceiling ( ) ;
v = world . uniques_index [ ROOM_W ] - > room - > ceil . items [ 2 ] - > collision_poly [ 0 ] ;
v . y - = 30 ;
player . physics - > position = v ;
player . physics - > next_position = v ;
}
int get_floor_ceiling ( ) {
@ -613,6 +649,7 @@ int get_floor_ceiling() {
@@ -613,6 +649,7 @@ int get_floor_ceiling() {
room_world . room = room ;
add_to_world ( room_world ) ;
world . uniques_index [ ROOM_W ] - > room - > env = e ;
return 0 ;
}
@ -884,37 +921,37 @@ int process_collisions(Body *thing, Vect *trans) {
@@ -884,37 +921,37 @@ int process_collisions(Body *thing, Vect *trans) {
int num_cols = 0 ;
int num = 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 ) {
for ( int k = 0 ; k < world . items . size ; k + + ) {
if ( world . get ( k ) . kind = = STATIC_WALL_W
& & world . get ( k ) . wall - > physics - > uid ! = thing - > uid ) {
if ( ( world . get ( k ) . wall - > physics - > position . x - viewport_pos . x ) > ( width * 2 )
| | world . get ( k ) . wall - > physics - > position . x - viewport_pos . x < 0 ) {
continue ;
} else {
num + + ;
}
if ( check_collision ( world . things [ k ] . wall - > physics , thing , & temptrans ) ) {
if ( check_collision ( world . get ( k ) . wall - > physics , thing , & temptrans ) ) {
num + + ;
thing - > colliding = true ;
translation = vect_add ( translation , temptrans ) ;
}
} 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 ) {
} else if ( world . get ( k ) . kind = = FLOOR | | world . get ( k ) . kind = = CEILING ) {
for ( int i = 0 ; i < world . get ( k ) . floor - > numPolys ; i + + ) {
if ( ( world . get ( k ) . floor - > polys [ i ] . physics - > position . x - viewport_pos . x ) > ( 2 * width )
| | ( world . get ( k ) . floor - > polys [ i ] . physics - > position . x - viewport_pos . x ) < - width ) {
continue ;
} else {
num + + ;
}
if ( check_collision ( world . things [ k ] . floor - > polys [ i ] . physics , thing , & temptrans ) ) {
if ( check_collision ( world . get ( k ) . floor - > polys [ i ] . physics , thing , & temptrans ) ) {
num_cols + + ;
thing - > colliding = true ;
translation = vect_add ( translation , temptrans ) ;
}
}
} else if ( world . things [ k ] . kind = = ROOM_W ) {
for ( int i = 0 ; i < world . things [ k ] . room - > floor . numItems ; i + + ) {
Body * s = world . things [ k ] . room - > floor . items [ i ] ;
} else if ( world . get ( k ) . kind = = ROOM_W ) {
for ( int i = 0 ; i < world . get ( k ) . room - > floor . numItems ; i + + ) {
Body * s = world . get ( k ) . room - > floor . items [ i ] ;
if ( s - > position . x + E_ROOM_RES < viewport_pos . x ) {
continue ;
} else if ( s - > position . x > viewport_pos . x + width ) {
@ -930,8 +967,8 @@ int process_collisions(Body *thing, Vect *trans) {
@@ -930,8 +967,8 @@ int process_collisions(Body *thing, Vect *trans) {
}
}
for ( int i = 0 ; i < world . things [ k ] . room - > ceil . numItems ; i + + ) {
Body * s = world . things [ k ] . room - > ceil . items [ i ] ;
for ( int i = 0 ; i < world . get ( k ) . room - > ceil . numItems ; i + + ) {
Body * s = world . get ( k ) . room - > ceil . items [ i ] ;
if ( s - > position . x + E_ROOM_RES < viewport_pos . x ) {
continue ;
} else if ( s - > position . x > viewport_pos . x + width ) {
@ -1249,32 +1286,35 @@ void get_projectile(Projectile** proj) {
@@ -1249,32 +1286,35 @@ void get_projectile(Projectile** proj) {
void advance_things ( void ) {
int numcols ;
Vect translation ;
for ( int i = 0 ; i < world . size ; i + + ) {
switch ( world . things [ i ] . kind ) {
for ( int i = 0 ; i < world . items . size ; i + + ) {
switch ( world . get ( i ) . kind ) {
case PLAYER_W :
advance_thing ( ( world . things [ i ] . player - > physics ) ) ;
break ;
advance_thing ( ( world . get ( i ) . player - > physics ) ) ;
continue ;
case STATIC_WALL_W :
advance_thing ( world . things [ i ] . wall - > physics ) ;
break ;
advance_thing ( world . get ( i ) . wall - > physics ) ;
continue ;
case FLOOR :
break ;
/*for (int k = 0; k < world.things[i] .floor->numPolys; k++) {*/
/*advance_thing(world.things[i] .floor->polys[k].physics);*/
continue ;
/*for (int k = 0; k < world.get(i) .floor->numPolys; k++) {*/
/*advance_thing(world.get(i) .floor->polys[k].physics);*/
/*}*/
/*break;*/
case CEILING :
break ;
/*for (int k = 0; k < world.things[i] .floor->numPolys; k++) {*/
/*advance_thing(world.things[i] .floor->polys[k].physics);*/
continue ;
/*for (int k = 0; k < world.get(i) .floor->numPolys; k++) {*/
/*advance_thing(world.get(i) .floor->polys[k].physics);*/
/*}*/
/*break;*/
case PROJECTILE :
if ( ( numcols = process_collisions ( world . things [ i ] . projectile - > physics ,
if ( ( numcols = process_collisions ( world . get ( i ) . projectile - > physics ,
& translation ) ) ) {
world . things [ i ] . projectile - > on_collision ( world . things [ i ] . projectile ) ;
world . get ( i ) . projectile - > on_collision ( world . get ( i ) . projectile ) ;
}
world . things [ i ] . projectile - > on_step ( world . things [ i ] . projectile ) ;
world . get ( i ) . projectile - > on_step ( world . get ( i ) . projectile ) ;
continue ;
default :
continue ;
}
}
}
@ -1293,20 +1333,18 @@ bool unique_world_kind(enum world_thing_kind k) {
@@ -1293,20 +1333,18 @@ bool unique_world_kind(enum world_thing_kind k) {
// grow array of world things if needed
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 ) ) {
}
}
thing . nid = world . items . size ;
world_thing * t = calloc ( 1 , sizeof ( world_thing ) ) ;
memcpy ( t , & 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 ;
arlst_add ( & world . items , t ) ;
if ( unique_world_kind ( thing . kind ) ) {
void * ref = arlst_get ( & world . items , world . items . size - 1 ) ;
world . uniques_index [ thing . kind ] = ref ;
}
world . size + + ;
//printf("Added to world: %d\n", thing.kind);
printf ( " Added to world: %d \n " , thing . kind ) ;
}
/* Send a projectile from body in direction dir (in degrees) with the force of
@ -1355,11 +1393,9 @@ void get_room(void) {
@@ -1355,11 +1393,9 @@ void get_room(void) {
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 . items = new_arlst ( 100 ) ;
c . uniques_index = calloc ( 10 , sizeof ( world_thing * ) ) ;
c . get = world_getter ; // gross
return c ;
}