diff options
| author | jussi | 2022-05-04 17:21:49 +0300 |
|---|---|---|
| committer | jussi | 2022-05-04 17:21:49 +0300 |
| commit | ed4636fa812e64c5391ee9f408092990f33277b4 (patch) | |
| tree | 9ea8054c54c5dd2d9da449f401d3c064a3b6114a /examples | |
| parent | 6f4aceeb4c9793ff8b86cbae99d5475b987af9eb (diff) | |
| download | reilua-enhanced-ed4636fa812e64c5391ee9f408092990f33277b4.tar.gz reilua-enhanced-ed4636fa812e64c5391ee9f408092990f33277b4.tar.bz2 reilua-enhanced-ed4636fa812e64c5391ee9f408092990f33277b4.zip | |
Camera2D.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/2D_camera/main.lua | 67 | ||||
| -rw-r--r-- | examples/waving_cubes/main.lua | 2 |
2 files changed, 67 insertions, 2 deletions
diff --git a/examples/2D_camera/main.lua b/examples/2D_camera/main.lua new file mode 100644 index 0000000..23128dc --- /dev/null +++ b/examples/2D_camera/main.lua @@ -0,0 +1,67 @@ +local tileTexture = -1 +local camera = -1 +local cameraPos = { 0, 0 } +local cameraRot = 0.0 +local cameraZoom = 1.0 +local cameraSpeed = 100.0 +local cameraRotSpeed = 100.0 +local cameraZoomSpeed = 10.0 + +function init() + local monitor = 0 + local mPos = RL_GetMonitorPosition( monitor ) + local mSize = RL_GetMonitorSize( monitor ) + local winSize = RL_GetWindowSize() + + RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) + RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL_SetWindowTitle( "Camera 2D" ) + + tileTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" ) + camera = RL_CreateCamera2D() + RL_SetCamera2DOffset( camera, { winSize[1] / 2, winSize[2] / 2 } ) +end + +function process( delta ) + -- Move. + if RL_IsKeyDown( KEY_RIGHT ) then + cameraPos[1] = cameraPos[1] + cameraSpeed * delta + elseif RL_IsKeyDown( KEY_LEFT ) then + cameraPos[1] = cameraPos[1] - cameraSpeed * delta + end + if RL_IsKeyDown( KEY_DOWN ) then + cameraPos[2] = cameraPos[2] + cameraSpeed * delta + elseif RL_IsKeyDown( KEY_UP ) then + cameraPos[2] = cameraPos[2] - cameraSpeed * delta + end + -- Rotate. + if RL_IsKeyDown( string.byte( "E" ) ) then + cameraRot = cameraRot + cameraRotSpeed * delta + elseif RL_IsKeyDown( string.byte( "Q" ) ) then + cameraRot = cameraRot - cameraRotSpeed * delta + end + -- Zoom. + if RL_IsKeyDown( string.byte( "R" ) ) then + cameraZoom = cameraZoom + cameraZoomSpeed * delta + elseif RL_IsKeyDown( string.byte( "F" ) ) then + cameraZoom = cameraZoom - cameraZoomSpeed * delta + end +end + +function draw() + RL_ClearBackground( RAYWHITE ) + RL_SetCamera2DTarget( camera, cameraPos ) + RL_SetCamera2DRotation( camera, cameraRot ) + RL_SetCamera2DZoom( camera, cameraZoom ) + + RL_BeginMode2D( camera ) + -- Draw wall. + for y = 0, 4 do + for x = 0, 6 do + RL_DrawTextureRec( tileTexture, { 0, 0, 32, 32 }, { x * 32, y * 32 }, WHITE ) + end + end + -- Draw hero. + RL_DrawTextureRec( tileTexture, { 3 * 32, 0, 32, 32 }, { cameraPos[1] - 16, cameraPos[2] - 16 }, WHITE ) + RL_EndMode2D() +end diff --git a/examples/waving_cubes/main.lua b/examples/waving_cubes/main.lua index 969dc3c..90e7b5d 100644 --- a/examples/waving_cubes/main.lua +++ b/examples/waving_cubes/main.lua @@ -6,9 +6,7 @@ Modified by Jussi Viitala (@nullstare) for ReiLua style. ]] -local winSize = RL_GetWindowSize() local camera = -1 - local num_blocks = 15 function init() |
