Frogger
Note
Requires: session 5 (Breakout) finished.
A frog wants to reach the other side. For that he has to cross a busy road and a dangerous river. Cars drive in three lanes, logs float on the water. One wrong step and it’s over.
Getting started
Download the starter code and unpack the ZIP. Open main.py in Thonny and click Run. You see the playing field, but the frog doesn’t move yet. You fill in the functions.
How does it work?
The screen is split into horizontal lanes of 40 pixels:
- Top: 5 ponds where the frog has to arrive safely
- River (3 lanes): logs float past. On a log you’re safe, in the water you drown.
- Grass verge: safe resting spot in the middle
- Road (3 lanes): cars drive back and forth. Getting hit = dead.
- Bottom: starting position of the frog
TEGEL = 40
KOLOMMEN, RIJEN = 13, 14
# Lanes: (row, direction, speed)
AUTO_BANEN = [
(6, 1, 2), # right, slow
(7, -1, 4), # left, fast
(8, 1, 3), # right, medium
]Cars and logs are pygame.Rect objects in a list. Every frame you shift them all and remove the ones that fall off the screen.
The frog moves in fixed steps of TEGEL pixels. Press an arrow key and the frog jumps one tile in that direction.
You check collisions with rect.colliderect(andere_rect).
✅ Basic
- Move the frog: catch the arrow keys in
KEYDOWNand adjustkikker.xandkikker.ybyTEGEL. - Spawn cars: fill in
spawn_auto(). Pick a random lane, make aRectjust outside the screen, add it toauto_lijst. - Move cars: in
update(): shift every car withrect.x += richting * snelheid. Remove cars outside the screen. Keep at least 6 cars. - Spawn logs: fill in
spawn_hout(). The same principle, but withHOUT_BANENand a bigger width. - Move logs: in
update(): shift and remove like with the cars. Keep at least 4 logs. - Car collision: if
kikker.colliderect(auto): callsterf(). - Drowning: if the frog is in the river (row 2, 3 or 4) and not on a log:
sterf(). - Pond check: if the frog is close to an empty pond: set
huizen_gevuld[i] = True,score += 10, reset the frog. 5 ponds full = won.
Done? You have a working Frogger!
⭐ Stretch
- Lives counter: the
levenssystem is already there. Make sure the game stops whenlevens <= 0and show “GAME OVER”. - Timer: add a timer. Start with 30 seconds per level. When the timer runs out you lose a life. Show the timer in the HUD. Every pond you fill gives you 5 extra seconds.
- Difficulty: raise the speed of the cars and logs as the score goes up (
snelheid = basis + score // 50).
🔥 Expert
- Bonus fly: a green insect appears at a random spot on the map and moves around. Catch it for 20 bonus points. Let it disappear after 5 seconds.
- High score: store the highest score in a variable
high_score. Show it next to the current score. Update it when the player sets a new record. - Different vehicles: add trucks (2 tiles wide, slower) and motorbikes (1 tile, faster). Use a separate list or a
typefield. - Animation: let the frog blink briefly when he dies (
dood_timeris already there). Draw a small splash when the frog drowns.
Downloads
- Starter code:
main.pywith the playing field, the frog and all the drawing code ready; you fill in the logic.
Inspired by the classic Frogger (1981, Konami). Drawings with pygame.draw.