'F' → Fullscreen
Copy 1-07-move to 1-09-bounce and add the first decision:
local x = 100local y = 300local radius = 40local speedX = 200
function love.update(dt) x = x + speedX * dt
if x > 800 - radius then speedX = -speedX endend
function love.draw() love.graphics.circle("fill", x, y, radius)endRun it. The circle crosses, touches the right wall, comes back — and leaves through the left side, because nothing is watching that wall.
function love.update(dt) x = x + speedX * dt
if x > 800 - radius then speedX = -speedX end
if x < radius then speedX = -speedX endendNow it bounces forever. Leave it running while you write the next part — if it ever escapes or gets stuck, you want to see it happen.
x < radius and not x < 0? For the same reason the right wall is 800 - radius. The circle is drawn from its center, so its left edge is radius pixels earlier than its center.The bounce is hard to see at the moment it happens. Add an if / else in the drawing box:
function love.draw() if speedX > 0 then love.graphics.setColor(0.2, 0.8, 0.3) else love.graphics.setColor(0.9, 0.2, 0.2) end
love.graphics.circle("fill", x, y, radius)end

Green going right, red going left, and the swap happens exactly at the wall. You now have a decision in each box — one that changes the world, one that changes the picture.
Add speedY, move y the same way x moves, and give the top and bottom walls their own two decisions. The window is 600 tall.
Four walls, four if statements. Test it by starting the ball in a corner.
Change the right wall test to ask for an exact match:
if x == 800 - radius then speedX = -speedXendThe ball leaves and never comes back. No error, no crash, and the line looks perfectly reasonable. Explain on your sheet why the condition is never true, using what your readout showed you last session.
Then try to find a speedX that does make it work, and say why relying on that would be a bad idea.
Start the ball outside the window — change local x = 100 to local x = 900 and run it.
The ball never appears. Add print(x, speedX) to the update box and watch the terminal for a few seconds.
Write down what the two numbers do. This is a real bug that shows up in real games, and the fix is not another if — it is understanding why two decisions can undo each other.
The exam calls this selection, and it is one of the three things every program in the course is built from.
if score > 100 then print("Win")else print("Keep going")endIF(score > 100){ DISPLAY("Win")}ELSE{ DISPLAY("Keep going")}| Lua | Exam notation | |
|---|---|---|
| Start the condition | if x > 400 then | IF(x > 400) |
| Hold the block | then … end | { … } |
| The other branch | else | ELSE |
The exam wraps a block in { and }, each on its own line, and there is no space before the parenthesis in IF(condition). Both of those are worth copying exactly when you write notation by hand.
IF and IF / ELSE. There is no ELSE IF at all. Lua has one, and what the exam does instead is the next session.1-09-bounce bounces off all four walls and never escapes> or <, and accounts for the radius==Answer the following questions before submitting your work.
love.update and one in love.draw. Explain what each one decides and why it belongs in the box it is in.== let the ball escape, with no error. Explain why the condition is never true, and say what that tells you about testing a moving value for an exact match.800 - radius rather than 800. Describe what the program looks like with 800, and say what you would use for a rectangle instead of a circle.Submit the required files to the appropriate dropbox.