summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/automation_events/main.lua97
-rw-r--r--examples/resources/lib/quaternion.lua28
-rw-r--r--examples/resources/lib/vector2.lua20
-rw-r--r--examples/resources/lib/vector3.lua24
4 files changed, 169 insertions, 0 deletions
diff --git a/examples/automation_events/main.lua b/examples/automation_events/main.lua
new file mode 100644
index 0000000..33589a4
--- /dev/null
+++ b/examples/automation_events/main.lua
@@ -0,0 +1,97 @@
+package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
+
+Vec2 = require( "vector2" )
+
+local eventList = nil
+local evenRecording = false
+local eventPlaying = false
+local frameCounter = 0
+local playFrameCounter = 0
+local currentPlayFrame = 0
+local player = {
+ pos = Vec2:new( 160, 200 ),
+ speed = 100.0,
+}
+
+function RL.init()
+ RL.SetWindowTitle( "Automation Events" )
+ RL.SetWindowState( RL.FLAG_VSYNC_HINT )
+ RL.SetTextLineSpacing( 25 )
+
+ eventList = RL.LoadAutomationEventList( nil )
+ RL.SetAutomationEventList( eventList )
+end
+
+function RL.update( delta )
+ local moveDir = Vec2:new()
+
+ if RL.IsKeyDown( RL.KEY_RIGHT ) then
+ moveDir.x = 1
+ elseif RL.IsKeyDown( RL.KEY_LEFT ) then
+ moveDir.x = -1
+ end
+
+ if RL.IsKeyDown( RL.KEY_DOWN ) then
+ moveDir.y = 1
+ elseif RL.IsKeyDown( RL.KEY_UP ) then
+ moveDir.y = -1
+ end
+
+ player.pos:addEq( moveDir:scale( player.speed * delta ) )
+
+ -- Events.
+
+ if RL.IsKeyPressed( RL.KEY_S ) then
+ evenRecording = not evenRecording
+
+ if evenRecording then
+ RL.StartAutomationEventRecording()
+ else
+ RL.StopAutomationEventRecording()
+ end
+ end
+ if RL.IsKeyPressed( RL.KEY_A ) then
+ eventPlaying = not eventPlaying
+ evenRecording = false
+ playFrameCounter = 0
+ currentPlayFrame = 0
+ end
+
+ if eventPlaying then
+ while playFrameCounter == RL.GetAutomationEventFrame( RL.GetAutomationEvent( eventList, currentPlayFrame ) ) do
+ RL.TraceLog( RL.LOG_INFO, "playFrameCounter: "..playFrameCounter.."\tcurrentPlayFrame: "..currentPlayFrame )
+
+ RL.PlayAutomationEvent( RL.GetAutomationEvent( eventList, currentPlayFrame ) )
+ currentPlayFrame = currentPlayFrame + 1
+
+ if currentPlayFrame == RL.GetAutomationEventListCount( eventList ) then
+ eventPlaying = false
+ currentPlayFrame = 0
+ playFrameCounter = 0
+
+ RL.TraceLog( RL.LOG_INFO, "FINISH PLAYING!" )
+ break
+ end
+ end
+
+ playFrameCounter = playFrameCounter + 1
+ end
+end
+
+function RL.draw()
+ RL.ClearBackground( RL.RAYWHITE )
+ RL.DrawCircle( player.pos, 8.0, RL.BLUE )
+
+ local text = "Toggle recording: S\nToggle play: A\n"
+ local textColor = RL.GREEN
+
+ if evenRecording then
+ text = text.."Recording"
+ textColor = RL.RED
+ elseif eventPlaying then
+ text = text.."Playing"
+ textColor = RL.BLUE
+ end
+
+ RL.DrawText( text, { 20, 20 }, 20, textColor )
+end
diff --git a/examples/resources/lib/quaternion.lua b/examples/resources/lib/quaternion.lua
index 56b5c49..dfb07f4 100644
--- a/examples/resources/lib/quaternion.lua
+++ b/examples/resources/lib/quaternion.lua
@@ -153,4 +153,32 @@ function Quaternion:transform( mat )
return Quaternion:new( RL.QuaternionTransform( self, mat ) )
end
+function Quaternion:addEq( q2 )
+ self.x = self.x + q2.x
+ self.y = self.y + q2.y
+ self.z = self.z + q2.z
+ self.w = self.w + q2.w
+end
+
+function Quaternion:subEq( q2 )
+ self.x = self.x - q2.x
+ self.y = self.y - q2.y
+ self.z = self.z - q2.z
+ self.w = self.w - q2.w
+end
+
+function Quaternion:mulEq( q2 )
+ self.x = self.x * q2.x
+ self.y = self.y * q2.y
+ self.z = self.z * q2.z
+ self.w = self.w * q2.w
+end
+
+function Quaternion:divEq( q2 )
+ self.x = self.x / q2.x
+ self.y = self.y / q2.y
+ self.z = self.z / q2.z
+ self.w = self.w / q2.w
+end
+
return Quaternion
diff --git a/examples/resources/lib/vector2.lua b/examples/resources/lib/vector2.lua
index d66cd07..7672589 100644
--- a/examples/resources/lib/vector2.lua
+++ b/examples/resources/lib/vector2.lua
@@ -181,4 +181,24 @@ function Vector2:equals( v2 )
return RL.Vector2Equals( self, v2 )
end
+function Vector2:addEq( v2 )
+ self.x = self.x + v2.x
+ self.y = self.y + v2.y
+end
+
+function Vector2:subEq( v2 )
+ self.x = self.x - v2.x
+ self.y = self.y - v2.y
+end
+
+function Vector2:mulEq( v2 )
+ self.x = self.x * v2.x
+ self.y = self.y * v2.y
+end
+
+function Vector2:divEq( v2 )
+ self.x = self.x / v2.x
+ self.y = self.y / v2.y
+end
+
return Vector2
diff --git a/examples/resources/lib/vector3.lua b/examples/resources/lib/vector3.lua
index 037e440..eda39e2 100644
--- a/examples/resources/lib/vector3.lua
+++ b/examples/resources/lib/vector3.lua
@@ -208,4 +208,28 @@ function Vector3:equals( v2 )
return RL.Vector3Equals( self, v2 )
end
+function Vector3:addEq( v2 )
+ self.x = self.x + v2.x
+ self.y = self.y + v2.y
+ self.z = self.z + v2.z
+end
+
+function Vector3:subEq( v2 )
+ self.x = self.x - v2.x
+ self.y = self.y - v2.y
+ self.z = self.z - v2.z
+end
+
+function Vector3:mulEq( v2 )
+ self.x = self.x * v2.x
+ self.y = self.y * v2.y
+ self.z = self.z * v2.z
+end
+
+function Vector3:divEq( v2 )
+ self.x = self.x / v2.x
+ self.y = self.y / v2.y
+ self.z = self.z / v2.z
+end
+
return Vector3