Fixes for some Lua bugs

This commit is contained in:
ghassanpl 2016-08-06 16:58:48 +02:00
parent d5f5f0a930
commit 4960e6b6d7
20 changed files with 413 additions and 103 deletions

View File

@ -11,6 +11,7 @@
MAX_CIRCLES = 64 MAX_CIRCLES = 64
--[[
typedef struct { -- TODO: Find a Lua alternative: TABLES? typedef struct { -- TODO: Find a Lua alternative: TABLES?
Vector2 position Vector2 position
float radius float radius
@ -18,6 +19,7 @@ typedef struct { -- TODO: Find a Lua alternative: TABLES?
float speed float speed
Color color Color color
} CircleWave } CircleWave
--]]
-- Initialization -- Initialization
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
@ -35,11 +37,13 @@ local colors = { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK,
local circles = {} local circles = {}
for i = MAX_CIRCLES, 1, -1 do for i = MAX_CIRCLES, 1, -1 do
circles[i] = {}
circles[i].alpha = 0.0 circles[i].alpha = 0.0
circles[i].radius = GetRandomValue(10, 40) circles[i].radius = GetRandomValue(10, 40)
circles[i].position = Vector2(0, 0)
circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius) 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].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius)
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0 circles[i].speed = GetRandomValue(1, 100)/20000.0
circles[i].color = colors[GetRandomValue(1, 14)] circles[i].color = colors[GetRandomValue(1, 14)]
end end
@ -64,8 +68,8 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
for i = MAX_CIRCLES, 1, -1 do for i = MAX_CIRCLES, 1, -1 do
circles[i].alpha += circles[i].speed circles[i].alpha = circles[i].alpha + circles[i].speed
circles[i].radius += circles[i].speed*10.0 circles[i].radius = circles[i].radius + circles[i].speed*10.0
if (circles[i].alpha > 1.0) then circles[i].speed = circles[i].speed*-1 end if (circles[i].alpha > 1.0) then circles[i].speed = circles[i].speed*-1 end
@ -75,7 +79,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius) 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].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius)
circles[i].color = colors[GetRandomValue(0, 13)] circles[i].color = colors[GetRandomValue(0, 13)]
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0 circles[i].speed = GetRandomValue(1, 100)/20000.0
end end
end end
@ -108,7 +112,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
-- Draw time bar -- Draw time bar
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY) DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY)
DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON) DrawRectangle(20, screenHeight - 20 - 12, timePlayed, 12, MAROON)
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE) DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE)
EndDrawing() EndDrawing()
@ -126,6 +130,3 @@ CloseAudioDevice() -- Close audio device (music streaming is automatically s
CloseWindow() -- Close window and OpenGL context CloseWindow() -- Close window and OpenGL context
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
return 0
}

View File

@ -49,8 +49,8 @@ while not WindowShouldClose() do -- Detect window close button or ESC
-- Check collision between ray and box -- Check collision between ray and box
collision = CheckCollisionRayBox(ray, collision = CheckCollisionRayBox(ray,
(BoundingBox){(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 }}) (Vector3)(cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2)))
end end
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------

View File

@ -36,7 +36,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
ballPosition.x = ballPosition.x + gamepadMovement.x ballPosition.x = ballPosition.x + gamepadMovement.x
ballPosition.y = ballPosition.y - gamepadMovement.y ballPosition.y = ballPosition.y - gamepadMovement.y
if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A)) then if (IsGamepadButtonPressed(GAMEPAD.PLAYER1, GAMEPAD.BUTTON_A)) then
ballPosition.x = screenWidth/2 ballPosition.x = screenWidth/2
ballPosition.y = screenHeight/2 ballPosition.y = screenHeight/2
end end

View File

@ -22,7 +22,7 @@ local camera = Camera(Vector3(5.0, 4.0, 5.0), Vector3(0.0, 2.0, 0.0), Vector3(0.
local bill = LoadTexture("resources/billboard.png") -- Our texture billboard local bill = LoadTexture("resources/billboard.png") -- Our texture billboard
local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard
SetCameraMode(CAMERA.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 SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
@ -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 while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
UpdateCamera(&camera) -- Update internal camera and our camera UpdateCamera(camera) -- Update internal camera and our camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw
@ -45,9 +45,9 @@ while not WindowShouldClose() do -- Detect window close button or ESC
Begin3dMode(camera) Begin3dMode(camera)
DrawBillboard(camera, bill, billPosition, 2.0f, WHITE) DrawBillboard(camera, bill, billPosition, 2.0, WHITE)
DrawGrid(10, 1.0f) -- Draw a grid DrawGrid(10, 1.0) -- Draw a grid
End3dMode() End3dMode()

View File

@ -40,10 +40,10 @@ while not WindowShouldClose() do -- Detect window close button or ESC
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Move player -- Move player
if (IsKeyDown(KEY.RIGHT)) then playerPosition.x = playerPosition.x + 0.2f end if (IsKeyDown(KEY.RIGHT)) then playerPosition.x = playerPosition.x + 0.2
elseif (IsKeyDown(KEY.LEFT)) then playerPosition.x = playerPosition.x - 0.2f end elseif (IsKeyDown(KEY.LEFT)) then playerPosition.x = playerPosition.x - 0.2
elseif (IsKeyDown(KEY.DOWN)) then playerPosition.z = playerPosition.z + 0.2f end elseif (IsKeyDown(KEY.DOWN)) then playerPosition.z = playerPosition.z + 0.2
elseif (IsKeyDown(KEY.UP)) then playerPosition.z = playerPosition.z - 0.2f end elseif (IsKeyDown(KEY.UP)) then playerPosition.z = playerPosition.z - 0.2 end
collision = false collision = false

View File

@ -31,7 +31,7 @@ local mapPosition = Vector3(-16.0, 0.0, -8.0) -- Set model position
UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM
SetCameraMode(CAMERA.ORBITAL) -- Set an orbital camera mode SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
@ -42,7 +42,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per-secon
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
UpdateCamera(&camera) -- Update internal camera and our camera UpdateCamera(camera) -- Update internal camera and our camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw
@ -57,7 +57,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC
End3dMode() End3dMode()
DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0, 4.0, WHITE) DrawTextureEx(cubicmap, (Vector2)(screenWidth - cubicmap.width*4 - 20, 20), 0.0, 4.0, WHITE)
DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN) DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN)
DrawText("cubicmap image used to", 658, 90, 10, GRAY) DrawText("cubicmap image used to", 658, 90, 10, GRAY)

View File

@ -21,13 +21,13 @@ local camera = Camera(Vector3(18.0, 16.0, 18.0), Vector3(0.0, 0.0, 0.0), Vector3
local image = LoadImage("resources/heightmap.png") -- Load heightmap image (RAM) local image = LoadImage("resources/heightmap.png") -- Load heightmap image (RAM)
local texture = LoadTextureFromImage(image) -- Convert image to texture (VRAM) local texture = LoadTextureFromImage(image) -- Convert image to texture (VRAM)
local map = LoadHeightmap(image, Vector3(16, 8, 16) -- Load heightmap model with defined size local map = LoadHeightmap(image, Vector3(16, 8, 16)) -- Load heightmap model with defined size
map.material.texDiffuse = texture -- Set map diffuse texture map.material.texDiffuse = texture -- Set map diffuse texture
local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (depends on model scaling!) local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (depends on model scaling!)
UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM
SetCameraMode(CAMERA.ORBITAL) -- Set an orbital camera mode SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
@ -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 while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
UpdateCamera(&camera) -- Update internal camera and our camera UpdateCamera(camera) -- Update internal camera and our camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw

View File

@ -42,9 +42,9 @@ while not WindowShouldClose() do -- Detect window close button or ESC
Begin3dMode(camera) Begin3dMode(camera)
DrawModel(dwarf, position, 2.0f, WHITE) -- Draw 3d model with texture DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture
DrawGrid(10, 1.0f) -- Draw a grid DrawGrid(10, 1.0) -- Draw a grid
DrawGizmo(position) -- Draw gizmo DrawGizmo(position) -- Draw gizmo

View File

@ -29,8 +29,8 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// ExecuteLuaFile("core_basic_window.lua"); // OK! // ExecuteLuaFile("core_basic_window.lua"); // OK!
// ExecuteLuaFile("core_input_keys.lua"); // OK! // ExecuteLuaFile("core_input_keys.lua"); // OK!
// ExecuteLuaFile("core_input_mouse.lua"); // OK! // ExecuteLuaFile("core_input_mouse.lua"); // OK!
// ExecuteLuaFile("core_mouse_wheel.lua"); // OK! // ExecuteLuaFile("core_mouse_wheel.lua"); // OK!
// ExecuteLuaFile("core_input_gamepad.lua"); // OK! // ExecuteLuaFile("core_input_gamepad.lua"); // OK!
// ExecuteLuaFile("core_random_values.lua"); // OK! // ExecuteLuaFile("core_random_values.lua"); // OK!
@ -55,31 +55,31 @@ int main()
// ExecuteLuaFile("textures_srcrec_dstrec.lua"); // OK! // ExecuteLuaFile("textures_srcrec_dstrec.lua"); // OK!
// ExecuteLuaFile("textures_to_image.lua"); // OK! // ExecuteLuaFile("textures_to_image.lua"); // OK!
// ExecuteLuaFile("textures_raw_data.lua"); // ERROR: Lua Error: attempt to index a number value // 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_formats_loading.lua"); // ISSUE: texture.id not exposed to be checked
// ExecuteLuaFile("textures_particles_trail_blending.lua"); // ERROR: Using struct // ExecuteLuaFile("textures_particles_trail_blending.lua"); // ERROR: Using struct
// ExecuteLuaFile("textures_image_processing.lua"); // ERROR: GetImageData() --> UpdateTexture() // ExecuteLuaFile("textures_image_processing.lua"); // ERROR: GetImageData() --> UpdateTexture()
// ExecuteLuaFile("textures_image_drawing.lua"); // OK! // ExecuteLuaFile("textures_image_drawing.lua"); // OK!
// ExecuteLuaFile("text_sprite_fonts.lua"); // OK! // ExecuteLuaFile("text_sprite_fonts.lua"); // OK!
// ExecuteLuaFile("text_bmfont_ttf.lua"); // OK! // ExecuteLuaFile("text_bmfont_ttf.lua"); // OK!
// ExecuteLuaFile("text_rbmf_fonts.lua"); // ERROR: Lua Error: attempt to index a nil value // 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_format_text.lua"); // OK! NOTE: Use lua string.format() instead of raylib FormatText()
// ExecuteLuaFile("text_font_select.lua"); // OK! // ExecuteLuaFile("text_font_select.lua"); // OK!
// ExecuteLuaFile("text_writing_anim.lua"); // ERROR: SubText() // 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_geometric_shapes.lua"); // ERROR: Lua Error: attempt to index a number value - Begin3dMode(camera)
// ExecuteLuaFile("models_box_collisions.lua"); // // ExecuteLuaFile("models_box_collisions.lua"); //
// ExecuteLuaFile("models_billboard.lua"); // // ExecuteLuaFile("models_billboard.lua"); //
// ExecuteLuaFile("models_obj_loading.lua"); // // ExecuteLuaFile("models_obj_loading.lua"); //
// ExecuteLuaFile("models_heightmap.lua"); // // ExecuteLuaFile("models_heightmap.lua"); //
// ExecuteLuaFile("models_cubicmap.lua"); // // ExecuteLuaFile("models_cubicmap.lua"); //
// ExecuteLuaFile("shaders_model_shader.lua"); // // ExecuteLuaFile("shaders_model_shader.lua"); //
// ExecuteLuaFile("shaders_shapes_textures.lua"); // // ExecuteLuaFile("shaders_shapes_textures.lua"); //
// ExecuteLuaFile("shaders_custom_uniform.lua"); // // ExecuteLuaFile("shaders_custom_uniform.lua"); //
// ExecuteLuaFile("shaders_postprocessing.lua"); // // ExecuteLuaFile("shaders_postprocessing.lua"); //
// ExecuteLuaFile("shaders_standard_lighting.lua"); // // ExecuteLuaFile("shaders_standard_lighting.lua"); //
// ExecuteLuaFile("audio_sound_loading.lua"); // OK! // ExecuteLuaFile("audio_sound_loading.lua"); // OK!
// ExecuteLuaFile("audio_music_stream.lua"); // OK! // ExecuteLuaFile("audio_music_stream.lua"); // OK!
// ExecuteLuaFile("audio_module_playing.lua"); // ERROR: Using struct ExecuteLuaFile("audio_module_playing.lua"); // ERROR: Using struct
// ExecuteLuaFile("audio_raw_stream.lua"); // ERROR: UpdateAudioStream() ExecuteLuaFile("audio_raw_stream.lua"); // ERROR: UpdateAudioStream()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -26,7 +26,7 @@ SetConfigFlags(FLAG.MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable") InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable")
-- Define the camera to look into our 3d world -- Define the camera to look into our 3d world
local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)) local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture (diffuse map) local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture (diffuse map)
@ -47,7 +47,7 @@ local swirlCenter = { screenWidth/2, screenHeight/2 }
local target = LoadRenderTexture(screenWidth, screenHeight) local target = LoadRenderTexture(screenWidth, screenHeight)
-- Setup orbital camera -- Setup orbital camera
SetCameraMode(CAMERA.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 SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
@ -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 -- Send new value to the shader to be used on drawing
SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2) SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2)
UpdateCamera(&camera) -- Update internal camera and our camera UpdateCamera(camera) -- Update internal camera and our camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw

