Browse Source

Updated Lua examples

Most of the examples already working! Only some of them still fail,
mostly related to data arrays...
raysan5 9 years ago
parent
commit
865b216ebe

+ 2 - 12
examples/audio_module_playing.lua

@@ -11,16 +11,6 @@
 
 MAX_CIRCLES = 64
 
---[[
-typedef struct {        -- TODO: Find a Lua alternative: TABLES?
-    Vector2 position
-    float radius
-    float alpha
-    float speed
-    Color color
-} CircleWave
---]]
-
 -- Initialization
 -------------------------------------------------------------------------------------------
 local screenWidth = 800
@@ -78,7 +68,7 @@ while not WindowShouldClose() do        -- Detect window close button or ESC key
             circles[i].radius = GetRandomValue(10, 40)
             circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius)
             circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius)
-            circles[i].color = colors[GetRandomValue(0, 13)]
+            circles[i].color = colors[GetRandomValue(1, 14)]
             circles[i].speed = GetRandomValue(1, 100)/20000.0
         end
     end
@@ -112,7 +102,7 @@ while not WindowShouldClose() do        -- Detect window close button or ESC key
 
         -- Draw time bar
         DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY)
-        DrawRectangle(20, screenHeight - 20 - 12, timePlayed, 12, MAROON)
+        DrawRectangle(20, screenHeight - 20 - 12, timePlayed//1, 12, MAROON)
         DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE)
 
     EndDrawing()

+ 1 - 1
examples/core_2d_camera.lua

@@ -91,7 +91,7 @@ while not WindowShouldClose() do                -- Detect window close button or
 
         ClearBackground(RAYWHITE)
 
-        Begin2dMode(camera)    -- ERROR: Lua Error: attempt to index a number value (?)
+        Begin2dMode(camera)
 
             DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY)
             

+ 5 - 3
examples/core_3d_picking.lua

@@ -41,7 +41,7 @@ SetTargetFPS(60)                   -- Set our game to run at 60 frames-per-secon
 while not WindowShouldClose() do            -- Detect window close button or ESC key
     -- Update
     ---------------------------------------------------------------------------------------
-    UpdateCamera(camera)           -- Update internal camera and our camera
+    camera = UpdateCamera(camera)           -- Update internal camera and our camera
     
     if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then
         -- NOTE: This function is NOT WORKING properly!
@@ -49,8 +49,10 @@ while not WindowShouldClose() do            -- Detect window close button or ESC
         
         -- Check collision between ray and box
         collision = CheckCollisionRayBox(ray,
-                    (BoundingBox)((Vector3)(cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2),
-                                  (Vector3)(cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2)))
+                        BoundingBox(Vector3(cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2),
+                                    Vector3(cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2)))
+
+        --print("collision check:", collision)
     end
     ---------------------------------------------------------------------------------------
 

+ 1 - 1
examples/core_world_screen.lua

@@ -56,7 +56,7 @@ while not WindowShouldClose() do        -- Detect window close button or ESC key
 
         End3dMode()
         
-        DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20)//2, cubeScreenPosition.y, 20, BLACK)
+        DrawText("Enemy: 100 / 100", cubeScreenPosition.x//1 - MeasureText("Enemy: 100 / 100", 20)//2, cubeScreenPosition.y//1, 20, BLACK)
         DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20))//2, 25, 20, GRAY)
 
     EndDrawing()

+ 1 - 1
examples/models_billboard.lua

@@ -34,7 +34,7 @@ SetTargetFPS(60)                   -- Set our game to run at 60 frames-per-secon
 while not WindowShouldClose() do            -- Detect window close button or ESC key
     -- Update
     ---------------------------------------------------------------------------------------
-    UpdateCamera(camera)          -- Update internal camera and our camera
+    camera = UpdateCamera(camera)           -- Update internal camera and our camera
     ---------------------------------------------------------------------------------------
 
     -- Draw

+ 1 - 1
examples/models_box_collisions.lua

@@ -60,7 +60,7 @@ while not WindowShouldClose() do            -- Detect window close button or ESC
                             enemyBoxPos.z - enemyBoxSize.z/2), 
                     Vector3(enemyBoxPos.x + enemyBoxSize.x/2,
                             enemyBoxPos.y + enemyBoxSize.y/2, 
-                            enemyBoxPos.z + enemyBoxSize.z/2))) then collision = true 
+                            enemyBoxPos.z + enemyBoxSize.z/2)))) then collision = true 
     end
     
     -- Check collisions player vs enemy-sphere

