Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.
You now have everything to build a runner game like Chrome Dino: a character that runs (or stays in place), obstacles that scroll from the right, and a jump or dodge to avoid them.
Keep two variables: player_y or use player_rect.y, and a vertical speed (e.g. vy = 0). When the player presses jump, set vy = -15 (or another negative number). Each frame:
vy += 0.8 (or similar).player_rect.y += vy.player_rect.y = ground_y and vy = 0 so they can’t fall through or jump again mid-air if you only allow one jump at a time.Only allow jump when the player is on the ground (e.g. if player_rect.bottom >= ground_y and event.key == pygame.K_SPACE: vy = -15).
rect.right < 0), remove it and (optionally) add a new one on the right at a random or fixed position.if random.randint(0, 60) == 0: obstacles.append(pygame.Rect(600, ground_y - height, width, height)).When player_rect.colliderect(obstacle):
game_over = True.pygame.font or a big rect) and maybe “Press R to restart”.game_over = False, player back to start, clear obstacles, and continue the loop.pygame.mixer (beep on jump or game over).You’ve gone from no coding to a playable game — keep iterating and adding ideas.
Back to: Coding Club homepage