Finding Pi - the Py Game That Teaches You the Digits of Pi and How to Make Make Pie by Playing Py Game Made Using Pygame and Py(thon) on (rasberry) Pi
by jetcrafts in Craft > Digital Graphics
61 Views, 2 Favorites, 0 Comments
Finding Pi - the Py Game That Teaches You the Digits of Pi and How to Make Make Pie by Playing Py Game Made Using Pygame and Py(thon) on (rasberry) Pi

this is a game i made at my grandparents place for pi day , I really hope u enjoy.
you play as pi running from approximation, which will kill you ,
u run around trying to pick back up all you're digits while getting chased
after picking up 6, an oven and then ingredients start to spawn
u use these to craft pies for power ups
to craft them you go to the pie in the middle
it gives you recipes for the fillings and crusts
use these to bake pies which give u power ups
apple pie gives you 5 more lives
lemon meringue pie gives u double speed
and raspberry pie gives u the ability to pin the approximation symbol down for 5 seconds
to win u must bake all the pie,s and collect the first 30 digits of pi
Supplies
- a python ide
- install pygame library
How to Run

https://github.com/jectrafts/finding-pi
this is the github with all the codes and sprites ( pls follow me)( I didn't upload code here cause its 600 lines and there are like 7 sprite images )
go to you're ide,s terminal and install pygame:
one way is using pip install:
all u hv to do is download it as a zip file and unzip and run main.py
Gameplay
you use WASD or arrow keys to move
once you collect the first 6 numbers
a oven will spawn, pick it up
head to the pie in the middle which pauses the game and gives you recipes to make pies, to leave the pie click space
learn the recipes and collect ingredients around you to bake pies by going into the pie in the middle
you first have to make pie crust and then the fillings
you hv to bake apple pie first which gives you 5 more lives
then lemon pie which gives u 2x speed
and then rasberry pie which lets u pause time for 5 seconds
to win u must bake all pie,s and collect all 30 digits of pi
How Does This Game Even Work
Imports and Initialization
Imports:
- pygame: Core library for game development.
- random: For spawning objects randomly.
- math: For distance calculations (e.g., hypot).
- time: For delays (e.g., countdown on replay).
Initialization:
- Initializes Pygame.
- Creates a 1200x700 pixel window.
- Sets the window title to "Square Pacman - Numbers & Chaser".
- Stores screen dimensions in WIDTH and HEIGHT.
Colors
setting the color
Image Loading
Player and Chaser: Loads player.png and chaser.png, scales them to 30x30 pixels, and uses alpha transparency.
Pie: Loads pie.png (50x50), centers it on-screen. If it fails, draws a blue circle with a white π symbol as a fallback.
Oven: Loads oven.png (40x40) if supported, otherwise draws a brown rectangle with a gray center.
Backgrounds:
- background.png for gameplay, scaled to 1200x700, with a black fallback.
- start_background.png for the start screen, scaled similarly, with a black fallback.
Music: Loads background_music.mp3 for playback during gameplay.
Token Images
Loads images for each token type (e.g., flour.png), scales them to 20x20. If missing, uses a white circle as a fallback. Stored in a dictionary token_images.
Fonts and Clock
Defines various font sizes for different UI elements (e.g., font for general text, xlarge_font for "Next" digit).
clock controls the frame rate (later set to 60 FPS).
Game Data
Pi Digits: pi_sequence is a string of π digits; pi_digits filters out non-digits. current_digit_index tracks progress.
Difficulty: easy_digit_size (32) and normal_digit_size (24) adjust digit font size per level.
Game State: Tracks last collected point, oven status, and message timing.
Tokens: token_types defines max quantities and colors for each token.
Recipes: Defines ingredients for intermediate items (pie_crust, fillings) and final pies (apple_pie, etc.).
Inventory: collected_tokens tracks gathered tokens; crafted_items tracks crafted items; tokens_on_map lists active tokens.
Functions
- Spawning Functions:
- spawn_point_with_specific_digit(digit, existing_points): Spawns a digit at a random position, avoiding player, last point, pie, and other points.
- spawn_oven(): Spawns the oven away from the player and pie.
- spawn_token(existing_tokens): Spawns a token if under its max limit, avoiding collisions.
- Movement Functions:
- teleport_chaser_away(): Moves chaser far from player.
- move_player_away_from_point(point, distance=5): Nudges player away from a collected point.
- teleport_player_from_pie(): Moves player away from the center pie when hit.
- Crafting Functions:
- can_craft(item): Checks if an item can be crafted based on available tokens or components, with pie prerequisites (e.g., apple pie before lemon).
- craft_item(item): Deducts required resources and increments crafted count, applying effects (e.g., +5 lives for apple pie).
- Reset Game:
- reset_game(): Resets all game variables to initial states, spawns 5 initial digits.
- Text Wrapping:
- wrap_text(text, font, max_width): Splits text into lines that fit within max_width, used for "How to Play" and win messages.
Initial Game State
Initializes game state variables, starting in the menu with music off.
Main Game Loop
- Runs until running = False. current_time tracks milliseconds for timers.
Event Handling
- Quit: Closes game on window close or ESC, stopping music.
- Space: Toggles pause, teleports player from pie if hit.
- P Key: Pauses chaser for 5 seconds if raspberry pie is crafted.
- Mouse Clicks:
- Start menu: Selects levels (1-3, setting speed/font), "How to Play", or "Leave" (stops music).
- How to Play: "Back" to menu.
- Death confirmation: "Yes" (to menu, stops music) or "No" (resumes).
- Paused: Crafts items if oven acquired.
- Win screen: "Replay" (countdown, resets) or "Main Menu" (stops music).
Rendering and Logic
- Start Menu:
- Displays start_background_img.
- Shows title, level buttons, and controls text.
- How to Play:
- Black background.
- Wrapped instructions text and "Back" button.
- Gameplay (not game_over and not game_won):
- Active State:
- Displays background_img.
- Handles player movement (WASD/arrows), collision with pie (pauses), chaser movement (reverses if hits pie), digit collection (score up or death if wrong), token collection, oven spawning/acquisition, and pie crafting effects.
- Updates UI (score, lives, next digit, collected digits).
- Death Confirmation: Black background, asks to die or continue.
- Paused: Shows background_img, game state frozen, displays recipes and crafting options.
- Win Screen:
- Black background.
- Shows "You Won!", wrapped win message, π digits, and replay/menu buttons.
Display and Frame Rate
Updates the screen and limits to 60 FPS. Quits Pygame on exit.
Hope U Enjoy
i hope u try this out and enjoy this
a little birdy told me the win screen has something cool