+ 4 - 4
examples/models_cubicmap.lua

@@ -32,17 +32,17 @@ local mapPosition = Vector3(-16.0, 0.0, -8.0)          -- Set model position
 UnloadImage(image)     -- Unload cubesmap image from RAM, already uploaded to VRAM
 
 SetCameraMode(CameraMode.ORBITAL)      -- Set an orbital camera mode
-SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position
-SetCameraFovy(camera.fovy)         -- Set internal camera field-of-view Y
+SetCameraPosition(camera.position)     -- Set internal camera position to match our custom camera position
+SetCameraFovy(camera.fovy)             -- Set internal camera field-of-view Y
 
-SetTargetFPS(60)                   -- Set our game to run at 60 frames-per-second
+SetTargetFPS(60)                       -- Set our game to run at 60 frames-per-second
 -------------------------------------------------------------------------------------------
 
 -- Main game loop
 while not WindowShouldClose() do            -- Detect window close button or ESC key
     -- Update
     ---------------------------------------------------------------------------------------
-    UpdateCamera(camera)          -- Update internal camera and our camera
+    camera = UpdateCamera(camera)           -- Update internal camera and our camera
     ---------------------------------------------------------------------------------------
 
     -- Draw

+ 1 - 1
examples/models_heightmap.lua

@@ -37,7 +37,7 @@ SetTargetFPS(60)                   -- Set our game to run at 60 frames-per-secon
 while not WindowShouldClose() do            -- Detect window close button or ESC key
     -- Update
     ---------------------------------------------------------------------------------------
-    UpdateCamera(camera)          -- Update internal camera and our camera
+    camera = UpdateCamera(camera)           -- Update internal camera and our camera
     ---------------------------------------------------------------------------------------
 
     -- Draw

+ 33 - 33
examples/rlua_execute_file.c

@@ -29,8 +29,8 @@ int main()
     //--------------------------------------------------------------------------------------
 
     // ExecuteLuaFile("core_basic_window.lua");                 // OK!
-		// ExecuteLuaFile("core_input_keys.lua");                   // OK!
-		// ExecuteLuaFile("core_input_mouse.lua");                  // OK!
+    // ExecuteLuaFile("core_input_keys.lua");                   // OK!
+    // ExecuteLuaFile("core_input_mouse.lua");                  // OK!
     // ExecuteLuaFile("core_mouse_wheel.lua");                  // OK!
     // ExecuteLuaFile("core_input_gamepad.lua");                // OK!
     // ExecuteLuaFile("core_random_values.lua");                // OK!
@@ -38,13 +38,13 @@ int main()
     // ExecuteLuaFile("core_drop_files.lua");                   // ERROR: GetDroppedFiles()
     // ExecuteLuaFile("core_storage_values.lua");               // OK!
     // ExecuteLuaFile("core_gestures_detection.lua");           // OK!
-    // ExecuteLuaFile("core_3d_mode.lua");                      // ERROR: Lua Error: attempt to index a number value - Begin3dMode()
-    // ExecuteLuaFile("core_3d_picking.lua");                   // ERROR: Lua Error: attempt to index a number value
-    // ExecuteLuaFile("core_3d_camera_free.lua");               // ERROR: Lua Error: attempt to index a number value
-    // ExecuteLuaFile("core_3d_camera_first_person.lua");       // ERROR: Lua Error: attempt to index a number value
-    // ExecuteLuaFile("core_2d_camera.lua");                    // ERROR: Lua Error: attempt to index a number value - Begin2dMode()
-    // ExecuteLuaFile("core_world_screen.lua");                 // ERROR: Lua Error: attempt to index a number value
-    // ExecuteLuaFile("core_oculus_rift.lua");                  // ERROR: Lua Error: attempt to index a number value
+    // ExecuteLuaFile("core_3d_mode.lua");                      // OK!
+    // ExecuteLuaFile("core_3d_picking.lua");                   // ISSUE: CheckCollisionRayBox() returns false despite touching box
+    // ExecuteLuaFile("core_3d_camera_free.lua");               // OK!
+    // ExecuteLuaFile("core_3d_camera_first_person.lua");       // OK!
+    // ExecuteLuaFile("core_2d_camera.lua");                    // OK!
+    // ExecuteLuaFile("core_world_screen.lua");                 // OK!
+    // ExecuteLuaFile("core_oculus_rift.lua");                  // OK!
     // ExecuteLuaFile("shapes_logo_raylib.lua");                // OK!
     // ExecuteLuaFile("shapes_basic_shapes.lua");               // OK!
     // ExecuteLuaFile("shapes_colors_palette.lua");             // OK!
