Skip to content

Commit 53d9f32

Browse files
authored
Merge pull request #319 from Kinvert/whisker_racer_fixes2
Whisker Racer Leaving Track and Mini Map
2 parents d0861c3 + f2a9db1 commit 53d9f32

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

pufferlib/ocean/whisker_racer/whisker_racer.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ void reset_round(WhiskerRacer* env) {
242242
}
243243

244244
void c_reset(WhiskerRacer* env) {
245+
compute_observations(env);
245246
env->score = 0;
246247
reset_round(env);
247248
env->tick = 0;
248-
compute_observations(env);
249249
}
250250

251251
// Line segment intersection helper function
@@ -354,6 +354,13 @@ void calc_whisker_lengths(WhiskerRacer* env) {
354354
c_reset(env);
355355
}
356356
}
357+
358+
if (*lengths[0] >= 0.99f && *lengths[1] >= 0.99f) { // Car probably left the track
359+
for (int j = 0; j < 2; j++) *lengths[j] = 0.0f;
360+
env->terminals[0] = 1;
361+
add_log(env);
362+
c_reset(env);
363+
}
357364
}
358365

359366
void update_radial_progress(WhiskerRacer* env) {
@@ -755,6 +762,7 @@ void Mode7(WhiskerRacer* env, RenderTexture2D mode7RenderTexture) {
755762
int height = env->height;
756763
int width = env->width;
757764
float inv_width = env->inv_width;
765+
float inv_height = env->inv_height;
758766

759767
int horizon = height / 2;
760768

@@ -766,6 +774,8 @@ void Mode7(WhiskerRacer* env, RenderTexture2D mode7RenderTexture) {
766774

767775
float height9 = 9.0f * height;
768776

777+
DrawRectangle(0, horizon, width, height-horizon, DARKGREEN);
778+
769779
for (int screenY = horizon; screenY < height; screenY += 3) {
770780
float row = (float)(screenY - horizon);
771781

@@ -798,6 +808,33 @@ void Mode7(WhiskerRacer* env, RenderTexture2D mode7RenderTexture) {
798808
UnloadImageColors(pixels);
799809
UnloadImage(sceneImage);
800810

811+
int minimap_width = width * 0.333f;
812+
int minimap_height = height * 0.333f;
813+
int minimap_x = width - minimap_width;
814+
int minimap_y = 0;
815+
816+
DrawTexturePro(
817+
scene,
818+
(Rectangle){0, 0, width, -height},
819+
(Rectangle){minimap_x, minimap_y, minimap_width, minimap_height},
820+
(Vector2){0, 0},
821+
0,
822+
WHITE
823+
);
824+
825+
float minimap_puffer_size = 8.0f;
826+
float minimap_px = minimap_x + (env->px * inv_width) * minimap_width;
827+
float minimap_py = minimap_y + ((height - env->py) * inv_height) * minimap_height;
828+
829+
DrawTexturePro(
830+
env->puffer,
831+
(Rectangle){0, 0, 128, 128},
832+
(Rectangle){minimap_px, minimap_py, minimap_puffer_size, minimap_puffer_size},
833+
(Vector2){minimap_puffer_size / 2.0f, minimap_puffer_size / 2.0f},
834+
(-env->ang * 180.0f / PI) - 10,
835+
WHITE
836+
);
837+
801838
EndDrawing();
802839
}
803840

@@ -866,7 +903,6 @@ void c_render(WhiskerRacer* env) {
866903
}
867904

868905
Vector2* center_points = malloc(sizeof(Vector2) * (env->track.total_points + 3));
869-
//center_points[0] = (Vector2){SCREEN_WIDTH*0.5f, SCREEN_HEIGHT*0.5f};
870906
for (int i = 0; i < env->track.total_points; i++) {
871907
center_points[i] = env->track.centerline[i];
872908
center_points[i].y = env->height - center_points[i].y;

0 commit comments

Comments
 (0)