Finish medbay

main
Cameron Murphy Reikes 2 years ago
parent ca2e4196d9
commit 3fa6f9d933

@ -215,7 +215,7 @@ void create_body(GameState* gs, Entity* e)
V2 player_vel(GameState* gs, Entity* player) V2 player_vel(GameState* gs, Entity* player)
{ {
assert(player->is_player); assert(player->is_player);
Entity* potential_seat = get_entity(gs, player->currently_piloting_seat); Entity* potential_seat = get_entity(gs, player->currently_inside_of_box);
if (potential_seat != NULL) if (potential_seat != NULL)
{ {
return cp_to_v2(cpBodyGetVelocity(get_entity(gs, potential_seat->shape_parent_entity)->body)); return cp_to_v2(cpBodyGetVelocity(get_entity(gs, potential_seat->shape_parent_entity)->body));
@ -775,7 +775,7 @@ void ser_entity(SerState* ser, GameState* gs, Entity* e)
SER_VAR(&e->is_player); SER_VAR(&e->is_player);
if (e->is_player) if (e->is_player)
{ {
ser_entityid(ser, &e->currently_piloting_seat); ser_entityid(ser, &e->currently_inside_of_box);
SER_VAR(&e->spice_taken_away); SER_VAR(&e->spice_taken_away);
SER_VAR(&e->goldness); SER_VAR(&e->goldness);
} }
@ -798,7 +798,7 @@ void ser_entity(SerState* ser, GameState* gs, Entity* e)
SER_VAR(&e->wanted_thrust); SER_VAR(&e->wanted_thrust);
SER_VAR(&e->energy_used); SER_VAR(&e->energy_used);
SER_VAR(&e->sun_amount); SER_VAR(&e->sun_amount);
ser_entityid(ser, &e->piloted_by); ser_entityid(ser, &e->player_who_is_inside_of_me);
} }
} }
@ -835,7 +835,7 @@ void ser_server_to_client(SerState* ser, ServerToClient* s)
for (size_t i = 0; i < gs->cur_next_entity; i++) for (size_t i = 0; i < gs->cur_next_entity; i++)
{ {
Entity* e = &gs->entities[i]; Entity* e = &gs->entities[i];
if (e->exists) if (e->exists && !e->is_box) // boxes are serialized after their parent entities, their grid.
{ {
SER_VAR(&entities_done); SER_VAR(&entities_done);
SER_VAR(&i); SER_VAR(&i);
@ -1045,8 +1045,8 @@ void process(GameState* gs, float dt)
if (player->input.seat_action) if (player->input.seat_action)
{ {
player->input.seat_action = false; // "handle" the input player->input.seat_action = false; // "handle" the input
Entity* the_seat = get_entity(gs, p->currently_piloting_seat); Entity* the_seat = get_entity(gs, p->currently_inside_of_box);
if (the_seat == NULL) // not piloting any seat if (the_seat == NULL) // not in any seat
{ {
cpPointQueryInfo query_info = { 0 }; cpPointQueryInfo query_info = { 0 };
cpShape* result = cpSpacePointQueryNearest(gs->space, v2_to_cp(world_hand_pos), 0.1f, cpShapeFilterNew(CP_NO_GROUP, CP_ALL_CATEGORIES, BOXES), &query_info); cpShape* result = cpSpacePointQueryNearest(gs->space, v2_to_cp(world_hand_pos), 0.1f, cpShapeFilterNew(CP_NO_GROUP, CP_ALL_CATEGORIES, BOXES), &query_info);
@ -1054,16 +1054,15 @@ void process(GameState* gs, float dt)
{ {
Entity* potential_seat = cp_shape_entity(result); Entity* potential_seat = cp_shape_entity(result);
assert(potential_seat->is_box); assert(potential_seat->is_box);
if (potential_seat->box_type == BoxCockpit) if (potential_seat->box_type == BoxCockpit || potential_seat->box_type == BoxMedbay) // @Robust check by feature flag instead of box type
{ {
p->currently_piloting_seat = get_id(gs, potential_seat); p->currently_inside_of_box = get_id(gs, potential_seat);
potential_seat->piloted_by = get_id(gs, p); potential_seat->player_who_is_inside_of_me = get_id(gs, p);
} }
} }
else else
{ {
Log("No seat to get into for a player at point %f %f\n", world_hand_pos.x, world_hand_pos.y);
Log("No ship above player at point %f %f\n", world_hand_pos.x, world_hand_pos.y);
} }
} }
else else
@ -1071,8 +1070,8 @@ void process(GameState* gs, float dt)
V2 pilot_seat_exit_spot = V2add(box_pos(the_seat), V2scale(box_facing_vector(the_seat), BOX_SIZE)); V2 pilot_seat_exit_spot = V2add(box_pos(the_seat), V2scale(box_facing_vector(the_seat), BOX_SIZE));
cpBodySetPosition(p->body, v2_to_cp(pilot_seat_exit_spot)); cpBodySetPosition(p->body, v2_to_cp(pilot_seat_exit_spot));
cpBodySetVelocity(p->body, v2_to_cp(player_vel(gs, p))); cpBodySetVelocity(p->body, v2_to_cp(player_vel(gs, p)));
the_seat->piloted_by = (EntityID){ 0 }; the_seat->player_who_is_inside_of_me = (EntityID){ 0 };
p->currently_piloting_seat = (EntityID){ 0 }; p->currently_inside_of_box = (EntityID){ 0 };
} }
} }
#endif #endif
@ -1085,9 +1084,9 @@ void process(GameState* gs, float dt)
{ {
player->input.movement = V2scale(V2normalize(player->input.movement), clamp(V2length(player->input.movement), 0.0f, 1.0f)); player->input.movement = V2scale(V2normalize(player->input.movement), clamp(V2length(player->input.movement), 0.0f, 1.0f));
} }
Entity* piloting_seat = get_entity(gs, p->currently_piloting_seat); Entity* seat_inside_of = get_entity(gs, p->currently_inside_of_box);
if (piloting_seat == NULL) if (seat_inside_of == NULL)
{ {
cpShapeSetFilter(p->shape, PLAYER_SHAPE_FILTER); cpShapeSetFilter(p->shape, PLAYER_SHAPE_FILTER);
cpBodyApplyForceAtWorldPoint(p->body, v2_to_cp(V2scale(player->input.movement, PLAYER_JETPACK_FORCE)), cpBodyGetPosition(p->body)); cpBodyApplyForceAtWorldPoint(p->body, v2_to_cp(V2scale(player->input.movement, PLAYER_JETPACK_FORCE)), cpBodyGetPosition(p->body));
@ -1095,12 +1094,13 @@ void process(GameState* gs, float dt)
} }
else else
{ {
cpShapeSetFilter(p->shape, CP_SHAPE_FILTER_NONE); // no collisions while going to pilot seat assert(seat_inside_of->is_box);
cpBodySetPosition(p->body, v2_to_cp(box_pos(piloting_seat))); cpShapeSetFilter(p->shape, CP_SHAPE_FILTER_NONE); // no collisions while in a seat
cpBodySetPosition(p->body, v2_to_cp(box_pos(seat_inside_of)));
// set thruster thrust from movement // set thruster thrust from movement
{ if(seat_inside_of->box_type == BoxCockpit) {
Entity* g = get_entity(gs, piloting_seat->shape_parent_entity); Entity* g = get_entity(gs, seat_inside_of->shape_parent_entity);
V2 target_direction = { 0 }; V2 target_direction = { 0 };
if (V2length(player->input.movement) > 0.0f) if (V2length(player->input.movement) > 0.0f)
@ -1236,15 +1236,15 @@ void process(GameState* gs, float dt)
cpBodyApplyForceAtWorldPoint(e->body, v2_to_cp(thruster_force(cur)), v2_to_cp(box_pos(cur))); cpBodyApplyForceAtWorldPoint(e->body, v2_to_cp(thruster_force(cur)), v2_to_cp(box_pos(cur)));
} }
} }
if (cur->box_type == BoxCockpit) if (cur->box_type == BoxMedbay)
{ {
Entity* potential_pilot = get_entity(gs, cur->piloted_by); Entity* potential_meatbag_to_heal = get_entity(gs, cur->player_who_is_inside_of_me);
if (potential_pilot != NULL && potential_pilot->spice_taken_away) if (potential_meatbag_to_heal != NULL)
{ {
float energy_to_recharge = min(potential_pilot->spice_taken_away, PLAYER_ENERGY_RECHARGE_PER_SECOND * dt); float energy_to_recharge = min(potential_meatbag_to_heal->spice_taken_away, PLAYER_ENERGY_RECHARGE_PER_SECOND * dt);
if (possibly_use_energy(gs, e, energy_to_recharge)) if (possibly_use_energy(gs, e, energy_to_recharge))
{ {
potential_pilot->spice_taken_away -= energy_to_recharge; potential_meatbag_to_heal->spice_taken_away -= energy_to_recharge;
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

@ -53,6 +53,7 @@ static sg_image image_cockpit_used;
static sg_image image_stars; static sg_image image_stars;
static sg_image image_stars2; static sg_image image_stars2;
static sg_image image_sun; static sg_image image_sun;
static sg_image image_medbay_used;
static int cur_editing_boxtype = -1; static int cur_editing_boxtype = -1;
static int cur_editing_rotation = 0; static int cur_editing_rotation = 0;
@ -82,6 +83,10 @@ static struct BoxInfo {
.type = BoxCockpit, .type = BoxCockpit,
.image_path = "loaded/cockpit.png", .image_path = "loaded/cockpit.png",
}, },
{
.type = BoxMedbay,
.image_path = "loaded/medbay.png",
},
}; };
const int boxes_len = sizeof(boxes) / sizeof(*boxes); const int boxes_len = sizeof(boxes) / sizeof(*boxes);
@ -165,6 +170,7 @@ init(void)
image_stars = load_image("loaded/stars.png"); image_stars = load_image("loaded/stars.png");
image_stars2 = load_image("loaded/stars2.png"); image_stars2 = load_image("loaded/stars2.png");
image_sun = load_image("loaded/sun.png"); image_sun = load_image("loaded/sun.png");
image_medbay_used = load_image("loaded/medbay_used.png");
} }
// socket initialization // socket initialization
@ -737,10 +743,14 @@ frame(void)
sg_image img = boxinfo(b->box_type).image; sg_image img = boxinfo(b->box_type).image;
if (b->box_type == BoxCockpit) if (b->box_type == BoxCockpit)
{ {
if (get_entity(&gs, b->piloted_by) != NULL) if (get_entity(&gs, b->player_who_is_inside_of_me) != NULL)
img = image_cockpit_used; img = image_cockpit_used;
} }
if (b->box_type == BoxMedbay)
{
if (get_entity(&gs, b->player_who_is_inside_of_me) != NULL)
img = image_medbay_used;
}
sgp_set_image(0, img); sgp_set_image(0, img);
draw_texture_centered(box_pos(b), BOX_SIZE); draw_texture_centered(box_pos(b), BOX_SIZE);
sgp_reset_image(0); sgp_reset_image(0);
@ -764,7 +774,7 @@ frame(void)
V2 to = V2add(grid_com(g), vel); V2 to = V2add(grid_com(g), vel);
sgp_draw_line(grid_com(g).x, grid_com(g).y, to.x, to.y); sgp_draw_line(grid_com(g).x, grid_com(g).y, to.x, to.y);
} }
if (e->is_player && get_entity(&gs, e->currently_piloting_seat) == NULL) { if (e->is_player && get_entity(&gs, e->currently_inside_of_box) == NULL) {
transform_scope transform_scope
{ {
sgp_rotate_at(entity_rotation(e), entity_pos(e).x, entity_pos(e).y); sgp_rotate_at(entity_rotation(e), entity_pos(e).x, entity_pos(e).y);

@ -81,6 +81,7 @@ enum BoxType
BoxThruster, BoxThruster,
BoxBattery, BoxBattery,
BoxCockpit, BoxCockpit,
BoxMedbay,
BoxSolarPanel, BoxSolarPanel,
BoxLast, BoxLast,
}; };
@ -143,7 +144,7 @@ typedef struct Entity
// player // player
bool is_player; bool is_player;
EntityID currently_piloting_seat; EntityID currently_inside_of_box;
float spice_taken_away; // at 1.0, out of spice float spice_taken_away; // at 1.0, out of spice
float goldness; // how much the player is a winner float goldness; // how much the player is a winner
@ -162,7 +163,7 @@ typedef struct Entity
float thrust; // the actual thrust it can provide based on energy sources in the grid float thrust; // the actual thrust it can provide based on energy sources in the grid
float energy_used; // battery float energy_used; // battery
float sun_amount; // solar panel, between 0 and 1 float sun_amount; // solar panel, between 0 and 1
EntityID piloted_by; EntityID player_who_is_inside_of_me;
} Entity; } Entity;
typedef struct Player typedef struct Player

Loading…
Cancel
Save