View File

@ -26,7 +26,7 @@ SetConfigFlags(FLAG.MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader") InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
-- Define the camera to look into our 3d world -- Define the camera to look into our 3d world
local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)) local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture
@ -39,7 +39,7 @@ dwarf.material.texDiffuse = texture -- Bind texture to model
local position = Vector3(0.0, 0.0, 0.0) -- Set model position local position = Vector3(0.0, 0.0, 0.0) -- Set model position
-- Setup orbital camera -- Setup orbital camera
SetCameraMode(CAMERA.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 SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
@ -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 while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
UpdateCamera(&camera) -- Update internal camera and our camera UpdateCamera(camera) -- Update internal camera and our camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw

View File

@ -26,7 +26,7 @@ SetConfigFlags(FLAG.MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader") InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
-- Define the camera to look into our 3d world -- Define the camera to look into our 3d world
local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)) local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture (diffuse map) local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture (diffuse map)
@ -41,7 +41,7 @@ local shader = LoadShader("resources/shaders/glsl330/base.vs",
local target = LoadRenderTexture(screenWidth, screenHeight) local target = LoadRenderTexture(screenWidth, screenHeight)
-- Setup orbital camera -- Setup orbital camera
SetCameraMode(CAMERA.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 SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
@ -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 while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
UpdateCamera(&camera) -- Update internal camera and our camera UpdateCamera(camera) -- Update internal camera and our camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw
@ -88,7 +88,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
EndDrawing() EndDrawing()
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
} end
-- De-Initialization -- De-Initialization
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------

View File

@ -90,7 +90,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
EndDrawing() EndDrawing()
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
} end
-- De-Initialization -- De-Initialization
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------

View File

