oc_request_quit #55
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#define NUM_BLOCKS_PER_ROW 7
|
#define NUM_BLOCKS_PER_ROW 7
|
||||||
#define NUM_BLOCKS 42 // 7 * 6
|
#define NUM_BLOCKS 42 // 7 * 6
|
||||||
|
#define NUM_BLOCKS_TO_WIN (NUM_BLOCKS - 2)
|
||||||
|
|
||||||
#define BLOCKS_WIDTH 810.0f
|
#define BLOCKS_WIDTH 810.0f
|
||||||
#define BLOCK_HEIGHT 30.0f
|
#define BLOCK_HEIGHT 30.0f
|
||||||
|
@ -30,6 +31,7 @@ int blockHealth[NUM_BLOCKS] = {
|
||||||
3, 3, 3, 3, 3, 3, 3,
|
3, 3, 3, 3, 3, 3, 3,
|
||||||
3, 3, 3, 3, 3, 3, 3
|
3, 3, 3, 3, 3, 3, 3
|
||||||
};
|
};
|
||||||
|
int score = 0;
|
||||||
|
|
||||||
oc_vec2 frameSize = { 100, 100 };
|
oc_vec2 frameSize = { 100, 100 };
|
||||||
|
|
||||||
|
@ -98,6 +100,18 @@ ORCA_EXPORT void oc_on_init(void)
|
||||||
oc_arena_clear(oc_scratch());
|
oc_arena_clear(oc_scratch());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ORCA_EXPORT void oc_on_terminate(void)
|
||||||
|
{
|
||||||
|
if(score == NUM_BLOCKS_TO_WIN)
|
||||||
|
{
|
||||||
|
oc_log_info("you win!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
oc_log_info("goodbye world!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ORCA_EXPORT void oc_on_resize(u32 width, u32 height)
|
ORCA_EXPORT void oc_on_resize(u32 width, u32 height)
|
||||||
{
|
{
|
||||||
oc_log_info("frame resize %u, %u", width, height);
|
oc_log_info("frame resize %u, %u", width, height);
|
||||||
|
@ -219,6 +233,11 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
|
||||||
oc_log_info("Collision! direction=%d", result);
|
oc_log_info("Collision! direction=%d", result);
|
||||||
blockHealth[i] -= 1;
|
blockHealth[i] -= 1;
|
||||||
|
|
||||||
|
if(blockHealth[i] == 0)
|
||||||
|
{
|
||||||
|
++score;
|
||||||
|
}
|
||||||
|
|
||||||
f32 vx = velocity.x;
|
f32 vx = velocity.x;
|
||||||
f32 vy = velocity.y;
|
f32 vy = velocity.y;
|
||||||
|
|
||||||
|
@ -246,6 +265,11 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(score == NUM_BLOCKS_TO_WIN)
|
||||||
|
{
|
||||||
|
oc_request_quit();
|
||||||
|
}
|
||||||
|
|
||||||
oc_canvas_set_current(canvas);
|
oc_canvas_set_current(canvas);
|
||||||
|
|
||||||
oc_set_color_rgba(10.0f / 255.0f, 31.0f / 255.0f, 72.0f / 255.0f, 1);
|
oc_set_color_rgba(10.0f / 255.0f, 31.0f / 255.0f, 72.0f / 255.0f, 1);
|
||||||
|
@ -303,6 +327,20 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
|
||||||
oc_image_draw(ballImage, ball);
|
oc_image_draw(ballImage, ball);
|
||||||
}
|
}
|
||||||
oc_matrix_pop();
|
oc_matrix_pop();
|
||||||
|
|
||||||
|
// draw score text
|
||||||
|
{
|
||||||
|
oc_move_to(10, 10);
|
||||||
|
oc_str8 text = oc_str8_pushf(oc_scratch(), "Destroy all %d blocks to win! Current score: %d", NUM_BLOCKS_TO_WIN, score);
|
||||||
|
oc_rect textRect = oc_text_bounding_box(pongFont, 20, text);
|
||||||
|
oc_vec2 textPos = { 10, 10 };
|
||||||
|
oc_matrix_push(flipYAt(textPos));
|
||||||
|
{
|
||||||
|
oc_text_outlines(text);
|
||||||
|
oc_fill();
|
||||||
|
}
|
||||||
|
oc_matrix_pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
oc_matrix_pop();
|
oc_matrix_pop();
|
||||||
|
|
||||||
|
|
|
@ -400,6 +400,10 @@ extern "C"
|
||||||
|
|
||||||
ORCA_API int oc_directory_create(oc_str8 path);
|
ORCA_API int oc_directory_create(oc_str8 path);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void ORCA_IMPORT(oc_request_quit)(void);
|
||||||
|
|
||||||
#endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)
|
#endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -796,6 +796,15 @@ i32 orca_runloop(void* user)
|
||||||
oc_arena_clear(oc_scratch());
|
oc_arena_clear(oc_scratch());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(exports[OC_EXPORT_TERMINATE])
|
||||||
|
{
|
||||||
|
M3Result res = m3_Call(exports[OC_EXPORT_TERMINATE], 0, 0);
|
||||||
|
if(res)
|
||||||
|
{
|
||||||
|
ORCA_WASM3_ABORT(app->runtime.m3Runtime, res, "Runtime error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
X(OC_EXPORT_KEY_UP, "oc_on_key_up", "", "i") \
|
X(OC_EXPORT_KEY_UP, "oc_on_key_up", "", "i") \
|
||||||
X(OC_EXPORT_FRAME_REFRESH, "oc_on_frame_refresh", "", "") \
|
X(OC_EXPORT_FRAME_REFRESH, "oc_on_frame_refresh", "", "") \
|
||||||
X(OC_EXPORT_FRAME_RESIZE, "oc_on_resize", "", "ii") \
|
X(OC_EXPORT_FRAME_RESIZE, "oc_on_resize", "", "ii") \
|
||||||
X(OC_EXPORT_RAW_EVENT, "oc_on_raw_event", "", "i")
|
X(OC_EXPORT_RAW_EVENT, "oc_on_raw_event", "", "i") \
|
||||||
|
X(OC_EXPORT_TERMINATE, "oc_on_terminate", "", "")
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,5 +63,11 @@
|
||||||
"cname": "oc_get_host_platform",
|
"cname": "oc_get_host_platform",
|
||||||
"ret": {"name": "int", "tag": "i"},
|
"ret": {"name": "int", "tag": "i"},
|
||||||
"args": []
|
"args": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "oc_request_quit",
|
||||||
|
"cname": "oc_request_quit",
|
||||||
|
"ret": {"name": "void", "tag": "v"},
|
||||||
|
"args": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue