Merge spice into damage so on collisin player hurt

main
Cameron Murphy Reikes 2 years ago
parent 08144acd52
commit a92656699d

@ -470,7 +470,7 @@ static cpBool on_damage(cpArbiter* arb, cpSpace* space, cpDataPointer userData)
entity_a = cp_shape_entity(a);
entity_b = cp_shape_entity(b);
float damage = V2length(cp_to_v2(cpArbiterTotalImpulse(arb))) * 0.25f;
float damage = V2length(cp_to_v2(cpArbiterTotalImpulse(arb))) * COLLISION_DAMAGE_SCALING;
if (damage > 0.05f)
{
// Log("Collision with damage %f\n", damage);
@ -776,7 +776,6 @@ void ser_entity(SerState* ser, GameState* gs, Entity* e)
if (e->is_player)
{
ser_entityid(ser, &e->currently_inside_of_box);
SER_VAR(&e->spice_taken_away);
SER_VAR(&e->goldness);
}
@ -1036,7 +1035,7 @@ void process(GameState* gs, float dt)
if (V2length(V2sub(cp_to_v2(cpBodyGetPosition(p->body)), gs->goldpos)) < GOLD_COLLECT_RADIUS)
{
p->goldness += 0.1f;
p->spice_taken_away = 0.0f;
p->damage = 0.0f;
gs->goldpos = (V2){ .x = hash11((float)gs->time) * 20.0f, .y = hash11((float)gs->time - 13.6f) * 20.0f };
}
@ -1090,7 +1089,7 @@ void process(GameState* gs, float dt)
{
cpShapeSetFilter(p->shape, PLAYER_SHAPE_FILTER);
cpBodyApplyForceAtWorldPoint(p->body, v2_to_cp(V2scale(player->input.movement, PLAYER_JETPACK_FORCE)), cpBodyGetPosition(p->body));
p->spice_taken_away += movement_strength * dt * PLAYER_JETPACK_SPICE_PER_SECOND;
p->damage += movement_strength * dt * PLAYER_JETPACK_SPICE_PER_SECOND;
}
else
{
@ -1134,14 +1133,14 @@ void process(GameState* gs, float dt)
{
Entity* cur_box = cp_shape_entity(nearest);
Entity* cur_grid = cp_body_entity(cpShapeGetBody(nearest));
p->spice_taken_away -= SPICE_PER_BLOCK*((BATTERY_CAPACITY - cur_box->energy_used)/BATTERY_CAPACITY);
p->damage -= DAMAGE_TO_PLAYER_PER_BLOCK*((BATTERY_CAPACITY - cur_box->energy_used)/BATTERY_CAPACITY);
grid_remove_box(gs, cur_grid, cur_box);
}
else if (target_grid == NULL)
{
Entity* new_grid = new_entity(gs);
grid_create(gs, new_grid);
p->spice_taken_away += 0.1f;
p->damage += DAMAGE_TO_PLAYER_PER_BLOCK;
entity_set_pos(new_grid, world_build);
Entity* new_box = new_entity(gs);
@ -1157,17 +1156,17 @@ void process(GameState* gs, float dt)
grid_correct_for_holes(gs, target_grid); // no holey ship for you!
new_box->box_type = player->input.build_type;
new_box->compass_rotation = player->input.build_rotation;
p->spice_taken_away += SPICE_PER_BLOCK;
p->damage += DAMAGE_TO_PLAYER_PER_BLOCK;
}
}
#endif
if (p->spice_taken_away >= 1.0f)
if (p->damage >= 1.0f)
{
entity_destroy(gs, p);
player->entity = (EntityID){ 0 };
}
p->spice_taken_away = clamp01(p->spice_taken_away);
p->damage = clamp01(p->damage);
}
// process entities
@ -1246,10 +1245,10 @@ void process(GameState* gs, float dt)
Entity* potential_meatbag_to_heal = get_entity(gs, cur->player_who_is_inside_of_me);
if (potential_meatbag_to_heal != NULL)
{
float energy_to_recharge = min(potential_meatbag_to_heal->spice_taken_away, PLAYER_ENERGY_RECHARGE_PER_SECOND * dt);
float energy_to_recharge = min(potential_meatbag_to_heal->damage, PLAYER_ENERGY_RECHARGE_PER_SECOND * dt);
if (possibly_use_energy(gs, e, energy_to_recharge))
{
potential_meatbag_to_heal->spice_taken_away -= energy_to_recharge;
potential_meatbag_to_heal->damage -= energy_to_recharge;
}
}
}

@ -288,10 +288,10 @@ ui(bool draw, float dt, float width, float height)
// if(draw) sgp_scale(1.0f, -1.0f);
// draw spice bar
if (draw) {
static float spice_taken_away = 0.5f;
static float damage = 0.5f;
if (myentity() != NULL) {
spice_taken_away = myentity()->spice_taken_away;
damage = myentity()->damage;
}
sgp_set_color(0.5f, 0.5f, 0.5f, cur_opacity);
@ -300,7 +300,7 @@ ui(bool draw, float dt, float width, float height)
sgp_draw_filled_rect(margin, 80.0f, bar_width, 30.0f);
sgp_set_color(1.0f, 1.0f, 1.0f, cur_opacity);
sgp_draw_filled_rect(
margin, 80.0f, bar_width * (1.0f - spice_taken_away), 30.0f);
margin, 80.0f, bar_width * (1.0f - damage), 30.0f);
}
// draw item toolbar

@ -6,11 +6,13 @@
#define PLAYER_SIZE ((V2){.x = BOX_SIZE, .y = BOX_SIZE})
#define PLAYER_MASS 0.5f
#define PLAYER_JETPACK_FORCE 2.0f
#define PLAYER_JETPACK_SPICE_PER_SECOND 0.3f
//#define PLAYER_JETPACK_SPICE_PER_SECOND 0.3f
#define PLAYER_JETPACK_SPICE_PER_SECOND 0.0f
#define MAX_HAND_REACH 1.0f
#define GOLD_COLLECT_RADIUS 0.3f
#define BUILD_BOX_SNAP_DIST_TO_SHIP 0.2f
#define BOX_MASS 1.0f
#define COLLISION_DAMAGE_SCALING 0.1f
#define THRUSTER_FORCE 4.0f
#define THRUSTER_ENERGY_USED_PER_SECOND 0.05f
#define VISION_RADIUS 16.0f
@ -20,8 +22,8 @@
#define SUN_POS ((V2){50.0f,0.0f})
#define SUN_GRAVITY_STRENGTH (5.0e3f)
#define SOLAR_ENERGY_PER_SECOND 0.02f
#define SPICE_PER_BLOCK 0.1f
#define BATTERY_CAPACITY SPICE_PER_BLOCK
#define DAMAGE_TO_PLAYER_PER_BLOCK 0.1f
#define BATTERY_CAPACITY DAMAGE_TO_PLAYER_PER_BLOCK
#define PLAYER_ENERGY_RECHARGE_PER_SECOND 0.1f
#define TIMESTEP (1.0f / 60.0f) // not required to simulate at this, but this defines what tick the game is on
@ -137,7 +139,6 @@ typedef struct Entity
cpBody* body; // used by grid, player, and box
cpShape* shape; // must be a box so shape_size can be set appropriately, and serialized
// for serializing the shape
// @Robust remove shape_parent_entity from this struct, use the shape's body to figure out
// what the shape's parent entity is
@ -147,7 +148,6 @@ typedef struct Entity
// player
bool is_player;
EntityID currently_inside_of_box;
float spice_taken_away; // at 1.0, out of spice
float goldness; // how much the player is a winner
// grids

Loading…
Cancel
Save