@ -26,7 +26,7 @@ SetConfigFlags(FLAG.MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader") InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
-- Define the camera to look into our 3d world -- 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 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 position = Vector3(0.0, 0.0, 0.0) -- Set model position
local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model
@ -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.texNormal = LoadTexture("resources/model/dwarf_normal.png") -- Load model normal texture
material.texSpecular = LoadTexture("resources/model/dwarf_specular.png") -- Load model specular texture material.texSpecular = LoadTexture("resources/model/dwarf_specular.png") -- Load model specular texture
material.colDiffuse = WHITE material.colDiffuse = WHITE
material.colAmbient = (Color){0, 0, 10, 255} material.colAmbient = (Color)(0, 0, 10, 255)
material.colSpecular = WHITE material.colSpecular = WHITE
material.glossiness = 50.0f material.glossiness = 50.0
dwarf.material = material -- Apply material to model dwarf.material = material -- Apply material to model
local spotLight = CreateLight(LIGHT_SPOT, (Vector3){3.0f, 5.0f, 2.0f}, (Color){255, 255, 255, 255}) local spotLight = CreateLight(LIGHT_SPOT, (Vector3)(3.0, 5.0, 2.0), (Color)(255, 255, 255, 255))
spotLight->target = (Vector3){0.0f, 0.0f, 0.0f} spotLight.target = (Vector3)(0.0, 0.0, 0.0)
spotLight->intensity = 2.0f spotLight.intensity = 2.0
spotLight->diffuse = (Color){255, 100, 100, 255} spotLight.diffuse = (Color)(255, 100, 100, 255)
spotLight->coneAngle = 60.0f spotLight.coneAngle = 60.0
local dirLight = CreateLight(LIGHT_DIRECTIONAL, (Vector3){0.0f, -3.0f, -3.0f}, (Color){255, 255, 255, 255}) local dirLight = CreateLight(LIGHT_DIRECTIONAL, (Vector3)(0.0, -3.0, -3.0), (Color)(255, 255, 255, 255))
dirLight->target = (Vector3){1.0f, -2.0f, -2.0f} dirLight.target = (Vector3)(1.0, -2.0, -2.0)
dirLight->intensity = 2.0f 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.0f, 4.0f, 5.0f}, (Color){255, 255, 255, 255}) local pointLight = CreateLight(LIGHT_POINT, (Vector3)(0.0, 4.0, 5.0), (Color)(255, 255, 255, 255))
pointLight->intensity = 2.0f pointLight.intensity = 2.0
pointLight->diffuse = (Color){100, 100, 255, 255} pointLight.diffuse = (Color)(100, 100, 255, 255)
pointLight->radius = 3.0f pointLight.radius = 3.0
-- Setup orbital camera -- Setup orbital camera
SetCameraMode(CAMERA.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 SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target 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 while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
UpdateCamera(&camera) -- Update internal camera and our camera UpdateCamera(camera) -- Update internal camera and our camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw
@ -98,7 +98,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
EndDrawing() EndDrawing()
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
} end
-- De-Initialization -- De-Initialization
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------

View File

@ -87,7 +87,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC
btnNextInColor = PURPLE btnNextInColor = PURPLE
end end
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) then if (IsMouseButtonDown(MOUSE.LEFT_BUTTON)) then
framesCounter = 20 -- Frames button is 'active' framesCounter = 20 -- Frames button is 'active'
btnNextOutColor = MAROON btnNextOutColor = MAROON
btnNextInColor = RED btnNextInColor = RED

View File

@ -50,7 +50,7 @@ for i = 1, 8 do
positions[i].y = 60 + fonts[i].size + 50*i positions[i].y = 60 + fonts[i].size + 50*i
end end
local colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD } local colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, BLACK }
SetTargetFPS(60) -- Set target frames-per-second SetTargetFPS(60) -- Set target frames-per-second
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------

View File

@ -38,7 +38,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC
ClearBackground(RAYWHITE) ClearBackground(RAYWHITE)
DrawText(SubText(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) DrawText("PRESS [ENTER] to RESTART!", 240, 280, 20, LIGHTGRAY)

View File

@ -12,15 +12,6 @@
MAX_PARTICLES = 200 MAX_PARTICLES = 200
-- Particle structure with basic data -- Particle structure with basic data
struct.Particle {
position,
color,
alpha,
size,
rotation,
active -- NOTE: Use it to activate/deactive particle
}
-- Initialization -- Initialization
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
local screenWidth = 800 local screenWidth = 800
@ -33,6 +24,7 @@ local mouseTail = {}
-- Initialize particles -- Initialize particles
for i = 1, MAX_PARTICLES do for i = 1, MAX_PARTICLES do
mouseTail[i] = {}
mouseTail[i].position = Vector2(0, 0) mouseTail[i].position = Vector2(0, 0)
mouseTail[i].color = Color(GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255) mouseTail[i].color = Color(GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255)
mouseTail[i].alpha = 1.0 mouseTail[i].alpha = 1.0
@ -45,7 +37,7 @@ local gravity = 3.0
local smoke = LoadTexture("resources/smoke.png") local smoke = LoadTexture("resources/smoke.png")
local blending = BLEND.ALPHA local blending = BlendMode.ALPHA
SetTargetFPS(60) SetTargetFPS(60)
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
@ -80,8 +72,8 @@ while not WindowShouldClose() do -- Detect window close button or ESC
end end
if (IsKeyPressed(KEY.SPACE)) then if (IsKeyPressed(KEY.SPACE)) then
if (blending == BLEND.ALPHA) then blending = BLEND_ADDITIVE if (blending == BlendMode.ALPHA) then blending = BlendMode.ADDITIVE
else blending = BLEND.ALPHA end else blending = BlendMode.ALPHA end
end end
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
@ -107,7 +99,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC
DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK) DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK)
if (blending == BLEND_ALPHA) then DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK) if (blending == BlendMode.ALPHA) then DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK)
else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE) end else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE) end
EndDrawing() EndDrawing()

297
games/arkanoid.lua Normal file
View File

