summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjussi2024-03-17 10:38:30 +0200
committerjussi2024-03-17 10:38:30 +0200
commitae1d0b65f16b24f2e0db39cb8baef4af57b2a12f (patch)
tree80358810635da19821bdb38ece2098c2dd48f1ff /examples
parentca238975dc63d2dddcd2b17ad627bedc95dd158c (diff)
downloadreilua-enhanced-ae1d0b65f16b24f2e0db39cb8baef4af57b2a12f.tar.gz
reilua-enhanced-ae1d0b65f16b24f2e0db39cb8baef4af57b2a12f.tar.bz2
reilua-enhanced-ae1d0b65f16b24f2e0db39cb8baef4af57b2a12f.zip
Round and pubsub lib.
Diffstat (limited to 'examples')
-rw-r--r--examples/heightmap/main.lua4
-rw-r--r--examples/lightmap/main.lua9
-rw-r--r--examples/raygui_extensions/main.lua4
-rw-r--r--examples/resources/lib/color.lua9
-rw-r--r--examples/resources/lib/pubsub.lua34
-rw-r--r--examples/resources/lib/utillib.lua5
-rw-r--r--examples/snake/main.lua2
-rw-r--r--examples/window/main.lua6
8 files changed, 60 insertions, 13 deletions
diff --git a/examples/heightmap/main.lua b/examples/heightmap/main.lua
index db03e97..91c532f 100644
--- a/examples/heightmap/main.lua
+++ b/examples/heightmap/main.lua
@@ -40,8 +40,6 @@ function RL.init()
camera:setTarget( { 0, 0, 0 } )
camera:setUp( { 0, 1, 0 } )
camera.mode = camera.MODES.ORBITAL
- -- camera.mode = camera.MODES.FREE
- -- camera.mode = camera.MODES.FIRST_PERSON
heigthImage = RL.LoadImage( RL.GetBasePath().."../resources/images/heightmap.png" )
@@ -78,7 +76,7 @@ function RL.init()
material = RL.LoadMaterialDefault()
RL.SetMaterialTexture( material, RL.MATERIAL_MAP_ALBEDO, groundTexture )
- matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) )
+ matrix = RL.MatrixTranslate( { -4, 0, -4 } )
end
function RL.update( delta )
diff --git a/examples/lightmap/main.lua b/examples/lightmap/main.lua
index b7f3a93..20a2729 100644
--- a/examples/lightmap/main.lua
+++ b/examples/lightmap/main.lua
@@ -31,15 +31,12 @@ function RL.init()
camera:setTarget( { 0, 0, 0 } )
camera:setUp( { 0, 1, 0 } )
camera.mode = camera.MODES.ORBITAL
- -- camera.mode = camera.MODES.FREE
- -- camera.mode = camera.MODES.FIRST_PERSON
- local ts = PLANE_SIZE
local meshData = {
vertices = { { 0, 0, 0 }, { 0, 0, PLANE_SIZE }, { PLANE_SIZE, 0, PLANE_SIZE },
{ 0, 0, 0 }, { PLANE_SIZE, 0, PLANE_SIZE }, { PLANE_SIZE, 0, 0 } },
- texcoords = { { 0, 0 }, { 0, ts }, { ts, ts },
- { 0, 0 }, { ts, ts }, { ts, 0 } },
+ texcoords = { { 0, 0 }, { 0, PLANE_SIZE }, { PLANE_SIZE, PLANE_SIZE },
+ { 0, 0 }, { PLANE_SIZE, PLANE_SIZE }, { PLANE_SIZE, 0 } },
texcoords2 = { { 0, 0 }, { 0, 1 }, { 1, 1 },
{ 0, 0 }, { 1, 1 }, { 1, 0 } },
colors = { RL.WHITE, RL.WHITE, RL.WHITE,
@@ -80,7 +77,7 @@ function RL.init()
},
}
material = RL.CreateMaterial( materialData )
- matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) )
+ matrix = RL.MatrixTranslate( { -PLANE_SIZE / 2, 0, -PLANE_SIZE / 2 } )
end
function RL.update( delta )
diff --git a/examples/raygui_extensions/main.lua b/examples/raygui_extensions/main.lua
index a7dfa15..35cf48a 100644
--- a/examples/raygui_extensions/main.lua
+++ b/examples/raygui_extensions/main.lua
@@ -79,7 +79,9 @@ local function addPropertyList()
nil,
{
properties = {
- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
+ -- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
+ { RL.LISTVIEW, RL.BORDER_COLOR_FOCUSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) },
+ { RL.LISTVIEW, RL.BORDER_COLOR_PRESSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) },
}
}
)
diff --git a/examples/resources/lib/color.lua b/examples/resources/lib/color.lua
index 9369a34..a508fa3 100644
--- a/examples/resources/lib/color.lua
+++ b/examples/resources/lib/color.lua
@@ -144,4 +144,13 @@ function Color:alphaBlend( dst, src, tint )
return Color:new( RL.ColorAlphaBlend( dst, src, tint ) )
end
+function Color:lerp( color, amount )
+ return Color:new(
+ RL.Lerp( self.r, color.r, amount ),
+ RL.Lerp( self.g, color.g, amount ),
+ RL.Lerp( self.b, color.b, amount ),
+ RL.Lerp( self.a, color.a, amount )
+ )
+end
+
return Color
diff --git a/examples/resources/lib/pubsub.lua b/examples/resources/lib/pubsub.lua
new file mode 100644
index 0000000..2847d92
--- /dev/null
+++ b/examples/resources/lib/pubsub.lua
@@ -0,0 +1,34 @@
+local PubSub = {}
+PubSub.__index = PubSub
+
+function PubSub:new()
+ local object = setmetatable( {}, self )
+
+ object.signals = {}
+
+ return object
+end
+
+function PubSub:add( name )
+ self.signals[ name ] = {}
+end
+
+function PubSub:subscribe( name, func )
+ table.insert( self.signals[ name ], func )
+end
+
+function PubSub:unSubscribe( name, uFunc )
+ for i, func in ipairs( self.signals[ name ] ) do
+ if func == uFunc then
+ table.remove( self.signals[ name ], i )
+ end
+ end
+end
+
+function PubSub:publish( name, ... )
+ for _, func in ipairs( self.signals[ name ] ) do
+ func( ... )
+ end
+end
+
+return PubSub
diff --git a/examples/resources/lib/utillib.lua b/examples/resources/lib/utillib.lua
index 0b54e12..73bb11c 100644
--- a/examples/resources/lib/utillib.lua
+++ b/examples/resources/lib/utillib.lua
@@ -1,5 +1,10 @@
-- Define useful global functions.
+-- For luaJit compatibility.
+if table.unpack == nil then
+ table.unpack = unpack
+end
+
local utillib = {}
function utillib.tableClone( org )
diff --git a/examples/snake/main.lua b/examples/snake/main.lua
index 3a3243f..d28901d 100644
--- a/examples/snake/main.lua
+++ b/examples/snake/main.lua
@@ -248,4 +248,6 @@ function RL.draw()
0.0,
RL.WHITE
)
+
+ RL.DrawFPS( { 20, 20 } )
end
diff --git a/examples/window/main.lua b/examples/window/main.lua
index ec2377b..77ac64c 100644
--- a/examples/window/main.lua
+++ b/examples/window/main.lua
@@ -11,10 +11,10 @@ end
function RL.update( delta )
if RL.IsKeyPressed( RL.KEY_ENTER ) then
local winSize = RL.GetScreenSize()
+ local measuredSize = RL.MeasureTextEx( RL.GetFontDefault(), text, textSize, 2 )
- textSize = RL.MeasureText( text, textSize )
textColor = RL.BLUE
- textPos = { winSize[1] / 2 - textSize[1] / 2, winSize[2] / 2 - textSize[2] / 2 }
+ textPos = { winSize[1] / 2 - measuredSize[1] / 2, winSize[2] / 2 - measuredSize[2] / 2 }
end
if RL.IsKeyPressed( RL.KEY_SPACE ) then
@@ -25,5 +25,5 @@ end
function RL.draw()
RL.ClearBackground( RL.RAYWHITE )
- RL.DrawText( text, textPos, textSize, textColor )
+ RL.DrawText( text, textPos, textSize, textColor )
end