diff --git a/milepost b/milepost index 23984e8..ff5a57f 160000 --- a/milepost +++ b/milepost @@ -1 +1 @@ -Subproject commit 23984e8370816c3f324af6ae58172c7be9ada32f +Subproject commit ff5a57fb92c301bb706dc87adb55a0ea17ac18b3 diff --git a/samples/pong/data/ball.png b/samples/pong/data/ball.png index c918ee5..4294de2 100644 Binary files a/samples/pong/data/ball.png and b/samples/pong/data/ball.png differ diff --git a/samples/pong/src/main.c b/samples/pong/src/main.c index 7795bb8..78289a7 100644 --- a/samples/pong/src/main.c +++ b/samples/pong/src/main.c @@ -16,7 +16,7 @@ const f32 BLOCK_WIDTH = (BLOCKS_WIDTH - ((NUM_BLOCKS_PER_ROW + 1) * BLOCKS_PADDI #define PADDLE_MAX_LAUNCH_ANGLE 0.7f const mg_color paddleColor = {1, 0, 0, 1}; -mp_rect paddle = {BLOCKS_WIDTH/2 - 100, 40, 200, 40}; +mp_rect paddle = {300, 50, 200, 24}; const mg_color ballColor = {1, 1, 0, 1}; mp_rect ball = {200, 200, 20, 20}; @@ -51,6 +51,7 @@ mg_surface mg_surface_main(void); f32 lerp(f32 a, f32 b, f32 t); mp_rect blockRect(int i); int checkCollision(mp_rect block); +mg_mat2x3 flipY(mp_rect r); mg_mat2x3 flipYAt(vec2 pos); str8 loadFile(mem_arena* arena, str8 filename) { @@ -252,11 +253,21 @@ ORCA_EXPORT void OnFrameRefresh(void) } mp_rect r = blockRect(i); + mg_set_color_rgba(0, 0, 0, 0.2); + mg_rounded_rectangle_fill(r.x, r.y-2, r.w, r.h, 4); mg_set_color_rgba(0.9, 0.9, 0.9, 1); mg_rounded_rectangle_fill(r.x, r.y, r.w, r.h, 4); - // TODO: measure and center text - vec2 textPos = {r.x + r.w/2 - 5, r.y + 9}; + int fontSize = 18; + str8 text = str8_pushf(mem_scratch(), + "%d", blockHealth[i] + ); + mp_rect textRect = mg_text_bounding_box(pongFont, fontSize, text); + + vec2 textPos = { + r.x + r.w/2 - textRect.w/2, + r.y + 9, // TODO: mg_text_bounding_box is returning extremely wack results for height. + }; mg_set_color_rgba(0, 0, 0, 1); mg_set_font(pongFont); @@ -264,17 +275,20 @@ ORCA_EXPORT void OnFrameRefresh(void) mg_move_to(textPos.x, textPos.y); mg_matrix_push(flipYAt(textPos)); { - str8 text = str8_pushf(mem_scratch(), - "%d", blockHealth[i] - ); mg_text_outlines(text); mg_fill(); } mg_matrix_pop(); } - mg_image_draw(paddleImage, paddle); - mg_image_draw(ballImage, ball); + mg_set_color_rgba(0.9, 0.9, 0.9, 1); + mg_rounded_rectangle_fill(paddle.x, paddle.y, paddle.w, paddle.h, 4); + + mg_matrix_push(flipY(ball)); + { + mg_image_draw(ballImage, ball); + } + mg_matrix_pop(); } mg_matrix_pop(); @@ -423,6 +437,13 @@ f32 lerp(f32 a, f32 b, f32 t) { return (1 - t) * a + t * b; } +mg_mat2x3 flipY(mp_rect r) { + return (mg_mat2x3){ + 1, 0, 0, + 0, -1, 2 * r.y + r.h, + }; +} + mg_mat2x3 flipYAt(vec2 pos) { return (mg_mat2x3){ 1, 0, 0,