'F' → Fullscreen
Copy template-game to 1-14-hits. Start with the variables:
local ballX = 100local ballY = 150local radius = 25local speedX = 260local speedY = 180
local blockX = 480local blockY = 300local blockW = 120local blockH = 120local speed = 300
local hits = 0local touching = falseIn love.update, bounce the ball off all four walls — this is session 11's version, with the direction check:
ballX = ballX + speedX * dtballY = ballY + speedY * dt
if ballX > 800 - radius and speedX > 0 then speedX = -speedXend
if ballX < radius and speedX < 0 then speedX = -speedXend
if ballY > 600 - radius and speedY > 0 then speedY = -speedYend
if ballY < radius and speedY < 0 then speedY = -speedYendThen add the four arrow-key questions from last session so you can drive the block, and clamp it to the window. Draw both shapes and run it. Get this working before anything notices anything.
At the bottom of love.update:
local overlapping = ballX + radius > blockX and ballX - radius < blockX + blockW and ballY + radius > blockY and ballY - radius < blockY + blockHThen draw the ball red when overlapping is true and white when it is not. Drive the block into the ball and check that the color changes at exactly the right moment on all four sides.
ballX + radius is the ball's right edge, and blockX is the block's left edge. If the first is not past the second, they cannot be touching, whatever the other three say.Add a counter the obvious way:
if overlapping then hits = hits + 1endDraw "Hits: " .. hits in the corner and touch the ball once.

Write down the number you get from a single touch. Then touch it again, more briefly, and write down that number too. The two will not match, and neither of them is one.
Change three lines:
if overlapping and not touching then hits = hits + 1end
touching = overlappingNow draw the ball red when touching is true instead of overlapping:
function love.draw() love.graphics.setColor(0.3, 0.7, 1) love.graphics.rectangle("fill", blockX, blockY, blockW, blockH)
if touching then love.graphics.setColor(0.9, 0.2, 0.2) else love.graphics.setColor(1, 1, 1) end love.graphics.circle("fill", ballX, ballY, radius)
love.graphics.setColor(0.8, 0.8, 0.8) love.graphics.setFont(font) love.graphics.print("Hits: " .. hits, 40, 40)end
One touch, one hit. Hold the ball against the block by chasing it and confirm the number does not climb while they stay in contact.
touching = overlapping has to come after the if. Put it first and touching is already up to date when the if asks, so the count never moves at all.Four situations, and predict each before you try it:
| What you do | Hits should go up by |
|---|---|
| Touch once and move away | |
| Hold contact for five seconds | |
| Touch, move away, touch again | |
| Sit still while the ball passes through you twice |
Swap the last two lines so touching = overlapping runs before the if.
The counter never moves. No error, and the collision still works — the ball still turns red. Explain on your sheet what touching holds at the moment the if asks about it.
Make the hit do more than count. Pick one:
All three need the guarded version. With the counting bug, the ball would reach the speed of light in about a second.
1-14-hits has a bouncing ball and a block you can driveAnswer the following questions before submitting your work.
and. Describe a position where three of them are true, the fourth is false, and the shapes are clearly not touching.touching is never drawn and holds nothing a player could see. Explain what job it does, and describe one thing in a game you have played that must work the same way.Submit the required files to the appropriate dropbox.