@ -0,0 +1,297 @@
--[[
raylib - sample game: arkanoid
Sample game Marc Palau and Ramon Santamaria
This game has been created using raylib v1.3 (www.raylib.com)
raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
Copyright (c) 2015 Ramon Santamaria (@raysan5)
Translated to Lua by Ghassan Al-Mashareqa (ghassan@ghassan.pl)
--]]
------------------------------------------------------------------------------------
-- Some Defines
------------------------------------------------------------------------------------
PLAYER_MAX_LIFE = 5
LINES_OF_BRICKS = 5
BRICKS_PER_LINE = 20
------------------------------------------------------------------------------------
-- Types and Structures Definition
------------------------------------------------------------------------------------
GameScreen = { LOGO = 0, TITLE = 1, GAMEPLAY = 2, ENDING = 3 }
function Player()
return { position = Vector2(0,0), size = Vector2(0,0), life = 0 }
end
function Ball()
return { position = Vector2(0,0), speed = Vector2(0,0), radius = 0, active = false }
end
function Brick()
return { position = Vector2(0,0), active = false }
end
--------------------------------------------------------------------------------------
-- Global Variables Declaration
--------------------------------------------------------------------------------------
screenWidth = 800;
screenHeight = 450;
framesCounter = 0;
gameOver = false;
pause = false;
player = Player()
ball = Ball()
brick = {}--[LINES_OF_BRICKS][BRICKS_PER_LINE];
for i = 0, LINES_OF_BRICKS-1 do
brick[i] = {}
for j = 0, BRICKS_PER_LINE-1 do
brick[i][j] = Brick()
end
end
brickSize = Vector2(0,0)
--------------------------------------------------------------------------------------
-- Module Functions Definitions (local)
--------------------------------------------------------------------------------------
-- Initialize game variables
function InitGame()
brickSize = Vector2(GetScreenWidth()/BRICKS_PER_LINE, 40)
-- Initialize player
player.position = Vector2(screenWidth/2, screenHeight*7/8)
player.size = Vector2(screenWidth/10, 20)
player.life = PLAYER_MAX_LIFE;
-- Initialize ball
ball.position = Vector2(screenWidth/2, screenHeight*7/8 - 30)
ball.speed = Vector2(0, 0)
ball.radius = 7;
ball.active = false;
-- Initialize bricks
local initialDownPosition = 50;
for i = 0, LINES_OF_BRICKS-1 do
for j = 0, BRICKS_PER_LINE-1 do
brick[i][j].position = Vector2(j*brickSize.x + brickSize.x/2, i*brickSize.y + initialDownPosition)
brick[i][j].active = true;
end
end
end
-- Update game (one frame)
function UpdateGame()
if (not gameOver) then
if (IsKeyPressed(KEY.P)) then pause = not pause; end
if (not pause) then
-- Player movement
if (IsKeyDown(KEY.LEFT)) then player.position.x = player.position.x - 5; end
if ((player.position.x - player.size.x/2) <= 0) then player.position.x = player.size.x/2; end
if (IsKeyDown(KEY.RIGHT)) then player.position.x = player.position.x + 5; end
if ((player.position.x + player.size.x/2) >= screenWidth) then player.position.x = screenWidth - player.size.x/2; end
-- Launch ball
if (not ball.active) then
if (IsKeyPressed(KEY.SPACE)) then
ball.active = true;
ball.speed = Vector2(0, -5)
end
end
UpdateBall();
-- Game over logic
if (player.life <= 0) then
gameOver = true;
else
gameOver = true;
for i = 0, LINES_OF_BRICKS-1 do
for j = 0, BRICKS_PER_LINE-1 do
if (brick[i][j].active) then gameOver = false; end
end
end
end
end
else
if (IsKeyPressed(KEY.ENTER)) then
InitGame();
gameOver = false;
end
end
end
-- Draw game (one frame)
function DrawGame()
BeginDrawing();
ClearBackground(RAYWHITE);
if (not gameOver) then
-- Draw player bar
DrawRectangle(player.position.x - player.size.x/2, player.position.y - player.size.y/2, player.size.x, player.size.y, BLACK);
-- Draw player lives
for i = 0, player.life-1 do
DrawRectangle(20 + 40*i, screenHeight - 30, 35, 10, LIGHTGRAY);
end
-- Draw ball
DrawCircleV(ball.position, ball.radius, MAROON);
-- Draw bricks
for i = 0, LINES_OF_BRICKS-1 do
for j = 0, BRICKS_PER_LINE-1 do
if (brick[i][j].active) then
if ((i + j) % 2 == 0) then
DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, GRAY);
else
DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, DARKGRAY);
end
end
end
end
if (pause) then
DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
end
else
DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
end
EndDrawing();
end
-- Unload game variables
function UnloadGame()
-- TODO: Unload all dynamic loaded data (textures, sounds, models...)
end
-- Update and Draw (one frame)
function UpdateDrawFrame()
UpdateGame();
DrawGame();
end
----------------------------------------------------------------------------------------
-- Additional module functions
----------------------------------------------------------------------------------------
function UpdateBall()
-- Update position
if (ball.active) then
ball.position.x = ball.position.x + ball.speed.x;
ball.position.y = ball.position.y + ball.speed.y;
else
ball.position = Vector2(player.position.x, screenHeight*7/8 - 30);
end
-- Bounce in x
if (((ball.position.x + ball.radius) >= screenWidth) or ((ball.position.x - ball.radius) <= 0))
then
ball.speed.x = ball.speed.x * -1;
end
-- Bounce in y
if ((ball.position.y - ball.radius) <= 0) then
ball.speed.y = ball.speed.y * -1;
end
-- Ball reaches bottom of the screen
if ((ball.position.y + ball.radius) >= screenHeight) then
ball.speed = Vector2(0, 0);
ball.active = false;
player.life = player.life - 1;
end
-- Collision logic: ball vs player
if CheckCollisionCircleRec(ball.position, ball.radius,
Rectangle(
player.position.x - player.size.x/2,
player.position.y - player.size.y/2,
player.size.x,
player.size.y)) then
if (ball.speed.y > 0) then
ball.speed.y = ball.speed.y * -1;
ball.speed.x = (ball.position.x - player.position.x)/(player.size.x/2)*5;
end
end
-- Collision logic: ball vs bricks
for i = 0,LINES_OF_BRICKS-1 do
for j = 0,BRICKS_PER_LINE-1 do
if (brick[i][j].active) then
-- Hit below
if (((ball.position.y - ball.radius) <= (brick[i][j].position.y + brickSize.y/2)) and
((ball.position.y - ball.radius) > (brick[i][j].position.y + brickSize.y/2 + ball.speed.y)) and
((math.abs(ball.position.x - brick[i][j].position.x)) < (brickSize.x/2 + ball.radius*2/3)) and (ball.speed.y < 0))
then
brick[i][j].active = false;
ball.speed.y = ball.speed.y * -1;
-- Hit above
elseif (((ball.position.y + ball.radius) >= (brick[i][j].position.y - brickSize.y/2)) and
((ball.position.y + ball.radius) < (brick[i][j].position.y - brickSize.y/2 + ball.speed.y)) and
((math.abs(ball.position.x - brick[i][j].position.x)) < (brickSize.x/2 + ball.radius*2/3)) and (ball.speed.y > 0))
then
brick[i][j].active = false;
ball.speed.y = ball.speed.y * -1;
-- Hit left
elseif (((ball.position.x + ball.radius) >= (brick[i][j].position.x - brickSize.x/2)) and
((ball.position.x + ball.radius) < (brick[i][j].position.x - brickSize.x/2 + ball.speed.x)) and
((math.abs(ball.position.y - brick[i][j].position.y)) < (brickSize.y/2 + ball.radius*2/3)) and (ball.speed.x > 0))
then
brick[i][j].active = false;
ball.speed.x = ball.speed.x * -1;
-- Hit right
elseif (((ball.position.x - ball.radius) <= (brick[i][j].position.x + brickSize.x/2)) and
((ball.position.x - ball.radius) > (brick[i][j].position.x + brickSize.x/2 + ball.speed.x)) and
((math.abs(ball.position.y - brick[i][j].position.y)) < (brickSize.y/2 + ball.radius*2/3)) and (ball.speed.x < 0))
then
brick[i][j].active = false;
ball.speed.x = ball.speed.x * -1;
end
end
end
end
end
InitWindow(screenWidth, screenHeight, "sample game: arkanoid");
InitGame();
SetTargetFPS(60);
----------------------------------------------------------------------------------------
-- Main game loop
while (not WindowShouldClose()) -- Detect window close button or ESC key
do
-- Update
------------------------------------------------------------------------------------
UpdateGame();
------------------------------------------------------------------------------------
-- Draw
------------------------------------------------------------------------------------
DrawGame();
------------------------------------------------------------------------------------
end
UnloadGame(); -- Unload loaded data (textures, sounds, models...)
CloseWindow(); -- Close window and OpenGL context

