|
|
|
@ -146,6 +146,31 @@ void get_new_physics(Body **phys) {
@@ -146,6 +146,31 @@ void get_new_physics(Body **phys) {
|
|
|
|
|
/*physics->collision_poly[0].y = physics->y_pos;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int string_update_fixed(String *string) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int string_set_end(String *string, void *setting) { |
|
|
|
|
string->end_point = *(Vect *)setting; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String *get_fixed_strings(int number) { |
|
|
|
|
String *strings = calloc(number, sizeof(String));
|
|
|
|
|
for (int i = 0; i < number; i++) { |
|
|
|
|
|
|
|
|
|
strings[i].attached = false; |
|
|
|
|
|
|
|
|
|
// takes self (String) and does nothing.
|
|
|
|
|
strings[i].update_end_point = string_update_fixed;
|
|
|
|
|
|
|
|
|
|
// takes self and vect to set string end point
|
|
|
|
|
strings[i].set_end_point = string_set_end;
|
|
|
|
|
} |
|
|
|
|
return strings; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
player_st get_player(int x, int y) { |
|
|
|
|
/* creates player at given postion and zeroes physics */ |
|
|
|
|
|
|
|
|
@ -176,6 +201,19 @@ player_st get_player(int x, int y) {
@@ -176,6 +201,19 @@ player_st get_player(int x, int y) {
|
|
|
|
|
|
|
|
|
|
player.physics->updateCollisionPoly = cast_update_collision_poly; |
|
|
|
|
|
|
|
|
|
// swing rope
|
|
|
|
|
player.physics->num_strings = 1; |
|
|
|
|
player.physics->max_strings = 1; |
|
|
|
|
player.physics->strings = get_fixed_strings(1); |
|
|
|
|
player.physics->strings->max_length = 890; |
|
|
|
|
|
|
|
|
|
// testing
|
|
|
|
|
Vect end_pt; |
|
|
|
|
end_pt.x = -100; |
|
|
|
|
end_pt.y = 0; |
|
|
|
|
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; |
|
|
|
|
rect[1].x = 10; rect[1].y = -10; |
|
|
|
@ -183,7 +221,8 @@ player_st get_player(int x, int y) {
@@ -183,7 +221,8 @@ player_st get_player(int x, int y) {
|
|
|
|
|
rect[3].x = -10; rect[3].y = 10; |
|
|
|
|
|
|
|
|
|
// gravity
|
|
|
|
|
set_motor_newtons(player.physics, M_GRAVITY, 0.0, player.physics->obj_mass * 4); |
|
|
|
|
set_motor_newtons(player.physics, M_GRAVITY, 0.0,
|
|
|
|
|
player.physics->obj_mass * 4); |
|
|
|
|
|
|
|
|
|
// walking motor
|
|
|
|
|
add_motor(player.physics, 0.0, player.physics->obj_mass * 9.81); |
|
|
|
@ -602,7 +641,6 @@ void advance_thing(Body * thing) {
@@ -602,7 +641,6 @@ void advance_thing(Body * thing) {
|
|
|
|
|
thing->updateCollisionPoly(thing); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thing->updateCollisionPoly(thing); |
|
|
|
|
Vect translation; |
|
|
|
|
Vect friction; |
|
|
|
@ -663,6 +701,63 @@ void advance_thing(Body * thing) {
@@ -663,6 +701,63 @@ void advance_thing(Body * thing) {
|
|
|
|
|
/*accel_thing(thing, rest.x, rest.y);*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < thing->num_strings; i++) { |
|
|
|
|
if (!thing->strings[i].attached) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double st_len = vect_distance(thing->next_position, thing->strings[i].end_point); |
|
|
|
|
double max_len = thing->strings[i].max_length; |
|
|
|
|
if (st_len > max_len) { |
|
|
|
|
|
|
|
|
|
printf("STRING: %f, %f\n", st_len, max_len); |
|
|
|
|
|
|
|
|
|
Vect end = thing->strings[i].end_point; |
|
|
|
|
Vect position = thing->next_position; |
|
|
|
|
|
|
|
|
|
Vect string; |
|
|
|
|
string.x = end.x - position.x; |
|
|
|
|
string.y = end.y - position.y; |
|
|
|
|
|
|
|
|
|
double disp = st_len - max_len; |
|
|
|
|
double angle = atan2(string.y, string.x); |
|
|
|
|
double scale_factor = max_len / vect_mag(string); |
|
|
|
|
|
|
|
|
|
Vect corrected_string; |
|
|
|
|
corrected_string.x = cos(angle) * max_len; |
|
|
|
|
corrected_string.y = sin(angle) * max_len; |
|
|
|
|
printf("corrected string : %f %f\n", corrected_string.x, corrected_string.y); |
|
|
|
|
thing->next_position = vect_scalar(thing->next_position,
|
|
|
|
|
scale_factor); |
|
|
|
|
|
|
|
|
|
/*thing->next_position.x += cos(angle) * disp;*/ |
|
|
|
|
/*thing->next_position.y += sin(angle) * disp;*/ |
|
|
|
|
|
|
|
|
|
// move the thing back to the right position
|
|
|
|
|
/*Vect adj_pos = vect_add(vect_scalar(corrected_string, -1),*/ |
|
|
|
|
/*string);*/ |
|
|
|
|
/*adj_pos = vect_scalar(adj_pos, -1);*/ |
|
|
|
|
/*thing->position = vect_add(thing->position, adj_pos);*/ |
|
|
|
|
|
|
|
|
|
// set velocity to 0 in direction of string
|
|
|
|
|
Vect vel_correction = project_vect(thing->vel, string); |
|
|
|
|
double dir; |
|
|
|
|
double corr = vect_scalar_projection(thing->vel, string); |
|
|
|
|
if (corr < 0) { |
|
|
|
|
corr *= -1; |
|
|
|
|
}
|
|
|
|
|
Vect v_corr; |
|
|
|
|
v_corr.y = corr * sin(angle); |
|
|
|
|
v_corr.x = corr * cos(angle); |
|
|
|
|
|
|
|
|
|
thing->vel = vect_add(v_corr, thing->vel); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint32_t now = SDL_GetTicks(); |
|
|
|
|
|
|
|
|
|
uint32_t time_delta = now - thing->last_advance_time ; |
|
|
|
@ -799,9 +894,7 @@ void add_to_world(world_thing thing) {
@@ -799,9 +894,7 @@ void add_to_world(world_thing thing) {
|
|
|
|
|
memcpy(world + things_in_world, &thing, sizeof(world_thing)); |
|
|
|
|
|
|
|
|
|
things_in_world += 1; |
|
|
|
|
|
|
|
|
|
//printf("Added to world: %d\n", thing.kind);
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void get_room(void) { |
|
|
|
@ -835,7 +928,7 @@ void startgame(SDL_Renderer * ren) {
@@ -835,7 +928,7 @@ void startgame(SDL_Renderer * ren) {
|
|
|
|
|
memset(world, 0, sizeof(world_thing) * 100); |
|
|
|
|
SDL_GetRendererOutputSize(ren, &width, &height); |
|
|
|
|
|
|
|
|
|
player = get_player(500,500); |
|
|
|
|
player = get_player(100,1000); |
|
|
|
|
|
|
|
|
|
world_thing player_world; |
|
|
|
|
|
|
|
|
|