🚀Refactor game with settings module + add AI mode, pause feature, and improved collision handling - #107
Open
siddhi123890 wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧩 Overview
This PR improves the Pong game by enhancing code structure, gameplay features, and maintainability.
Key improvements:
Centralized configuration using a new settings.py
Added AI (single-player) mode
Added pause/resume functionality
Improved collision detection logic
General code cleanup and refactoring
✨ Features Added
🤖 Single Player Mode (AI Paddle)
Added optional AI-controlled left paddle
Paddle automatically follows the ball
Can be toggled in settings.py:
SINGLE_PLAYER = True
⏸️ Pause / Resume Feature
Press Spacebar to pause/resume the game
Stops ball movement and screen updates during pause
⚙️ Settings Module
Introduced settings.py to store all configurable values:
Screen size and appearance
Paddle movement and boundaries
Ball speed and behavior
Collision thresholds
Game rules (win score, AI toggle)
🎯 Game Over System
Game ends when a player reaches the defined score limit
Displays winner message on screen
🛠️ Improvements
✅ Fixed Collision Logic
Corrected paddle collision condition to avoid logical errors due to operator precedence
🧹 Code Refactoring
Renamed variables for consistency:
X_move → x_move
Y_move → y_move
Removed unused objects
Improved function naming (go_up, go_down)
Replaced hardcoded values with configurable settings
📁 Files Modified / Added
➕ Added
settings.py (central configuration file)
🔄 Updated
main.py (game loop, AI, pause feature, settings integration)
ball.py (movement logic using settings)
paddle.py (movement boundaries from settings)
scoreboard.py (game over support)
🧪 How to Test
Run the game:
python main.py
Controls:
W / S → Left paddle
↑ / ↓ → Right paddle
Space → Pause / Resume
Optional:
Enable/disable AI in settings.py
Modify speed and difficulty via settings