View File

@ -325,6 +325,7 @@ static void LuaBuildOpaqueMetatables(void)
static Vector2 LuaGetArgument_Vector2(lua_State* L, int index) static Vector2 LuaGetArgument_Vector2(lua_State* L, int index)
{ {
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "x") == LUA_TNUMBER, index, "Expected Vector2"); luaL_argcheck(L, lua_getfield(L, index, "x") == LUA_TNUMBER, index, "Expected Vector2");
float x = (float)lua_tonumber(L, -1); float x = (float)lua_tonumber(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "y") == LUA_TNUMBER, index, "Expected Vector2"); luaL_argcheck(L, lua_getfield(L, index, "y") == LUA_TNUMBER, index, "Expected Vector2");
@ -335,6 +336,7 @@ static Vector2 LuaGetArgument_Vector2(lua_State* L, int index)
static Vector3 LuaGetArgument_Vector3(lua_State* L, int index) static Vector3 LuaGetArgument_Vector3(lua_State* L, int index)
{ {
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "x") == LUA_TNUMBER, index, "Expected Vector3"); luaL_argcheck(L, lua_getfield(L, index, "x") == LUA_TNUMBER, index, "Expected Vector3");
float x = (float)lua_tonumber(L, -1); float x = (float)lua_tonumber(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "y") == LUA_TNUMBER, index, "Expected Vector3"); luaL_argcheck(L, lua_getfield(L, index, "y") == LUA_TNUMBER, index, "Expected Vector3");
@ -347,6 +349,7 @@ static Vector3 LuaGetArgument_Vector3(lua_State* L, int index)
static Quaternion LuaGetArgument_Quaternion(lua_State* L, int index) static Quaternion LuaGetArgument_Quaternion(lua_State* L, int index)
{ {
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "x") == LUA_TNUMBER, index, "Expected Quaternion"); luaL_argcheck(L, lua_getfield(L, index, "x") == LUA_TNUMBER, index, "Expected Quaternion");
float x = (float)lua_tonumber(L, -1); float x = (float)lua_tonumber(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "y") == LUA_TNUMBER, index, "Expected Quaternion"); luaL_argcheck(L, lua_getfield(L, index, "y") == LUA_TNUMBER, index, "Expected Quaternion");
@ -361,6 +364,7 @@ static Quaternion LuaGetArgument_Quaternion(lua_State* L, int index)
static Color LuaGetArgument_Color(lua_State* L, int index) static Color LuaGetArgument_Color(lua_State* L, int index)
{ {
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "r") == LUA_TNUMBER, index, "Expected Color"); luaL_argcheck(L, lua_getfield(L, index, "r") == LUA_TNUMBER, index, "Expected Color");
unsigned char r = (unsigned char)lua_tointeger(L, -1); unsigned char r = (unsigned char)lua_tointeger(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "g") == LUA_TNUMBER, index, "Expected Color"); luaL_argcheck(L, lua_getfield(L, index, "g") == LUA_TNUMBER, index, "Expected Color");
@ -375,6 +379,7 @@ static Color LuaGetArgument_Color(lua_State* L, int index)
static Rectangle LuaGetArgument_Rectangle(lua_State* L, int index) static Rectangle LuaGetArgument_Rectangle(lua_State* L, int index)
{ {
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "x") == LUA_TNUMBER, index, "Expected Rectangle"); luaL_argcheck(L, lua_getfield(L, index, "x") == LUA_TNUMBER, index, "Expected Rectangle");
int x = (int)lua_tointeger(L, -1); int x = (int)lua_tointeger(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "y") == LUA_TNUMBER, index, "Expected Rectangle"); luaL_argcheck(L, lua_getfield(L, index, "y") == LUA_TNUMBER, index, "Expected Rectangle");
@ -390,13 +395,14 @@ static Rectangle LuaGetArgument_Rectangle(lua_State* L, int index)
static Camera LuaGetArgument_Camera(lua_State* L, int index) static Camera LuaGetArgument_Camera(lua_State* L, int index)
{ {
Camera result; Camera result;
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "position") == LUA_TTABLE, index, "Expected Camera"); luaL_argcheck(L, lua_getfield(L, index, "position") == LUA_TTABLE, index, "Expected Camera");
result.position = LuaGetArgument_Vector3(L, -1); result.position = LuaGetArgument_Vector3(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "target") == LUA_TTABLE, index, "Expected Camera"); luaL_argcheck(L, lua_getfield(L, index, "target") == LUA_TTABLE, index, "Expected Camera");
result.target = LuaGetArgument_Vector3(L, -1); result.target = LuaGetArgument_Vector3(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "up") == LUA_TTABLE, index, "Expected Camera"); luaL_argcheck(L, lua_getfield(L, index, "up") == LUA_TTABLE, index, "Expected Camera");
result.up = LuaGetArgument_Vector3(L, -1); result.up = LuaGetArgument_Vector3(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "fovy") == LUA_TTABLE, index, "Expected Camera"); luaL_argcheck(L, lua_getfield(L, index, "fovy") == LUA_TNUMBER, index, "Expected Camera");
result.fovy = LuaGetArgument_float(L, -1); result.fovy = LuaGetArgument_float(L, -1);
lua_pop(L, 4); lua_pop(L, 4);
return result; return result;
@ -405,13 +411,14 @@ static Camera LuaGetArgument_Camera(lua_State* L, int index)
static Camera2D LuaGetArgument_Camera2D(lua_State* L, int index) static Camera2D LuaGetArgument_Camera2D(lua_State* L, int index)
{ {
Camera2D result; Camera2D result;
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "offset") == LUA_TTABLE, index, "Expected Camera2D"); luaL_argcheck(L, lua_getfield(L, index, "offset") == LUA_TTABLE, index, "Expected Camera2D");
result.offset = LuaGetArgument_Vector2(L, -1); result.offset = LuaGetArgument_Vector2(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "target") == LUA_TTABLE, index, "Expected Camera2D"); luaL_argcheck(L, lua_getfield(L, index, "target") == LUA_TTABLE, index, "Expected Camera2D");
result.target = LuaGetArgument_Vector2(L, -1); result.target = LuaGetArgument_Vector2(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "rotation") == LUA_TTABLE, index, "Expected Camera2D"); luaL_argcheck(L, lua_getfield(L, index, "rotation") == LUA_TNUMBER, index, "Expected Camera2D");
result.rotation = LuaGetArgument_float(L, -1); result.rotation = LuaGetArgument_float(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "zoom") == LUA_TTABLE, index, "Expected Camera2D"); luaL_argcheck(L, lua_getfield(L, index, "zoom") == LUA_TNUMBER, index, "Expected Camera2D");
result.zoom = LuaGetArgument_float(L, -1); result.zoom = LuaGetArgument_float(L, -1);
lua_pop(L, 4); lua_pop(L, 4);
return result; return result;
@ -420,6 +427,7 @@ static Camera2D LuaGetArgument_Camera2D(lua_State* L, int index)
static BoundingBox LuaGetArgument_BoundingBox(lua_State* L, int index) static BoundingBox LuaGetArgument_BoundingBox(lua_State* L, int index)
{ {
BoundingBox result; BoundingBox result;
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "min") == LUA_TTABLE, index, "Expected BoundingBox"); luaL_argcheck(L, lua_getfield(L, index, "min") == LUA_TTABLE, index, "Expected BoundingBox");
result.min = LuaGetArgument_Vector3(L, -1); result.min = LuaGetArgument_Vector3(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "max") == LUA_TTABLE, index, "Expected BoundingBox"); luaL_argcheck(L, lua_getfield(L, index, "max") == LUA_TTABLE, index, "Expected BoundingBox");
@ -431,6 +439,7 @@ static BoundingBox LuaGetArgument_BoundingBox(lua_State* L, int index)
static Ray LuaGetArgument_Ray(lua_State* L, int index) static Ray LuaGetArgument_Ray(lua_State* L, int index)
{ {
Ray result; Ray result;
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "position") == LUA_TTABLE, index, "Expected Ray"); luaL_argcheck(L, lua_getfield(L, index, "position") == LUA_TTABLE, index, "Expected Ray");
result.position = LuaGetArgument_Vector3(L, -1); result.position = LuaGetArgument_Vector3(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "direction") == LUA_TTABLE, index, "Expected Ray"); luaL_argcheck(L, lua_getfield(L, index, "direction") == LUA_TTABLE, index, "Expected Ray");
@ -443,10 +452,12 @@ static Matrix LuaGetArgument_Matrix(lua_State* L, int index)
{ {
Matrix result = { 0 }; Matrix result = { 0 };
float* ptr = &result.m0; float* ptr = &result.m0;
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
lua_geti(L, -1, i+1); lua_geti(L, index, i+1);
ptr[i] = luaL_checkinteger(L, -1); ptr[i] = luaL_checknumber(L, -1);
} }
lua_pop(L, 16); lua_pop(L, 16);
return result; return result;
@ -455,6 +466,7 @@ static Matrix LuaGetArgument_Matrix(lua_State* L, int index)
static Material LuaGetArgument_Material(lua_State* L, int index) static Material LuaGetArgument_Material(lua_State* L, int index)
{ {
Material result; Material result;
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "shader") == LUA_TUSERDATA, index, "Expected Material"); luaL_argcheck(L, lua_getfield(L, index, "shader") == LUA_TUSERDATA, index, "Expected Material");
result.shader = LuaGetArgument_Shader(L, -1); result.shader = LuaGetArgument_Shader(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "texDiffuse") == LUA_TUSERDATA, index, "Expected Material"); luaL_argcheck(L, lua_getfield(L, index, "texDiffuse") == LUA_TUSERDATA, index, "Expected Material");
@ -463,13 +475,13 @@ static Material LuaGetArgument_Material(lua_State* L, int index)
result.texNormal = LuaGetArgument_Texture2D(L, -1); result.texNormal = LuaGetArgument_Texture2D(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "texSpecular") == LUA_TUSERDATA, index, "Expected Material"); luaL_argcheck(L, lua_getfield(L, index, "texSpecular") == LUA_TUSERDATA, index, "Expected Material");
result.texSpecular = LuaGetArgument_Texture2D(L, -1); result.texSpecular = LuaGetArgument_Texture2D(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "colDiffuse") == LUA_TUSERDATA, index, "Expected Material"); luaL_argcheck(L, lua_getfield(L, index, "colDiffuse") == LUA_TTABLE, index, "Expected Material");
result.colDiffuse = LuaGetArgument_Color(L, -1); result.colDiffuse = LuaGetArgument_Color(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "colAmbient") == LUA_TUSERDATA, index, "Expected Material"); luaL_argcheck(L, lua_getfield(L, index, "colAmbient") == LUA_TTABLE, index, "Expected Material");
result.colAmbient = LuaGetArgument_Color(L, -1); result.colAmbient = LuaGetArgument_Color(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "colSpecular") == LUA_TUSERDATA, index, "Expected Material"); luaL_argcheck(L, lua_getfield(L, index, "colSpecular") == LUA_TTABLE, index, "Expected Material");
result.colSpecular = LuaGetArgument_Color(L, -1); result.colSpecular = LuaGetArgument_Color(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "glossiness") == LUA_TUSERDATA, index, "Expected Material"); luaL_argcheck(L, lua_getfield(L, index, "glossiness") == LUA_TNUMBER, index, "Expected Material");
result.glossiness = LuaGetArgument_float(L, -1); result.glossiness = LuaGetArgument_float(L, -1);
lua_pop(L, 8); lua_pop(L, 8);
return result; return result;
@ -478,6 +490,7 @@ static Material LuaGetArgument_Material(lua_State* L, int index)
static Model LuaGetArgument_Model(lua_State* L, int index) static Model LuaGetArgument_Model(lua_State* L, int index)
{ {
Model result; Model result;
index = lua_absindex(L, index); // Makes sure we use absolute indices because we push multiple values
luaL_argcheck(L, lua_getfield(L, index, "mesh") == LUA_TUSERDATA, index, "Expected Model"); luaL_argcheck(L, lua_getfield(L, index, "mesh") == LUA_TUSERDATA, index, "Expected Model");
result.mesh = LuaGetArgument_Mesh(L, -1); result.mesh = LuaGetArgument_Mesh(L, -1);
luaL_argcheck(L, lua_getfield(L, index, "transform") == LUA_TTABLE, index, "Expected Model"); luaL_argcheck(L, lua_getfield(L, index, "transform") == LUA_TTABLE, index, "Expected Model");
@ -3637,6 +3650,7 @@ static luaL_Reg raylib_functions[] = {
REG(LoadRenderTexture) REG(LoadRenderTexture)
REG(UnloadImage) REG(UnloadImage)
REG(UnloadTexture) REG(UnloadTexture)
REG(UnloadRenderTexture)
REG(GetImageData) REG(GetImageData)
REG(GetTextureData) REG(GetTextureData)
REG(ImageToPOT) REG(ImageToPOT)
@ -3698,6 +3712,10 @@ static luaL_Reg raylib_functions[] = {
REG(LoadHeightmap) REG(LoadHeightmap)
REG(LoadCubicmap) REG(LoadCubicmap)
REG(UnloadModel) REG(UnloadModel)
REG(LoadMaterial)
REG(LoadDefaultMaterial)
REG(LoadStandardMaterial)
REG(UnloadMaterial)
//REG(GenMesh*) // Not ready yet... //REG(GenMesh*) // Not ready yet...
REG(DrawModel) REG(DrawModel)
@ -3972,6 +3990,8 @@ RLUADEF void InitLuaDevice(void)
LuaSetEnum("XBOX_AXIS_RIGHT_Y", 3); LuaSetEnum("XBOX_AXIS_RIGHT_Y", 3);
LuaSetEnum("XBOX_AXIS_LT_RT", 2); LuaSetEnum("XBOX_AXIS_LT_RT", 2);
#endif #endif
LuaSetEnum("XBOX_AXIS_LEFT_X", 0);
LuaSetEnum("XBOX_AXIS_LEFT_Y", 1);
LuaEndEnum("GAMEPAD"); LuaEndEnum("GAMEPAD");
lua_pushglobaltable(L); lua_pushglobaltable(L);