PyLua 2D Game Engine (LEngine)
PyLua integrates a native, hardware-accelerated 2D game framework directly into the language runtime. It bundles OpenGL graphics, 2D rigid-body physics, low-latency audio via miniaudio, immediate-mode UI, and multithreaded worker threads.
1. The Unity-Inspired Game Loop (`engine.run`)
The engine coordinates GLFW events, updates physics simulations, executes script entity updates, and swaps frame buffers in a single unified game loop:
import engine
-- 1. Create a 1280x720 window:
win = engine.Window.create("PyLua 2D Action", 1280, 720)
-- 2. Create physics world with gravity:
world = engine.Physics.createWorld(0, 9.8)
-- 3. Run the engine loop:
engine.run({
window = win,
physicsWorld = world,
init = function() {
print("Game Initialized!")
playerX = 100
playerY = 100
},
update = function(dt) {
-- Smooth movement scaled by delta time:
if (engine.Input.isKeyDown(262)) { playerX = playerX + 200 * dt } -- Right Arrow
if (engine.Input.isKeyDown(263)) { playerX = playerX - 200 * dt } -- Left Arrow
},
draw = function() {
-- Clear screen to dark slate:
engine.Graphics.clear(0.1, 0.12, 0.18, 1.0)
-- Render player character:
engine.Graphics.drawRect(playerX, playerY, 48, 48, 0.2, 0.6, 1.0, 1.0)
}
})
2. Engine Subsystems Overview
Window & Displays
GLFW windowing, monitor resolution queries, VSync, and fullscreen desktop modes.
SubsystemGraphics & Rendering
OpenGL 2D immediate-mode rendering for rectangles, circles, lines, textures, and fonts.
Subsystem2D Rigid-Body Physics
Gravity, velocity integration, box colliders, circle colliders, and collision resolution.
SubsystemAudio & Spatial Sound
Miniaudio backend with 3D spatial listener positioning, volume controls, and sound pooling.
SubsystemInput Handling
Real-time keyboard polling, mouse coordinates, button clicks, and scroll offsets.
SubsystemIn-Game Immediate UI
Immediate-mode UI controls: buttons, text labels, sliders, and health bar overlays.
SubsystemSprite Sheet Animation
Multi-sequence keyframe interpolation, panim file loading, and built-in editor mode.
SubsystemEntity-Script Model
Attach modular script components to game entities with automatic lifecycle dispatch.
SubsystemMultithreaded Workers
Spawn parallel background OS threads with isolated Lua state for procedural generation.