summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-01-09 22:38:34 -0500
committerrealtradam <[email protected]>2022-01-09 22:38:34 -0500
commit633f774b0c554e6c916ff3d3a73886e7285322a1 (patch)
tree64f168d344f377632d3891d21ff14adf80684e60 /src
parent3a5b8018c4db077ef65f9c55aa5293a014e93e45 (diff)
downloadsample-mruby-gem-633f774b0c554e6c916ff3d3a73886e7285322a1.tar.gz
sample-mruby-gem-633f774b0c554e6c916ff3d3a73886e7285322a1.zip
.
Diffstat (limited to 'src')
-rw-r--r--src/example.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/src/example.c b/src/example.c
index ff6a32f..140d032 100644
--- a/src/example.c
+++ b/src/example.c
@@ -2,55 +2,65 @@
#include <mruby/string.h>
#include <stdio.h>
#include <raylib.h>
+#if defined(PLATFORM_WEB)
+#include <emscripten/emscripten.h>
+#endif
const int screenWidth = 800;
const int screenHeight = 450;
+void UpdateDrawFrame(void); // Update and Draw one frame
static mrb_value
mrb_c_method(mrb_state *mrb, mrb_value self)
{
- //mrb_ensure_string_type(mrb, self);
- //printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self));
// Initialization
//--------------------------------------------------------------------------------------
-
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+#if defined(PLATFORM_WEB)
+ emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
+#else
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
- Texture2D texture = LoadTexture("assets/HYPERS.png");
- struct Vector2 position = { 0, 0 };
-
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
- // Update
- //----------------------------------------------------------------------------------
- // TODO: Update your variables here
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- DrawTextureEx(texture, position, 0.0f, 4.0f, WHITE);
-
- DrawText("HYPERS!", 500, 50, 20, RED);
-
- EndDrawing();
- //----------------------------------------------------------------------------------
+ UpdateDrawFrame();
}
+#endif
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
+
return self;
}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition
+//----------------------------------------------------------------------------------
+void UpdateDrawFrame(void)
+{
+ // Update
+ //----------------------------------------------------------------------------------
+ // TODO: Update your variables here
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+}
+
void
mrb_my_silly_extension_gem_init(mrb_state* mrb) {
struct RClass *class_cextension = mrb_define_module(mrb, "CRubyExtension");