From 3fa6f9d933b2446bfaeb4c0c56cfd1c2f08a1cdf Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Sun, 6 Nov 2022 11:19:29 -0800 Subject: [PATCH] Finish medbay --- gamestate.c | 48 ++++++++++++++++++++--------------------- loaded/medbay.png | Bin 0 -> 5560 bytes loaded/medbay_used.png | Bin 0 -> 5652 bytes main.c | 16 +++++++++++--- types.h | 5 +++-- 5 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 loaded/medbay.png create mode 100644 loaded/medbay_used.png diff --git a/gamestate.c b/gamestate.c index 7a7b8fe..194f3a0 100644 --- a/gamestate.c +++ b/gamestate.c @@ -215,7 +215,7 @@ void create_body(GameState* gs, Entity* e) V2 player_vel(GameState* gs, Entity* 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) { 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); 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->goldness); } @@ -798,7 +798,7 @@ void ser_entity(SerState* ser, GameState* gs, Entity* e) SER_VAR(&e->wanted_thrust); SER_VAR(&e->energy_used); 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++) { 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(&i); @@ -1045,8 +1045,8 @@ void process(GameState* gs, float dt) if (player->input.seat_action) { player->input.seat_action = false; // "handle" the input - Entity* the_seat = get_entity(gs, p->currently_piloting_seat); - if (the_seat == NULL) // not piloting any seat + Entity* the_seat = get_entity(gs, p->currently_inside_of_box); + if (the_seat == NULL) // not in any seat { 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); @@ -1054,16 +1054,15 @@ void process(GameState* gs, float dt) { Entity* potential_seat = cp_shape_entity(result); 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); - potential_seat->piloted_by = get_id(gs, p); + p->currently_inside_of_box = get_id(gs, potential_seat); + potential_seat->player_who_is_inside_of_me = get_id(gs, p); } } else { - - Log("No ship above player at point %f %f\n", world_hand_pos.x, world_hand_pos.y); + Log("No seat to get into for a player at point %f %f\n", world_hand_pos.x, world_hand_pos.y); } } 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)); cpBodySetPosition(p->body, v2_to_cp(pilot_seat_exit_spot)); cpBodySetVelocity(p->body, v2_to_cp(player_vel(gs, p))); - the_seat->piloted_by = (EntityID){ 0 }; - p->currently_piloting_seat = (EntityID){ 0 }; + the_seat->player_who_is_inside_of_me = (EntityID){ 0 }; + p->currently_inside_of_box = (EntityID){ 0 }; } } #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)); } - 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); 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 { - cpShapeSetFilter(p->shape, CP_SHAPE_FILTER_NONE); // no collisions while going to pilot seat - cpBodySetPosition(p->body, v2_to_cp(box_pos(piloting_seat))); + assert(seat_inside_of->is_box); + 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 - { - Entity* g = get_entity(gs, piloting_seat->shape_parent_entity); + if(seat_inside_of->box_type == BoxCockpit) { + Entity* g = get_entity(gs, seat_inside_of->shape_parent_entity); V2 target_direction = { 0 }; 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))); } } - if (cur->box_type == BoxCockpit) + if (cur->box_type == BoxMedbay) { - Entity* potential_pilot = get_entity(gs, cur->piloted_by); - if (potential_pilot != NULL && potential_pilot->spice_taken_away) + 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_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)) { - potential_pilot->spice_taken_away -= energy_to_recharge; + potential_meatbag_to_heal->spice_taken_away -= energy_to_recharge; } } } diff --git a/loaded/medbay.png b/loaded/medbay.png new file mode 100644 index 0000000000000000000000000000000000000000..41dd9abc83bf6cf224f2651e7ef5f6cd6e04336f GIT binary patch literal 5560 zcmeHKc{o)28=q{IrG%0#(;$>%c4p=pk-dyP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x2xPDTY)0K<|rMm{zjIX5ks5(18PbRP* z7G7_eZ2r_f;cl&2@zBiYnd?&nwz!?!Uw<{rAQZS)YtT1e+iJ%Q-tW*Nsp)YE7Bpq#hcZihI?|_sM=Bl~m7G}U-tfn*J39*PcV%{$ zHpJ>(J#8G57JrNv9Ub+|1m9u2MII-qh>7y2W;mQO+mX|*+heR-YFQGUh0>PYwk=5( zUe5Yyolk4qrI$Mm9{W}K{dU|NF+18EzovqH zSLKwyKc$(N%sABd=31k8I;&;yamNJZwzr1Q95%E5*sN`PF2C!iIHP8yt}R+Y#7>-0mF{NoL> z0jNwbhK77NKwEyl`o#Ipr5k&9Yy8p8-b|DBMA5`^D#8*9c+p-Tg>gwKX$LMFL7|%m zb7l|k%r{%2e6;A|`x$jd107Y@QpW*+(k9f_*4@e0_H$FlTJfHBDHiMt);cwT%S!U6 z+n8-(@eaCbSCe)2|7L&8{qDpgtjy(uDxBFnv}QP-FKKVDHc@}tIV-AHQwnbK<>_`dX73t~?N3MoVd3YJVQbjAjPxqspP2K_nr5io}0a9DOCI8+gylbr=#F+YnZf>9o8t*(v6ukI)e$0@%KR_QmhsgtRRI%85T{hu~F^FbKi=$ESk*Y)Aj07`QZ$&!cl`L>dFc>ItDSiCiuS z68TIj7o;(PFog)QHy}B7RO&aq$z$psQ_^|7eqK6(X~^7qFt}>Q&1^inNK9D58A#lH>y752I=`6m8|eCDbD}pyLort@pio4#HL1Now*QvYk8RnkN2ImSldcn z5a@De#`cEf+sbZ~*u&HA4CVPfS*qVlbox_type).image; 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; } - + 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); draw_texture_centered(box_pos(b), BOX_SIZE); sgp_reset_image(0); @@ -764,7 +774,7 @@ frame(void) V2 to = V2add(grid_com(g), vel); 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 { sgp_rotate_at(entity_rotation(e), entity_pos(e).x, entity_pos(e).y); diff --git a/types.h b/types.h index 0092223..540c8cb 100644 --- a/types.h +++ b/types.h @@ -81,6 +81,7 @@ enum BoxType BoxThruster, BoxBattery, BoxCockpit, + BoxMedbay, BoxSolarPanel, BoxLast, }; @@ -143,7 +144,7 @@ typedef struct Entity // player bool is_player; - EntityID currently_piloting_seat; + EntityID currently_inside_of_box; float spice_taken_away; // at 1.0, out of spice 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 energy_used; // battery float sun_amount; // solar panel, between 0 and 1 - EntityID piloted_by; + EntityID player_who_is_inside_of_me; } Entity; typedef struct Player