@@ -54,31 +54,31 @@ int main()
     // ExecuteLuaFile("textures_rectangle.lua");                // OK!
     // ExecuteLuaFile("textures_srcrec_dstrec.lua");            // OK!
     // ExecuteLuaFile("textures_to_image.lua");                 // OK!
-    // ExecuteLuaFile("textures_raw_data.lua");                 // ERROR: Lua Error: attempt to index a number value
-		// ExecuteLuaFile("textures_formats_loading.lua");          // ISSUE: texture.id not exposed to be checked
-		// ExecuteLuaFile("textures_particles_trail_blending.lua"); // ERROR: Using struct
-		// ExecuteLuaFile("textures_image_processing.lua");         // ERROR: GetImageData() --> UpdateTexture()
-		// ExecuteLuaFile("textures_image_drawing.lua");            // OK!
-		// ExecuteLuaFile("text_sprite_fonts.lua");                 // OK!
-		// ExecuteLuaFile("text_bmfont_ttf.lua");                   // OK!
-		// ExecuteLuaFile("text_rbmf_fonts.lua");                   // ERROR: Lua Error: attempt to index a nil value
-		// ExecuteLuaFile("text_format_text.lua");                  // OK! NOTE: Use lua string.format() instead of raylib FormatText()
-		// ExecuteLuaFile("text_font_select.lua");                  // OK!
-		// ExecuteLuaFile("text_writing_anim.lua");                 // ERROR: SubText()
-		// ExecuteLuaFile("models_geometric_shapes.lua");           // ERROR: Lua Error: attempt to index a number value - Begin3dMode(camera)
-		// ExecuteLuaFile("models_box_collisions.lua");             //
-		// ExecuteLuaFile("models_billboard.lua");                  //
-		// ExecuteLuaFile("models_obj_loading.lua");                //
-		// ExecuteLuaFile("models_heightmap.lua");                  //
-    // ExecuteLuaFile("models_cubicmap.lua");                   //
-		// ExecuteLuaFile("shaders_model_shader.lua");              //
-		// ExecuteLuaFile("shaders_shapes_textures.lua");           //
-    // ExecuteLuaFile("shaders_custom_uniform.lua");            //
-    // ExecuteLuaFile("shaders_postprocessing.lua");            //
-    // ExecuteLuaFile("shaders_standard_lighting.lua");         //
+    // ExecuteLuaFile("textures_raw_data.lua");                 // ERROR: bad argument #2 to 'LoadImageEx' (number expected, got no value)
+    // ExecuteLuaFile("textures_formats_loading.lua");          // ISSUE: texture.id not exposed to be checked (not really an issue...)
+    // ExecuteLuaFile("textures_particles_trail_blending.lua"); // OK!
+    // ExecuteLuaFile("textures_image_processing.lua");         // ERROR: GetImageData() --> UpdateTexture()
+    // ExecuteLuaFile("textures_image_drawing.lua");            // OK!
+    // ExecuteLuaFile("text_sprite_fonts.lua");                 // OK!
+    // ExecuteLuaFile("text_bmfont_ttf.lua");                   // OK!
+    // ExecuteLuaFile("text_rbmf_fonts.lua");                   // OK!
+    // ExecuteLuaFile("text_format_text.lua");                  // OK! NOTE: Use lua string.format() instead of raylib FormatText()
+    // ExecuteLuaFile("text_font_select.lua");                  // OK!
+    // ExecuteLuaFile("text_writing_anim.lua");                 // OK!
+    // ExecuteLuaFile("models_geometric_shapes.lua");           // OK!
+    // ExecuteLuaFile("models_box_collisions.lua");             // OK!
+    // ExecuteLuaFile("models_billboard.lua");                  // OK!
+    // ExecuteLuaFile("models_obj_loading.lua");                // OK!
+    // ExecuteLuaFile("models_heightmap.lua");                  // OK!
+    // ExecuteLuaFile("models_cubicmap.lua");                   // OK!
+    // ExecuteLuaFile("shaders_model_shader.lua");              // OK!
+    // ExecuteLuaFile("shaders_shapes_textures.lua");           // OK!
+    // ExecuteLuaFile("shaders_custom_uniform.lua");            // ISSUE: SetShaderValue()
+    // ExecuteLuaFile("shaders_postprocessing.lua");            // OK!
+    // ExecuteLuaFile("shaders_standard_lighting.lua");         // ERROR: CreateLight() returns an opaque pointer (fields can not be accessed)
     // ExecuteLuaFile("audio_sound_loading.lua");               // OK!
     // ExecuteLuaFile("audio_music_stream.lua");                // OK!
