diff options
-rw-r--r-- | src/game.c | 1 | ||||
-rw-r--r-- | src/model.c | 3 | ||||
-rw-r--r-- | src/physics.c | 15 | ||||
-rw-r--r-- | src/render.c | 2 | ||||
-rw-r--r-- | src/types.h | 5 |
5 files changed, 21 insertions, 5 deletions
@@ -283,6 +283,7 @@ Game *game_new(int width, int height, GameOptions gameopts) { g->lander->y = 0.0; g->lander->z = -4.93; g->lander->landed = 1; + g->lander->recharging = 1; g->lander->yaw = deg2rad(210.0); g->lander->attribs = OBJ_GRAVITY; diff --git a/src/model.c b/src/model.c index dfd2e1b..1432f62 100644 --- a/src/model.c +++ b/src/model.c @@ -481,7 +481,8 @@ ModelInstance *model_instance_new(ModelContext *ctx, const char *name, RenderCon instance->vz = 0.0; instance->yaw = 0.0; instance->yawspeed = 0.0; - instance->landed = 0.0; + instance->landed = 0; + instance->recharging = 0; return instance; diff --git a/src/physics.c b/src/physics.c index 8299704..5b9c641 100644 --- a/src/physics.c +++ b/src/physics.c @@ -88,7 +88,7 @@ int physics_point_is_inside_hull(double cx, double cy, double cz, double *fvert, } int physics_will_collide_face(double sx, double sy, double sz, double vx, double vy, double vz, - double nx, double ny, double nz, double *fvert, int nfvert, Uint32 dt, + double nx, double ny, double nz, double *fvert, int nfvert, double dt, double *ttc) { double px, py, pz; @@ -124,7 +124,7 @@ int physics_will_collide_face(double sx, double sy, double sz, double vx, double } /* Check for collision with all faces in a primitive */ -static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *other, Uint32 dt, int a, +static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *other, double dt, int a, double sx, double sy, double sz, CollisionSpec *coll) { int found = 0; @@ -167,6 +167,7 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot coll->cx = obj->x + ttc*obj->vx; coll->cy = obj->y + ttc*obj->vy; coll->cz = obj->z + ttc*obj->vz; + coll->name = other->model->name; found = 1; } @@ -289,6 +290,7 @@ static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) { coll.ttc = +HUGE_VAL; coll.nx = 0.0; coll.ny = 0.0; coll.nz = 0.0; coll.cx = 0.0; coll.cy = 0.0; coll.cz = 0.0; + coll.name = NULL; collided = physics_find_earliest_collision(obj, game, dt-sttc, &coll); if ( collided ) { @@ -302,18 +304,26 @@ static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) { /* Can we land here? */ if ( (coll.nx==0) && (coll.ny==0) && (coll.nz==1.0) ) { + /* Yes - land (already moved to this position */ obj->landed = 1; obj->vx = 0.0; obj->vy = 0.0; obj->vz = 0.0; obj->yawspeed = 0.0; + + if ( strcmp(coll.name, "platform") == 0 ) { + obj->recharging = 1; + } + } else { + /* No - bounce */ audio_play(game->audio, "clang", 1.0, 0); obj->vx = -obj->vx; obj->vy = -obj->vy; obj->vz = -obj->vz; + } } else { @@ -345,6 +355,7 @@ void physics_step(Game *game, Uint32 t) { game->lander->vz += THRUST * dt; game->fuel -= 0.0002; game->lander->landed = 0; + game->lander->recharging = 0; } } if ( game->forward && !game->lander->landed ) { diff --git a/src/render.c b/src/render.c index 8de79e3..07a50e6 100644 --- a/src/render.c +++ b/src/render.c @@ -645,7 +645,7 @@ void render_draw(Game *game, Uint32 t) { glViewport(0, 0, 64, 64); if ( r->shaders ) glUseProgram(r->swirly_program); if ( r->shaders ) glUniform1f(glGetUniformLocation(game->render->swirly_program, "time"), t); - if ( r->shaders ) glUniform1i(glGetUniformLocation(game->render->swirly_program, "landed"), game->lander->landed); + if ( r->shaders ) glUniform1i(glGetUniformLocation(game->render->swirly_program, "landed"), game->lander->recharging); if ( r->shaders ) glUniform2f(glGetUniformLocation(game->render->swirly_program, "lander"), 0.5, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); diff --git a/src/types.h b/src/types.h index dcbc097..d57af18 100644 --- a/src/types.h +++ b/src/types.h @@ -112,7 +112,8 @@ typedef struct { float yaw; float yawspeed; - int landed; + int landed; /* Object has landed */ + int recharging; /* Object has landed on a platform, so is recharging */ } ModelInstance; @@ -266,6 +267,8 @@ typedef struct { double cz; /* Coordinates of object at the moment when it collides */ double ttc; + + char *name; /* Name of object being collided against */ } CollisionSpec; |