From 3ff13d5529c00cbaecbd0fd9b4994c345dd2d39c Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Sun, 11 Dec 2022 17:36:00 -0800 Subject: [PATCH] Account for spawn dist in missile lookahead --- buildsettings.h | 2 +- gamestate.c | 5 ++--- types.h | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/buildsettings.h b/buildsettings.h index feb161f..986bf42 100644 --- a/buildsettings.h +++ b/buildsettings.h @@ -17,7 +17,7 @@ // #define PROFILING #define DEBUG_RENDERING // #define DEBUG_WORLD -// #define UNLOCK_ALL +#define UNLOCK_ALL #define TIME_BETWEEN_WORLD_SAVE 1.0f // #define INFINITE_RESOURCES #define DEBUG_TOOLS diff --git a/gamestate.c b/gamestate.c index 3798f36..ea7f992 100644 --- a/gamestate.c +++ b/gamestate.c @@ -312,7 +312,7 @@ static void on_missile_shape(cpShape *shape, cpContactPointSet *points, void *da // lookahead by their velocity cpVect rel_velocity = cpvsub(entity_vel(gs, other), entity_vel(gs, launcher)); - double dist = cpvdist(entity_pos(other), entity_pos(launcher)); + double dist = cpvdist(entity_pos(other), entity_pos(launcher)) - MISSILE_SPAWN_DIST; double time_of_travel = sqrt((2.0 * dist) / (MISSILE_BURN_FORCE / MISSILE_MASS)); @@ -2902,8 +2902,7 @@ void process(struct GameState *gs, double dt) Entity *new_missile = new_entity(gs); create_missile(gs, new_missile); new_missile->owning_squad = cur_box->owning_squad; // missiles have teams and attack eachother! - double missile_spawn_dist = sqrt((BOX_SIZE / 2.0) * (BOX_SIZE / 2.0) * 2.0) + MISSILE_COLLIDER_SIZE.x / 2.0 + 0.1; - cpBodySetPosition(new_missile->body, (cpvadd(entity_pos(cur_box), cpvspin((cpVect){.x = missile_spawn_dist, 0.0}, target.facing_angle)))); + cpBodySetPosition(new_missile->body, (cpvadd(entity_pos(cur_box), cpvspin((cpVect){.x = MISSILE_SPAWN_DIST, 0.0}, target.facing_angle)))); cpBodySetAngle(new_missile->body, target.facing_angle); cpBodySetVelocity(new_missile->body, (box_vel(cur_box))); } diff --git a/types.h b/types.h index 63e94ec..208ff52 100644 --- a/types.h +++ b/types.h @@ -29,6 +29,7 @@ // centered on the sprite #define MISSILE_SPRITE_SIZE ((cpVect){.x = BOX_SIZE, .y = BOX_SIZE}) #define MISSILE_COLLIDER_SIZE ((cpVect){.x = BOX_SIZE * 0.5f, .y = BOX_SIZE * 0.5f}) +#define MISSILE_SPAWN_DIST (sqrt((BOX_SIZE / 2.0) * (BOX_SIZE / 2.0) * 2.0) + MISSILE_COLLIDER_SIZE.x / 2.0 + 0.1) #define PLAYER_JETPACK_ROTATION_ENERGY_PER_SECOND 0.2f #define PLAYER_JETPACK_SPICE_PER_SECOND 0.08f #define SCANNER_ENERGY_USE 0.05f