-    ExecuteLuaFile("audio_module_playing.lua");              // ERROR: Using struct
+    // ExecuteLuaFile("audio_module_playing.lua");              // OK!
     ExecuteLuaFile("audio_raw_stream.lua");                  // ERROR: UpdateAudioStream()
 
     // De-Initialization
@@ -86,5 +86,5 @@ int main()
     CloseLuaDevice();        // Close Lua device and free resources
     //--------------------------------------------------------------------------------------
 
-	return 0;
+    return 0;
 }

+ 1 - 1
examples/shaders_custom_uniform.lua

@@ -66,7 +66,7 @@ while not WindowShouldClose() do       -- Detect window close button or ESC key
     -- Send new value to the shader to be used on drawing
     SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2)
     
-    UpdateCamera(camera)              -- Update internal camera and our camera
+    camera = UpdateCamera(camera)      -- Update internal camera and our camera
     ---------------------------------------------------------------------------------------
 
     -- Draw

+ 1 - 1
examples/shaders_model_shader.lua

@@ -50,7 +50,7 @@ SetTargetFPS(60)                          -- Set our game to run at 60 frames-pe
 while not WindowShouldClose() do          -- Detect window close button or ESC key
     -- Update
     ---------------------------------------------------------------------------------------
-    UpdateCamera(camera)                 -- Update internal camera and our camera
+    camera = UpdateCamera(camera)         -- Update internal camera and our camera
     ---------------------------------------------------------------------------------------
 
     -- Draw

+ 1 - 1
examples/shaders_postprocessing.lua

@@ -52,7 +52,7 @@ SetTargetFPS(60)                       -- Set our game to run at 60 frames-per-s
 while not WindowShouldClose() do       -- Detect window close button or ESC key
     -- Update
     ---------------------------------------------------------------------------------------
-    UpdateCamera(camera)              -- Update internal camera and our camera
+    camera = UpdateCamera(camera)      -- Update internal camera and our camera
     ---------------------------------------------------------------------------------------
 
     -- Draw

+ 12 - 12
examples/shaders_standard_lighting.lua

@@ -27,9 +27,9 @@ InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
 
 -- Define the camera to look into our 3d world
 local camera = Camera(Vector3(4.0, 4.0, 4.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
-local position = Vector3(0.0, 0.0, 0.0)   -- Set model position
 
 local dwarf = LoadModel("resources/model/dwarf.obj")                     -- Load OBJ model
+local position = Vector3(0.0, 0.0, 0.0)                                  -- Set model position
 
 local material = LoadStandardMaterial()
 
@@ -37,30 +37,30 @@ material.texDiffuse = LoadTexture("resources/model/dwarf_diffuse.png")   -- Load
 material.texNormal = LoadTexture("resources/model/dwarf_normal.png")     -- Load model normal texture
 material.texSpecular = LoadTexture("resources/model/dwarf_specular.png") -- Load model specular texture
 material.colDiffuse = WHITE
-material.colAmbient = (Color)(0, 0, 10, 255)
+material.colAmbient = Color(0, 0, 10, 255)
 material.colSpecular = WHITE
 material.glossiness = 50.0
 
 dwarf.material = material      -- Apply material to model
 
-local spotLight = CreateLight(LIGHT_SPOT, (Vector3)(3.0, 5.0, 2.0), (Color)(255, 255, 255, 255))
-spotLight.target = (Vector3)(0.0, 0.0, 0.0)
+local spotLight = CreateLight(LightType.SPOT, Vector3(3.0, 5.0, 2.0), Color(255, 255, 255, 255))
+spotLight.target = Vector3(0.0, 0.0, 0.0)
 spotLight.intensity = 2.0
-spotLight.diffuse = (Color)(255, 100, 100, 255)
+spotLight.diffuse = Color(255, 100, 100, 255)
 spotLight.coneAngle = 60.0
 
-local dirLight = CreateLight(LIGHT_DIRECTIONAL, (Vector3)(0.0, -3.0, -3.0), (Color)(255, 255, 255, 255))
-dirLight.target = (Vector3)(1.0, -2.0, -2.0)
+local dirLight = CreateLight(LightType.DIRECTIONAL, Vector3(0.0, -3.0, -3.0), Color(255, 255, 255, 255))
+dirLight.target = Vector3(1.0, -2.0, -2.0)
 dirLight.intensity = 2.0
-dirLight.diffuse = (Color)(100, 255, 100, 255)
+dirLight.diffuse = Color(100, 255, 100, 255)
 
-local pointLight = CreateLight(LIGHT_POINT, (Vector3)(0.0, 4.0, 5.0), (Color)(255, 255, 255, 255))
+local pointLight = CreateLight(LightType.POINT, Vector3(0.0, 4.0, 5.0), Color(255, 255, 255, 255))
 pointLight.intensity = 2.0
-pointLight.diffuse = (Color)(100, 100, 255, 255)
+pointLight.diffuse = Color(100, 100, 255, 255)
 pointLight.radius = 3.0
 
 -- Setup orbital camera
-SetCameraMode(CameraMode.ORBITAL)          -- Set an orbital camera mode
+SetCameraMode(CameraMode.ORBITAL)      -- Set an orbital camera mode
 SetCameraPosition(camera.position)     -- Set internal camera position to match our camera position
 SetCameraTarget(camera.target)         -- Set internal camera target to match our camera target
 
@@ -71,7 +71,7 @@ SetTargetFPS(60)                       -- Set our game to run at 60 frames-per-s
 while not WindowShouldClose() do       -- Detect window close button or ESC key
     -- Update
     ---------------------------------------------------------------------------------------
-    UpdateCamera(camera)              -- Update internal camera and our camera
+    camera = UpdateCamera(camera)      -- Update internal camera and our camera
     ---------------------------------------------------------------------------------------
 
     -- Draw

+ 1 - 1
examples/text_rbmf_fonts.lua

@@ -47,7 +47,7 @@ local positions = {}
 for i = 1, 8 do
     positions[i] = Vector2(0, 0)
     positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].size*2, spacings[i]).x/2
