|
|
@ -1805,11 +1805,30 @@ float batteries_use_energy(GameState *gs, Entity *grid, float *energy_left_over,
|
|
|
|
return energy_to_use;
|
|
|
|
return energy_to_use;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float sun_gravity_at_point(V2 p)
|
|
|
|
float entity_mass(Entity *m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (m->body != NULL)
|
|
|
|
|
|
|
|
return (float)cpBodyGetMass(m->body);
|
|
|
|
|
|
|
|
else if (m->is_box)
|
|
|
|
|
|
|
|
return BOX_MASS;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
assert(false);
|
|
|
|
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float sun_gravity_accel_at_point(V2 p, Entity *entity_with_gravity)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (V2length(V2sub(p, SUN_POS)) > SUN_NO_MORE_ELECTRICITY_OR_GRAVITY)
|
|
|
|
if (V2length(V2sub(p, SUN_POS)) > SUN_NO_MORE_ELECTRICITY_OR_GRAVITY)
|
|
|
|
return 0.0f;
|
|
|
|
return 0.0f;
|
|
|
|
return SUN_GRAVITY_STRENGTH;
|
|
|
|
V2 rel_vector = V2sub(entity_pos(entity_with_gravity), SUN_POS);
|
|
|
|
|
|
|
|
float mass = entity_mass(entity_with_gravity);
|
|
|
|
|
|
|
|
assert(mass != 0.0f);
|
|
|
|
|
|
|
|
float distance = V2length(rel_vector);
|
|
|
|
|
|
|
|
// return (GRAVITY_CONSTANT * (SUN_MASS * mass / (distance * distance))) / mass;
|
|
|
|
|
|
|
|
// the mass divides out
|
|
|
|
|
|
|
|
return (GRAVITY_CONSTANT * (SUN_MASS / (distance * distance)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void entity_ensure_in_orbit(Entity *e)
|
|
|
|
void entity_ensure_in_orbit(Entity *e)
|
|
|
@ -1818,7 +1837,7 @@ void entity_ensure_in_orbit(Entity *e)
|
|
|
|
|
|
|
|
|
|
|
|
cpVect pos = v2_to_cp(V2sub(entity_pos(e), SUN_POS));
|
|
|
|
cpVect pos = v2_to_cp(V2sub(entity_pos(e), SUN_POS));
|
|
|
|
cpFloat r = cpvlength(pos);
|
|
|
|
cpFloat r = cpvlength(pos);
|
|
|
|
cpFloat v = cpfsqrt(sun_gravity_at_point(cp_to_v2(pos)) / r) / r;
|
|
|
|
cpFloat v = cpfsqrt(sun_gravity_accel_at_point(cp_to_v2(pos), e) / r) / r;
|
|
|
|
cpBodySetVelocity(e->body, cpvmult(cpvperp(pos), v));
|
|
|
|
cpBodySetVelocity(e->body, cpvmult(cpvperp(pos), v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1848,7 +1867,6 @@ void create_bomb_station(GameState *gs, V2 pos, enum BoxType platonic_type)
|
|
|
|
Entity *grid = new_entity(gs);
|
|
|
|
Entity *grid = new_entity(gs);
|
|
|
|
grid_create(gs, grid);
|
|
|
|
grid_create(gs, grid);
|
|
|
|
entity_set_pos(grid, pos);
|
|
|
|
entity_set_pos(grid, pos);
|
|
|
|
entity_ensure_in_orbit(grid);
|
|
|
|
|
|
|
|
Entity *platonic_box = new_entity(gs);
|
|
|
|
Entity *platonic_box = new_entity(gs);
|
|
|
|
box_create(gs, platonic_box, grid, (V2){0});
|
|
|
|
box_create(gs, platonic_box, grid, (V2){0});
|
|
|
|
platonic_box->box_type = platonic_type;
|
|
|
|
platonic_box->box_type = platonic_type;
|
|
|
@ -1875,6 +1893,8 @@ void create_bomb_station(GameState *gs, V2 pos, enum BoxType platonic_type)
|
|
|
|
BOX_AT_TYPE(grid, ((V2){-BOX_SIZE * 6.0, -BOX_SIZE * 2.0}), BoxExplosive);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){-BOX_SIZE * 6.0, -BOX_SIZE * 2.0}), BoxExplosive);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){-BOX_SIZE * 6.0, -BOX_SIZE * 3.0}), BoxExplosive);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){-BOX_SIZE * 6.0, -BOX_SIZE * 3.0}), BoxExplosive);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){-BOX_SIZE * 6.0, -BOX_SIZE * 5.0}), BoxExplosive);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){-BOX_SIZE * 6.0, -BOX_SIZE * 5.0}), BoxExplosive);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entity_ensure_in_orbit(grid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void create_hard_shell_station(GameState *gs, V2 pos, enum BoxType platonic_type)
|
|
|
|
void create_hard_shell_station(GameState *gs, V2 pos, enum BoxType platonic_type)
|
|
|
@ -1886,7 +1906,6 @@ void create_hard_shell_station(GameState *gs, V2 pos, enum BoxType platonic_type
|
|
|
|
Entity *grid = new_entity(gs);
|
|
|
|
Entity *grid = new_entity(gs);
|
|
|
|
grid_create(gs, grid);
|
|
|
|
grid_create(gs, grid);
|
|
|
|
entity_set_pos(grid, pos);
|
|
|
|
entity_set_pos(grid, pos);
|
|
|
|
entity_ensure_in_orbit(grid);
|
|
|
|
|
|
|
|
Entity *platonic_box = new_entity(gs);
|
|
|
|
Entity *platonic_box = new_entity(gs);
|
|
|
|
box_create(gs, platonic_box, grid, (V2){0});
|
|
|
|
box_create(gs, platonic_box, grid, (V2){0});
|
|
|
|
platonic_box->box_type = platonic_type;
|
|
|
|
platonic_box->box_type = platonic_type;
|
|
|
@ -1906,6 +1925,7 @@ void create_hard_shell_station(GameState *gs, V2 pos, enum BoxType platonic_type
|
|
|
|
BOX_AT_TYPE(grid, ((V2){x, BOX_SIZE * 5.0}), BoxHullpiece);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){x, BOX_SIZE * 5.0}), BoxHullpiece);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){x, -BOX_SIZE * 5.0}), BoxHullpiece);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){x, -BOX_SIZE * 5.0}), BoxHullpiece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entity_ensure_in_orbit(grid);
|
|
|
|
indestructible = false;
|
|
|
|
indestructible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void create_initial_world(GameState *gs)
|
|
|
|
void create_initial_world(GameState *gs)
|
|
|
@ -1928,11 +1948,11 @@ void create_initial_world(GameState *gs)
|
|
|
|
grid_create(gs, grid);
|
|
|
|
grid_create(gs, grid);
|
|
|
|
entity_set_pos(grid, V2add(from, V2rotate((V2){.x = -BOX_SIZE * 9.0f}, theta)));
|
|
|
|
entity_set_pos(grid, V2add(from, V2rotate((V2){.x = -BOX_SIZE * 9.0f}, theta)));
|
|
|
|
cpBodySetAngle(grid->body, theta + PI);
|
|
|
|
cpBodySetAngle(grid->body, theta + PI);
|
|
|
|
entity_ensure_in_orbit(grid);
|
|
|
|
|
|
|
|
rot = Left;
|
|
|
|
rot = Left;
|
|
|
|
BOX_AT_TYPE(grid, ((V2){0.0f, 0.0f}), BoxMerge);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){0.0f, 0.0f}), BoxMerge);
|
|
|
|
BOX_AT(grid, ((V2){0.0f, -BOX_SIZE}));
|
|
|
|
BOX_AT(grid, ((V2){0.0f, -BOX_SIZE}));
|
|
|
|
BOX_AT_TYPE(grid, ((V2){BOX_SIZE, 0.0f}), BoxMerge);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){BOX_SIZE, 0.0f}), BoxMerge);
|
|
|
|
|
|
|
|
entity_ensure_in_orbit(grid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1940,7 +1960,6 @@ void create_initial_world(GameState *gs)
|
|
|
|
grid_create(gs, grid);
|
|
|
|
grid_create(gs, grid);
|
|
|
|
entity_set_pos(grid, from);
|
|
|
|
entity_set_pos(grid, from);
|
|
|
|
cpBodySetAngle(grid->body, theta);
|
|
|
|
cpBodySetAngle(grid->body, theta);
|
|
|
|
entity_ensure_in_orbit(grid);
|
|
|
|
|
|
|
|
rot = Left;
|
|
|
|
rot = Left;
|
|
|
|
BOX_AT_TYPE(grid, ((V2){-BOX_SIZE, 0.0f}), BoxMerge);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){-BOX_SIZE, 0.0f}), BoxMerge);
|
|
|
|
rot = Down;
|
|
|
|
rot = Down;
|
|
|
@ -1948,6 +1967,7 @@ void create_initial_world(GameState *gs)
|
|
|
|
rot = Up;
|
|
|
|
rot = Up;
|
|
|
|
BOX_AT_TYPE(grid, ((V2){0.0f, BOX_SIZE}), BoxMerge);
|
|
|
|
BOX_AT_TYPE(grid, ((V2){0.0f, BOX_SIZE}), BoxMerge);
|
|
|
|
cpBodySetVelocity(grid->body, v2_to_cp(V2rotate((V2){-0.4f, 0.0f}, theta)));
|
|
|
|
cpBodySetVelocity(grid->body, v2_to_cp(V2rotate((V2){-0.4f, 0.0f}, theta)));
|
|
|
|
|
|
|
|
entity_ensure_in_orbit(grid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
create_bomb_station(gs, (V2){-50.0f, 0.0f}, BoxExplosive);
|
|
|
|
create_bomb_station(gs, (V2){-50.0f, 0.0f}, BoxExplosive);
|
|
|
@ -2297,7 +2317,7 @@ void process(GameState *gs, float dt)
|
|
|
|
|
|
|
|
|
|
|
|
if (e->body != NULL)
|
|
|
|
if (e->body != NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cpVect g = cpvmult(pos_rel_sun, -sun_gravity_at_point(entity_pos(e)) / (sqdist * cpfsqrt(sqdist)));
|
|
|
|
cpVect g = cpvmult(pos_rel_sun, -sun_gravity_accel_at_point(entity_pos(e), e) / (sqdist * cpfsqrt(sqdist)));
|
|
|
|
cpBodyUpdateVelocity(e->body, g, 1.0f, dt);
|
|
|
|
cpBodyUpdateVelocity(e->body, g, 1.0f, dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|