Add pagination to game launcher - 4 games per page
- GameLauncher now displays only 4 games per page to keep menu in bounds - Added page navigation with page indicator (Page X/Y) - KEY0 navigates between pages and within page - KEY1 selects the highlighted game - Touch selection works on current page only - Helper methods: get_total_pages(), get_page_start_index(), get_page_end_index() - Updated both lib/ and emulator/ versions for consistency
This commit is contained in:
49
emulator/games/lua_examples/counter.lua
Normal file
49
emulator/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