-    positions[i].y = 60 + fonts[i].size + 50*i
+    positions[i].y = 60 + fonts[i].size + 45*(i - 1)
 end
 
 local colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, BLACK }

+ 1 - 1
examples/text_writing_anim.lua

@@ -38,7 +38,7 @@ while not WindowShouldClose() do            -- Detect window close button or ESC
 
         ClearBackground(RAYWHITE)
 
-        DrawText(string.sub(message, 0, framesCounter/10), 210, 160, 20, MAROON)
+        DrawText(string.sub(message, 0, framesCounter//10), 210, 160, 20, MAROON)
         
         DrawText("PRESS [ENTER] to RESTART!", 240, 280, 20, LIGHTGRAY)
 

+ 2 - 3
examples/textures_particles_trail_blending.lua

@@ -11,7 +11,6 @@
 
 MAX_PARTICLES = 200
 
--- Particle structure with basic data
 -- Initialization
 -------------------------------------------------------------------------------------------
 local screenWidth = 800
@@ -56,7 +55,7 @@ while not WindowShouldClose() do            -- Detect window close button or ESC
             mouseTail[i].active = true
             mouseTail[i].alpha = 1.0
             mouseTail[i].position = GetMousePosition()
-            i = MAX_PARTICLES
+            break
         end
     end
 
@@ -90,7 +89,7 @@ while not WindowShouldClose() do            -- Detect window close button or ESC
                 if (mouseTail[i].active) then 
                     DrawTexturePro(smoke, Rectangle(0, 0, smoke.width, smoke.height), 
                         Rectangle(mouseTail[i].position.x, mouseTail[i].position.y, 
-                                  smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size),
+                                  smoke.width*mouseTail[i].size//1, smoke.height*mouseTail[i].size//1),
                         Vector2(smoke.width*mouseTail[i].size/2, smoke.height*mouseTail[i].size/2), 
                         mouseTail[i].rotation, Fade(mouseTail[i].color, mouseTail[i].alpha)) end
             end

+ 1 - 1
examples/textures_raw_data.lua

@@ -36,7 +36,7 @@ local pixels = {}
 
 for y = 1, height do
     for x = 1, width do
-        if (((x/32+y/32)/1)%2 == 0) then pixels[y*height + x] = DARKBLUE
+        if ((((x - 1)/32+(y - 1)//32)//1)%2 == 0) then pixels[y*height + x] = DARKBLUE
         else pixels[y*height + x] = SKYBLUE end
     end
 end