Make pong prettier
This commit is contained in:
parent
6e2457ded3
commit
e2a2116cb2
2
milepost
2
milepost
|
@ -1 +1 @@
|
||||||
Subproject commit 23984e8370816c3f324af6ae58172c7be9ada32f
|
Subproject commit ff5a57fb92c301bb706dc87adb55a0ea17ac18b3
|
Binary file not shown.
Before Width: | Height: | Size: 490 KiB After Width: | Height: | Size: 60 KiB |
|
@ -16,7 +16,7 @@ const f32 BLOCK_WIDTH = (BLOCKS_WIDTH - ((NUM_BLOCKS_PER_ROW + 1) * BLOCKS_PADDI
|
||||||
#define PADDLE_MAX_LAUNCH_ANGLE 0.7f
|
#define PADDLE_MAX_LAUNCH_ANGLE 0.7f
|
||||||
|
|
||||||
const mg_color paddleColor = {1, 0, 0, 1};
|
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};
|
const mg_color ballColor = {1, 1, 0, 1};
|
||||||
mp_rect ball = {200, 200, 20, 20};
|
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);
|
f32 lerp(f32 a, f32 b, f32 t);
|
||||||
mp_rect blockRect(int i);
|
mp_rect blockRect(int i);
|
||||||
int checkCollision(mp_rect block);
|
int checkCollision(mp_rect block);
|
||||||
|
mg_mat2x3 flipY(mp_rect r);
|
||||||
mg_mat2x3 flipYAt(vec2 pos);
|
mg_mat2x3 flipYAt(vec2 pos);
|
||||||
|
|
||||||
str8 loadFile(mem_arena* arena, str8 filename) {
|
str8 loadFile(mem_arena* arena, str8 filename) {
|
||||||
|
@ -252,11 +253,21 @@ ORCA_EXPORT void OnFrameRefresh(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_rect r = blockRect(i);
|
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_set_color_rgba(0.9, 0.9, 0.9, 1);
|
||||||
mg_rounded_rectangle_fill(r.x, r.y, r.w, r.h, 4);
|
mg_rounded_rectangle_fill(r.x, r.y, r.w, r.h, 4);
|
||||||
|
|
||||||
// TODO: measure and center text
|
int fontSize = 18;
|
||||||
vec2 textPos = {r.x + r.w/2 - 5, r.y + 9};
|
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_color_rgba(0, 0, 0, 1);
|
||||||
mg_set_font(pongFont);
|
mg_set_font(pongFont);
|
||||||
|
@ -264,19 +275,22 @@ ORCA_EXPORT void OnFrameRefresh(void)
|
||||||
mg_move_to(textPos.x, textPos.y);
|
mg_move_to(textPos.x, textPos.y);
|
||||||
mg_matrix_push(flipYAt(textPos));
|
mg_matrix_push(flipYAt(textPos));
|
||||||
{
|
{
|
||||||
str8 text = str8_pushf(mem_scratch(),
|
|
||||||
"%d", blockHealth[i]
|
|
||||||
);
|
|
||||||
mg_text_outlines(text);
|
mg_text_outlines(text);
|
||||||
mg_fill();
|
mg_fill();
|
||||||
}
|
}
|
||||||
mg_matrix_pop();
|
mg_matrix_pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
mg_image_draw(paddleImage, paddle);
|
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_image_draw(ballImage, ball);
|
||||||
}
|
}
|
||||||
mg_matrix_pop();
|
mg_matrix_pop();
|
||||||
|
}
|
||||||
|
mg_matrix_pop();
|
||||||
|
|
||||||
mg_surface_prepare(surface);
|
mg_surface_prepare(surface);
|
||||||
mg_render(surface, canvas);
|
mg_render(surface, canvas);
|
||||||
|
@ -423,6 +437,13 @@ f32 lerp(f32 a, f32 b, f32 t) {
|
||||||
return (1 - t) * a + t * b;
|
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) {
|
mg_mat2x3 flipYAt(vec2 pos) {
|
||||||
return (mg_mat2x3){
|
return (mg_mat2x3){
|
||||||
1, 0, 0,
|
1, 0, 0,
|
||||||
|
|
Loading…
Reference in New Issue