@@ -39,6 +39,11 @@ const Color FENCE_COLOR = {240, 210, 130, 255};
3939const Color COIN_COLOR = {240 , 210 , 130 , 255 };
4040const Color GROUND_COLOR = {128 , 227 , 153 , 255 };
4141
42+ const Color PUFF_RED = (Color ){187 , 0 , 0 , 255 };
43+ const Color PUFF_CYAN = (Color ){0 , 187 , 187 , 255 };
44+ const Color PUFF_WHITE = (Color ){241 , 241 , 241 , 241 };
45+ const Color PUFF_BACKGROUND = (Color ){6 , 24 , 24 , 255 };
46+
4247// UTILS
4348typedef struct {
4449 float x ;
@@ -62,6 +67,10 @@ float to_y_pixel(float y){
6267 return WINDOW_HEIGHT - y * FACTOR ;
6368}
6469
70+ float randf () {
71+ return (float )rand () / (float )RAND_MAX ;
72+ }
73+
6574// OBJECTS
6675typedef struct {
6776 float x ;
@@ -74,10 +83,6 @@ typedef struct {
7483 Color c ;
7584} Ball ;
7685
77- void ball_display (Ball * ball ){
78- DrawCircleV ((Vector2 ){to_x_pixel (ball -> x ), to_y_pixel (ball -> y )}, to_p (ball -> r ), ball -> c );
79- }
80-
8186void ball_move (Ball * ball ){
8287 ball -> prev_x = ball -> x ;
8388 ball -> prev_y = ball -> y ;
@@ -258,8 +263,8 @@ void agent_display(Agent *agent, float bx, float by) {
258263 float dist = sqrtf (ballX * ballX + ballY * ballY );
259264 float eyeX = 0 , eyeY = 0 ;
260265 if (dist > 0 ) {
261- float eyeX = ballX / dist ;
262- float eyeY = ballY / dist ;
266+ eyeX = ballX / dist ;
267+ eyeY = ballY / dist ;
263268 }
264269
265270 // Draw white of the eye
@@ -391,6 +396,7 @@ typedef struct {
391396 float * bot_observations ; // Optional, for bot control
392397 float * bot_actions ; // Optional, for bot control
393398 int tick ;
399+ Texture2D puffers ;
394400} SlimeVolley ;
395401
396402
@@ -417,8 +423,8 @@ void init(SlimeVolley* env) {
417423void c_reset (SlimeVolley * env ) {
418424 env -> tick = 0 ;
419425 env -> delay_frames = INIT_DELAY_FRAMES ;
420- float ball_vx = (( float ) rand () / RAND_MAX ) * 40.0f - 20.0f ;
421- float ball_vy = (( float ) rand () / RAND_MAX ) * 15.0f + 10.0f ;
426+ float ball_vx = 40.0f * randf () - 20.0f ;
427+ float ball_vy = 15.0f * randf () + 10.0f ;
422428 * env -> ball = (Ball ){
423429 .x = 0 ,
424430 .y = REF_W /4 ,
@@ -444,7 +450,7 @@ void c_reset(SlimeVolley* env) {
444450 .dir = i == 0 ? -1 : 1 ,
445451 .x = i == 0 ? - REF_W /4 : REF_W /4 ,
446452 .y = REF_U ,
447- .c = i == 0 ? AGENT_LEFT_COLOR : AGENT_RIGHT_COLOR ,
453+ .c = i == 0 ? PUFF_RED : PUFF_CYAN ,
448454 .r = 1.5 ,
449455 .lives = MAXLIVES ,
450456 .observations = observations
@@ -464,8 +470,8 @@ float clip(float val, float min, float max) {
464470}
465471
466472void new_match (SlimeVolley * env ) {
467- float ball_vx = (( float ) rand () / RAND_MAX ) * 40.0f - 20.0f ;
468- float ball_vy = (( float ) rand () / RAND_MAX ) * 15.0f + 10.0f ;
473+ float ball_vx = 40.0f * randf () - 20.0f ;
474+ float ball_vy = 15.0f * randf () + 10.0f ;
469475 * env -> ball = (Ball ){
470476 .x = 0 ,
471477 .y = REF_W /4 ,
@@ -575,20 +581,46 @@ void c_step(SlimeVolley* env) {
575581// Required function. Should handle creating the client on first call
576582void c_render (SlimeVolley * env ) {
577583 if (!IsWindowReady ()) {
584+ SetConfigFlags (FLAG_MSAA_4X_HINT );
578585 InitWindow (WINDOW_WIDTH , WINDOW_HEIGHT , "PufferLib SlimeVolley" );
579- SetTargetFPS (60 );
586+ SetTargetFPS (50 ); // From original
587+ env -> puffers = LoadTexture ("resources/shared/puffers.png" );
580588 }
581589
582590 // Standard across our envs so exiting is always the same
583591 if (IsKeyDown (KEY_ESCAPE )) {
584592 exit (0 );
585593 }
586594 BeginDrawing ();
587- ClearBackground (BACKGROUND_COLOR );
595+ ClearBackground (PUFF_BACKGROUND );
588596 wall_display (env -> ground );
589597 wall_display (env -> fence );
590- ball_display (env -> fence_stub );
591- ball_display (env -> ball );
598+
599+ // Fence
600+ Ball * stub = env -> fence_stub ;
601+ DrawCircleV (
602+ (Vector2 ){to_x_pixel (stub -> x ), to_y_pixel (stub -> y )},
603+ to_p (stub -> r ), stub -> c
604+ );
605+
606+ Ball * puff = env -> ball ;
607+ DrawTexturePro (
608+ env -> puffers ,
609+ (Rectangle ){
610+ 0 ,
611+ (puff -> vx > 0 ? 576 : 608 ),
612+ 32 , 32 ,
613+ },
614+ (Rectangle ){
615+ to_x_pixel (puff -> x ) - 16 ,
616+ to_y_pixel (puff -> y ) - 16 ,
617+ 32 ,
618+ 32
619+ },
620+ (Vector2 ){0 , 0 },
621+ 0 ,
622+ WHITE
623+ );
592624
593625 for (int i = 0 ; i < 2 ; i ++ ) {
594626 agent_display (& env -> agents [i ], env -> ball -> x , env -> ball -> y );
0 commit comments