diff options
| author | jussi | 2023-04-06 12:31:37 +0300 |
|---|---|---|
| committer | jussi | 2023-04-06 12:31:37 +0300 |
| commit | 2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a (patch) | |
| tree | 825775577403d9341045571adb266173513c4bbd /examples/dungeon_crawler | |
| parent | 198a74c0aa27389c062c47bc29187c58a9d6c4a1 (diff) | |
| download | reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.tar.gz reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.tar.bz2 reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.zip | |
All global variables and functions are not in global RL table. doc_parser creates also ReiLua_API.lua.
Diffstat (limited to 'examples/dungeon_crawler')
| -rw-r--r-- | examples/dungeon_crawler/main.lua | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/examples/dungeon_crawler/main.lua b/examples/dungeon_crawler/main.lua index e1342ec..8732b0d 100644 --- a/examples/dungeon_crawler/main.lua +++ b/examples/dungeon_crawler/main.lua @@ -4,12 +4,12 @@ local camera = -1 local texture = -1 local textureSize = { 256, 96 } local res = { 384, 216 } -local winSize = RL_GetScreenSize() +local winSize = RL.GetScreenSize() local winScale = 4 local framebuffer = -1 local TILE_SIZE = 32 -local TILE_VERTEX_COLORS = { WHITE, WHITE, WHITE, WHITE } +local TILE_VERTEX_COLORS = { RL.WHITE, RL.WHITE, RL.WHITE, RL.WHITE } local FLOOR = 1 local CEILING = 2 @@ -51,38 +51,37 @@ local function getTileVer( x, y, type ) return verts end -function drawSprites() +local function drawSprites() for _, sprite in ipairs( sprites ) do - sprite.dis = RL_Vector2Distance( { pos[1], pos[3] }, { sprite.pos[1], sprite.pos[2] } ) + sprite.dis = RL.Vector2Distance( { pos[1], pos[3] }, { sprite.pos[1], sprite.pos[2] } ) end - + table.sort( sprites, function( a, b ) return a.dis > b.dis end ) for _, sprite in ipairs( sprites ) do - RL_DrawBillboardRec( camera, texture, { sprite.tile[1] * TILE_SIZE, sprite.tile[2] * TILE_SIZE, TILE_SIZE, TILE_SIZE }, - { sprite.pos[1], 0.5 * sprite.size, sprite.pos[2] }, { sprite.size, sprite.size }, WHITE ) + RL.DrawBillboardRec( camera, texture, { sprite.tile[1] * TILE_SIZE, sprite.tile[2] * TILE_SIZE, TILE_SIZE, TILE_SIZE }, + { sprite.pos[1], 0.5 * sprite.size, sprite.pos[2] }, { sprite.size, sprite.size }, RL.WHITE ) end end -function init() +function RL.init() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) winSize = { res[1] * winScale, res[2] * winScale } - RL_SetWindowSize( winSize ) - RL_SetExitKey( KEY_ESCAPE ) - -- framebuffer = RL_LoadRenderTexture( res ) - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - - texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" ) - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, pos ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCameraMode( camera, CAMERA_FIRST_PERSON ) + RL.SetWindowSize( winSize ) + RL.SetExitKey( RL.KEY_ESCAPE ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + + texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/tiles.png" ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, pos ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCameraMode( camera, RL.CAMERA_FIRST_PERSON ) -- for x = 0, 3 do -- for y = 0, 9 do @@ -94,41 +93,41 @@ function init() table.insert( sprites, { pos = { 0.5, 3.5 }, tile = { 3, 0 }, dis = 0, size = 0.7 } ) end -function draw() - RL_UpdateCamera3D( camera ) - pos = RL_GetCamera3DPosition( camera ) +function RL.draw() + RL.UpdateCamera3D( camera ) + pos = RL.GetCamera3DPosition( camera ) - -- RL_BeginTextureMode( framebuffer ) - RL_ClearBackground( { 100, 150, 150 } ) + -- RL.BeginTextureMode( framebuffer ) + RL.ClearBackground( { 100, 150, 150 } ) - RL_BeginMode3D( camera ) + RL.BeginMode3D( camera ) -- Floor and ceiling. for x = 0, 3 do for y = 0, 10 do - RL_DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), TILE_VERTEX_COLORS ) end end -- Walls. - RL_DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) for x = 0, 3 do - RL_DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) end for y = 0, 10 do - RL_DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) end drawSprites() - RL_EndMode3D() - -- RL_EndTextureMode() + RL.EndMode3D() + -- RL.EndTextureMode() - -- RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) - -- RL_DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE ) - -- RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE ) + -- RL.SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) + -- RL.DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE ) + -- RL.SetTextureSource( TEXTURE_SOURCE_TEXTURE ) end |
