Updated games: - pong.lua: All text now uses text_scaled with scale=2 - air_hockey.lua: All text now uses text_scaled with scale=2 - asteroids.lua: All text now uses text_scaled with scale=2 - ball.lua: All text now uses text_scaled with scale=2 - breakout.lua: All text now uses text_scaled with scale=2 - counter.lua: All text now uses text_scaled with scale=2 - flappy_bird.lua: All text now uses text_scaled with scale=2 - lunar_lander.lua: All text now uses text_scaled with scale=2 - snake.lua: All text now uses text_scaled with scale=2 - tetris.lua: All text now uses text_scaled with scale=2 All 14 games now have consistent 2x text scaling for better readability.
50 lines
1.5 KiB
Lua
50 lines
1.5 KiB
Lua
-- 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_scaled(20, 20, "Touch Counter", true, 2)
|
|
|
|
-- Draw count (centered)
|
|
local count_text = "Count: " .. tostring(game.vars.count)
|
|
renderer.text_scaled(game.width(, 2) / 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_scaled(20, game.height(, 2) - 30, pos_text, true)
|
|
|
|
-- Draw marker at last touch (convert to integers)
|
|
renderer.circle(math.floor(game.vars.last_x + 0.5), math.floor(game.vars.last_y + 0.5), 5, true, false)
|
|
end
|
|
|
|
-- Draw instructions
|
|
renderer.text_scaled(20, 50, "Tap screen to increment", true, 2)
|
|
end
|