47 lines
902 B
Text
47 lines
902 B
Text
-- Lesson 2: Numbers That Change
|
|
|
|
CELL_WIDTH = overlayGetFontWidth()
|
|
CELL_HEIGHT = overlayGetFontHeight()
|
|
TOP_ROW = 2
|
|
|
|
word = "Hello!"
|
|
wordX = 0
|
|
wordY = TOP_ROW
|
|
speedX = 0.25
|
|
speedY = 0.125
|
|
frames = 0
|
|
|
|
lastColumn = overlayGetWidth() // CELL_WIDTH - string.len(word)
|
|
lastRow = overlayGetHeight() // CELL_HEIGHT - 1
|
|
|
|
|
|
function onOverlayUpdate()
|
|
frames = frames + 1
|
|
wordX = wordX + speedX
|
|
wordY = wordY + speedY
|
|
|
|
if wordX < 0 then
|
|
wordX = 0
|
|
speedX = -speedX
|
|
end
|
|
|
|
if wordX > lastColumn then
|
|
wordX = lastColumn
|
|
speedX = -speedX
|
|
end
|
|
|
|
if wordY < TOP_ROW then
|
|
wordY = TOP_ROW
|
|
speedY = -speedY
|
|
end
|
|
|
|
if wordY > lastRow then
|
|
wordY = lastRow
|
|
speedY = -speedY
|
|
end
|
|
|
|
overlayClear()
|
|
overlayPrint(0, 0, "frame " .. frames)
|
|
overlayPrint(wordX, wordY, word)
|
|
return OVERLAY_UPDATED
|
|
end
|