summaryrefslogtreecommitdiff
path: root/examples/custom_main_loop
diff options
context:
space:
mode:
Diffstat (limited to 'examples/custom_main_loop')
-rw-r--r--examples/custom_main_loop/main.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/custom_main_loop/main.lua b/examples/custom_main_loop/main.lua
new file mode 100644
index 0000000..952496c
--- /dev/null
+++ b/examples/custom_main_loop/main.lua
@@ -0,0 +1,52 @@
+package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
+
+Vector2 = require( "vector2" )
+
+local function dysfunctionalPrint( message )
+ printt( message )
+end
+
+local function main()
+ RL.SetConfigFlags( RL.FLAG_VSYNC_HINT )
+ RL.InitWindow( { 800, 600 }, "Custom Main Loop" )
+
+ local catTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" )
+ local catPos = Vector2:new( 20, 20 )
+ local catSpeed = 200
+
+ while not RL.WindowShouldClose() do
+ local delta = RL.GetFrameTime()
+ local vel = Vector2:new()
+
+ if RL.IsKeyDown( RL.KEY_RIGHT ) then
+ vel.x = catSpeed * delta
+ elseif RL.IsKeyDown( RL.KEY_LEFT ) then
+ vel.x = -catSpeed * delta
+ end
+ if RL.IsKeyDown( RL.KEY_DOWN ) then
+ vel.y = catSpeed * delta
+ elseif RL.IsKeyDown( RL.KEY_UP ) then
+ vel.y = -catSpeed * delta
+ end
+
+ if RL.IsKeyPressed( RL.KEY_ENTER ) then
+ dysfunctionalPrint( "This will fail and give usefull traceback info" )
+ end
+
+ catPos:addEq( vel )
+
+ RL.BeginDrawing()
+ RL.ClearBackground( RL.LIGHTGRAY )
+ RL.DrawTexture( catTex, catPos, RL.WHITE )
+ RL.DrawFPS( { 10, 10 } )
+ RL.EndDrawing()
+ end
+end
+
+-- Call main to get traceback info.
+local success, result = xpcall( main, debug.traceback )
+
+if not success then
+ RL.TraceLog( RL.LOG_WARNING, "Error: "..result )
+ RL.CloseWindow()
+end