diff options
| author | jussi | 2022-05-27 17:53:48 +0300 |
|---|---|---|
| committer | jussi | 2022-05-27 17:53:48 +0300 |
| commit | 381adb3ba2e1c668bf29f95b8356ac8a859e0f3e (patch) | |
| tree | d9be867383f7734a26582cbaadcd912d47f85a29 | |
| parent | acad17965dee43816200b889f98f04f6ff80a939 (diff) | |
| download | reilua-enhanced-381adb3ba2e1c668bf29f95b8356ac8a859e0f3e.tar.gz reilua-enhanced-381adb3ba2e1c668bf29f95b8356ac8a859e0f3e.tar.bz2 reilua-enhanced-381adb3ba2e1c668bf29f95b8356ac8a859e0f3e.zip | |
Iqm test.
| -rw-r--r-- | examples/iqm_test/main.lua | 90 | ||||
| -rw-r--r-- | examples/platformer/main.lua | 6 | ||||
| -rw-r--r-- | examples/resources/images/monkey_tex.png | bin | 0 -> 9253 bytes | |||
| -rw-r--r-- | examples/resources/iqm/monkey.iqm | bin | 0 -> 137448 bytes | |||
| -rw-r--r-- | src/lua_core.c | 2 |
5 files changed, 94 insertions, 4 deletions
diff --git a/examples/iqm_test/main.lua b/examples/iqm_test/main.lua new file mode 100644 index 0000000..2aa72bc --- /dev/null +++ b/examples/iqm_test/main.lua @@ -0,0 +1,90 @@ +-- Followed this tutorial. https://www.youtube.com/watch?v=_EurjoraotA + +local monitor = 0 +local camera = -1 +local texture = -1 +local material = -1 +local model = -1 +local animations = -1 +local animationCount = 0 +local frame = 0 +local curAnim = 0 +local frameCount = 0 +local animSpeed = 60 + +function init() + 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 } ) + camera = RL_CreateCamera3D() + RL_SetCamera3DPosition( camera, { 0, 2, 4 } ) + RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL_SetCamera3DUp( camera, { 0, 2, 0 } ) + RL_SetCamera3DMode( camera, CAMERA_FREE ) + + material = RL_CreateMaterial( { + maps = { + { + MATERIAL_MAP_ALBEDO, + { + texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/monkey_tex.png" ), + color = WHITE, + }, + }, + }, + } ) + + model = RL_LoadModel( RL_GetBasePath().."../resources/iqm/monkey.iqm" ) + RL_SetModelMaterial( model, 0, material ) + animations, animationCount = RL_LoadModelAnimations( RL_GetBasePath().."../resources/iqm/monkey.iqm" ) + + print( "animationCount", animationCount ) +end + +function process( delta ) + if RL_IsKeyPressed( KEY_ENTER ) then + curAnim = curAnim + 1 + + if animationCount <= curAnim then + curAnim = 0 + end + + frame = 0.0 + frameCount = RL_GetModelAnimationFrameCount( animations, curAnim ) + elseif RL_IsKeyPressed( KEY_UP ) then + animSpeed = animSpeed + 5 + elseif RL_IsKeyPressed( KEY_DOWN ) then + animSpeed = animSpeed - 5 + end + + if RL_IsKeyDown( KEY_SPACE ) then + RL_UpdateModelAnimation( model, animations, curAnim, math.floor( frame ) ) + frame = frame + animSpeed * delta + + if frameCount < frame then + frame = 0.0 + elseif frame < 0 then + frame = frameCount + end + end +end + +function draw() + RL_ClearBackground( { 100, 150, 100 } ) + RL_UpdateCamera3D( camera ) + + RL_BeginMode3D( camera ) + RL_DrawGrid( 8, 1 ) + RL_DrawModelEx( model, { 0, 0, 0 }, { 1.0, 0.0, 0.0 }, -90.0, { 1.0, 1.0, 1.0 }, WHITE ) + RL_EndMode3D() + + RL_DrawText( 0, +"Enter: Change animation\ +Space: Play animation\ +Up arrow: Inreace animation speed\ +Down arrow: Decreace animation speed", + { 10, 10 }, 30, 5, WHITE ) +end diff --git a/examples/platformer/main.lua b/examples/platformer/main.lua index bc0023a..41254b7 100644 --- a/examples/platformer/main.lua +++ b/examples/platformer/main.lua @@ -9,7 +9,7 @@ local PLAYER_ACCELL = 5 local PLAYER_DEACCELL = 5 local GRAVITY = 6 local JUMP_STR = 3 -local WALK_ANIM_SPEED = 8 +local WALK_ANIM_SPEED = 12 local tex = RL_LoadTexture( RL_GetBasePath().."../resources/images/arcade_platformerV2.png" ) local res = Vec2:new( 160, 144 ) @@ -37,7 +37,7 @@ local player = { onFloor = false, frames = { { 6, 14, 20, 18 }, - { 39, 14, 20, 18 }, + { 39, 13, 20, 19 }, { 70, 14, 20, 18 }, { 6, 45, 20, 18 }, { 38, 45, 20, 18 }, @@ -269,7 +269,7 @@ local function drawPlayer() if math.abs( player.vel.x ) < 0.1 then player.curFrame = 1 else - player.animPos = player.animPos + WALK_ANIM_SPEED * math.abs( player.vel.x ) * RL_GetFrameTime() + player.animPos = player.animPos + WALK_ANIM_SPEED * ( math.abs( player.vel.x ) / PLAYER_MAXSPEED ) * RL_GetFrameTime() local frame = math.ceil( player.animPos ) if #player.walkAnimFrames < frame then diff --git a/examples/resources/images/monkey_tex.png b/examples/resources/images/monkey_tex.png Binary files differnew file mode 100644 index 0000000..5ef9bd4 --- /dev/null +++ b/examples/resources/images/monkey_tex.png diff --git a/examples/resources/iqm/monkey.iqm b/examples/resources/iqm/monkey.iqm Binary files differnew file mode 100644 index 0000000..4c196a6 --- /dev/null +++ b/examples/resources/iqm/monkey.iqm diff --git a/src/lua_core.c b/src/lua_core.c index 65ed85b..2bf4195 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -558,7 +558,7 @@ void luaRegister() { lua_register( L, "RL_IsFileDropped", lcoreIsFileDropped ); lua_register( L, "RL_GetDroppedFiles", lcoreGetDroppedFiles ); lua_register( L, "RL_GetFileModTime", lcoreGetFileModTime ); - /* Camera3D. */ + /* Camera2D. */ lua_register( L, "RL_CreateCamera2D", lcoreCreateCamera2D ); lua_register( L, "RL_UnloadCamera2D", lcoreUnloadCamera2D ); lua_register( L, "RL_BeginMode2D", lcoreBeginMode2D ); |
