Skip to content

Add Tkinter Pac-Man–like game in Python#1

Open
vck77 wants to merge 3 commits intomainfrom
codex/create-pac-man-clone-in-python
Open

Add Tkinter Pac-Man–like game in Python#1
vck77 wants to merge 3 commits intomainfrom
codex/create-pac-man-clone-in-python

Conversation

@vck77
Copy link
Owner

@vck77 vck77 commented Mar 2, 2026

Motivation

  • Provide a compact, self-contained Pac-Man–inspired demo written in pure Python using tkinter for easy running and learning.

Description

  • Add pacman_game.py implementing the game loop, a fixed MAP_LAYOUT, an Entity dataclass, player input handling, pellet and power-pellet scoring, ghost AI that chases or flees, collision handling, lives, win/lose states, and restart support.
  • Add README.md with quick-start instructions and controls showing how to run the game with python3 pacman_game.py.
  • Render the map with a configurable CELL_SIZE on a tk.Canvas and expose a tick_rate_ms for game pacing.

Testing

  • Ran python3 -m py_compile pacman_game.py which succeeded.
  • Attempted python3 -m py_compile pacman_game.py README.md which failed because README.md is not a Python file, as expected.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a622c7ed2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

pacman_game.py Outdated
def on_key(self, event: tk.Event):
if self.game_over:
if event.keysym.lower() == "r":
self.__init__(self.root)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cancel existing tick timer before restarting game

Pressing R in the game-over state calls __init__ on the same instance, but the previous after chain created in loop() is never canceled and loop() always re-schedules itself even when game_over is true. After each restart, another timer chain keeps running, so updates execute multiple times per tick and the game speed/collision behavior becomes increasingly incorrect.

Useful? React with 👍 / 👎.

self.player.direction = (0, 0)
self.pending_direction = (0, 0)

self.canvas = tk.Canvas(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Destroy or reuse the canvas when handling restart

Because restart re-enters __init__ on the existing window, this line creates a fresh Canvas each time and pack() adds it to the UI without removing the previous one. Repeating win/loss + restart cycles will stack canvases and grow resource usage/window layout unexpectedly instead of resetting the same board.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant