Skip to content

🚀Refactor game with settings module + add AI mode, pause feature, and improved collision handling - #107

Open
siddhi123890 wants to merge 5 commits into
qxresearch:masterfrom
siddhi123890:feature/settings-ai-pause-refactor
Open

🚀Refactor game with settings module + add AI mode, pause feature, and improved collision handling#107
siddhi123890 wants to merge 5 commits into
qxresearch:masterfrom
siddhi123890:feature/settings-ai-pause-refactor

Conversation

@siddhi123890

Copy link
Copy Markdown

🧩 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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants