|
|
|
@ -162,8 +162,8 @@ int string_update_fixed(String *string) {
@@ -162,8 +162,8 @@ int string_update_fixed(String *string) {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int string_set_end(String *string, void *setting) { |
|
|
|
|
string->end_point = *(Vect *)setting; |
|
|
|
|
int string_set_end(String *string, Vect *setting) { |
|
|
|
|
string->end_point = *setting; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -218,12 +218,6 @@ player_st get_player(int x, int y) {
@@ -218,12 +218,6 @@ player_st get_player(int x, int y) {
|
|
|
|
|
player.physics->strings = get_fixed_strings(1); |
|
|
|
|
player.physics->strings->max_length = 210; |
|
|
|
|
|
|
|
|
|
// testing
|
|
|
|
|
Vect end_pt; |
|
|
|
|
end_pt.x = 2000;
|
|
|
|
|
end_pt.y = 3000; |
|
|
|
|
player.physics->strings[0].set_end_point(player.physics->strings, &end_pt); |
|
|
|
|
player.physics->strings[0].attached = true; |
|
|
|
|
|
|
|
|
|
Vect *rect = player.physics->collision_shape; |
|
|
|
|
rect[0].x = -10; rect[0].y = -10; |
|
|
|
@ -578,6 +572,23 @@ void add_motor(Body *thing, double x, double y) {
@@ -578,6 +572,23 @@ void add_motor(Body *thing, double x, double y) {
|
|
|
|
|
thing->num_motors += 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void add_rope(void) { |
|
|
|
|
// testing
|
|
|
|
|
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); |
|
|
|
|
player.physics->strings[0].attached = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void delete_rope(void) { |
|
|
|
|
// testing
|
|
|
|
|
player.physics->strings[0].attached = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// basic collision handler for testing
|
|
|
|
|
//
|
|
|
|
|
int process_collisions(Body *thing, Vect *trans) { |
|
|
|
@ -656,6 +667,8 @@ void advance_thing(Body * thing) {
@@ -656,6 +667,8 @@ void advance_thing(Body * thing) {
|
|
|
|
|
Vect friction; |
|
|
|
|
translation.x = translation.y = 0; |
|
|
|
|
int numcols = 0; |
|
|
|
|
|
|
|
|
|
// collisions
|
|
|
|
|
if ((numcols = process_collisions(thing, &translation))) { |
|
|
|
|
double mag = vect_mag(translation); |
|
|
|
|
|
|
|
|
@ -711,6 +724,7 @@ void advance_thing(Body * thing) {
@@ -711,6 +724,7 @@ void advance_thing(Body * thing) {
|
|
|
|
|
/*accel_thing(thing, rest.x, rest.y);*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// pendulums
|
|
|
|
|
for (int i = 0; i < thing->num_strings; i++) { |
|
|
|
|
if (!thing->strings[i].attached) { |
|
|
|
|
continue; |
|
|
|
@ -719,6 +733,7 @@ void advance_thing(Body * thing) {
@@ -719,6 +733,7 @@ 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); |
|
|
|
|
if (st_len > max_len) { |
|
|
|
|
Vect string_end = thing->strings[i].end_point; |
|
|
|
|
Vect thing_position = thing->next_position; |
|
|
|
@ -735,17 +750,15 @@ void advance_thing(Body * thing) {
@@ -735,17 +750,15 @@ void advance_thing(Body * thing) {
|
|
|
|
|
thing->next_position.x += cos(angle) * disp; |
|
|
|
|
thing->next_position.y += sin(angle) * disp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vect corrected_string; |
|
|
|
|
corrected_string.x = cos(angle) * max_len; |
|
|
|
|
corrected_string.y = sin(angle) * max_len; |
|
|
|
|
/*Vect corrected_string;*/ |
|
|
|
|
/*corrected_string.x = cos(angle) * max_len;*/ |
|
|
|
|
/*corrected_string.y = sin(angle) * max_len;*/ |
|
|
|
|
|
|
|
|
|
// set velocity to 0 in direction of string
|
|
|
|
|
double corr_mag = vect_scalar_projection(thing->vel, string); |
|
|
|
|
|
|
|
|
|
thing->vel.x -= corr_mag * cos(angle); |
|
|
|
|
thing->vel.y -= corr_mag * sin(angle); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -783,8 +796,6 @@ void advance_thing(Body * thing) {
@@ -783,8 +796,6 @@ void advance_thing(Body * thing) {
|
|
|
|
|
double acc_y = thing->motors[i].y / thing->obj_mass; |
|
|
|
|
accel_thing(thing, acc_x, acc_y); |
|
|
|
|
} |
|
|
|
|
// printf("\n diff angle: %f pi: %f \n", dirV - dirF, M_PI);
|
|
|
|
|
// printf("Vel: %f, Force: %f\n\n", dirV, dirF);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// accelerate based on accel
|
|
|
|
@ -824,31 +835,6 @@ void advance_thing(Body * thing) {
@@ -824,31 +835,6 @@ void advance_thing(Body * thing) {
|
|
|
|
|
thing->next_position.x += (thing->vel.x * 1/2 * (double)time_delta);
|
|
|
|
|
thing->next_position.y += (thing->vel.y * 1/2 * (double)time_delta);
|
|
|
|
|
|
|
|
|
|
// revert if this caused collision
|
|
|
|
|
/*if (process_collisions(thing)) {*/ |
|
|
|
|
/*thing->x_pos = oldx;*/ |
|
|
|
|
/*thing->y_pos = oldy;*/ |
|
|
|
|
/*thing->updateCollisionPoly(thing);*/ |
|
|
|
|
/*return;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
|
|
|
|
|
// wrap screen
|
|
|
|
|
/*if (thing->x_pos > width) {*/ |
|
|
|
|
/*thing->x_pos = 0;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
|
|
|
|
|
/*if (thing->y_pos > height) {*/ |
|
|
|
|
/*thing->y_pos = 0;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
|
|
|
|
|
/*if (thing->y_pos < 0) {*/ |
|
|
|
|
/*thing->y_pos = height;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
|
|
|
|
|
/*if (thing->x_pos < 0) {*/ |
|
|
|
|
/*thing->x_pos = width;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -967,13 +953,14 @@ void get_room(void) {
@@ -967,13 +953,14 @@ void get_room(void) {
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
SDL_GetRendererOutputSize(ren, &width, &height); |
|
|
|
|
|
|
|
|
|
player = get_player(2000,3000); |
|
|
|
|
player = get_player(200,300); |
|
|
|
|
|
|
|
|
|
world_thing player_world; |
|
|
|
|
|
|
|
|
@ -1008,6 +995,22 @@ void walk_player(int x, int y) {
@@ -1008,6 +995,22 @@ void walk_player(int x, int y) {
|
|
|
|
|
add_motor_newtons(glob_player->physics, M_PLAYER_WALK, 100 *10* x , 100 * y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void handle_input_event(SDL_Event event) { |
|
|
|
|
switch (event.type) { |
|
|
|
|
case SDL_KEYDOWN: |
|
|
|
|
if (event.key.keysym.scancode == input_map.player_rope) { |
|
|
|
|
add_rope(); |
|
|
|
|
printf("add rope\n"); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case SDL_KEYUP: |
|
|
|
|
if (event.key.keysym.scancode == input_map.player_rope) { |
|
|
|
|
delete_rope(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void step(int interval) {
|
|
|
|
|
const uint8_t * keyboard; |
|
|
|
|
keyboard = SDL_GetKeyboardState(NULL); |
|
|
|
|