Add Lua 5.4 scripting integration for dynamic game loading
- Integrated Lua 5.4 engine (32-bit mode for embedded ARM) - Created LuaGame wrapper class implementing Game interface - Added C++ bindings exposing renderer, game state, and input to Lua - Implemented SD card loader for automatic .lua game discovery - Updated GameLauncher to support std::function for lambda captures - Made Game class members public for Lua bindings access - Added example Lua games: counter, snake, bouncing ball - Included comprehensive API documentation Games can now be written as .lua text files on SD card and loaded without recompilation. Build size: 747KB UF2, Lua VM uses ~50-80KB RAM.
This commit is contained in:
49
games/lua_examples/counter.lua
Normal file
49
games/lua_examples/counter.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
-- NAME: Touch Counter
|
||||
-- DESC: Simple tap counter demo
|
||||
|
||||
-- Initialize game state
|
||||
function init()
|
||||
game.vars.count = 0
|
||||
game.vars.last_x = 0
|
||||
game.vars.last_y = 0
|
||||
print("Counter initialized")
|
||||
end
|
||||
|
||||
-- Update game logic based on input
|
||||
function update(event)
|
||||
-- Check if touch/button pressed
|
||||
if event.type == INPUT.TOUCH_DOWN or event.type == INPUT.BUTTON_0 or event.type == INPUT.BUTTON_1 then
|
||||
game.vars.count = game.vars.count + 1
|
||||
game.vars.last_x = event.x
|
||||
game.vars.last_y = event.y
|
||||
print("Count: " .. game.vars.count)
|
||||
return true -- Request redraw
|
||||
end
|
||||
|
||||
return false -- No redraw needed
|
||||
end
|
||||
|
||||
-- Draw the game
|
||||
function draw()
|
||||
-- Clear screen
|
||||
renderer.clear(true)
|
||||
|
||||
-- Draw title
|
||||
renderer.text(20, 20, "Touch Counter", true)
|
||||
|
||||
-- Draw count (centered)
|
||||
local count_text = "Count: " .. tostring(game.vars.count)
|
||||
renderer.text(game.width() / 2 - 40, game.height() / 2 - 10, count_text, true)
|
||||
|
||||
-- Draw last touch position
|
||||
if game.vars.count > 0 then
|
||||
local pos_text = "Last: (" .. tostring(game.vars.last_x) .. ", " .. tostring(game.vars.last_y) .. ")"
|
||||
renderer.text(20, game.height() - 30, pos_text, true)
|
||||
|
||||
-- Draw marker at last touch
|
||||
renderer.circle(game.vars.last_x, game.vars.last_y, 5, true, false)
|
||||
end
|
||||
|
||||
-- Draw instructions
|
||||
renderer.text(20, 50, "Tap screen to increment", true)
|
||||
end
|
||||
Reference in New Issue
Block a user