-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
103 lines (80 loc) · 2.42 KB
/
config.py
File metadata and controls
103 lines (80 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
Game configuration module for Pong.
This module centralizes all game constants and configuration settings,
making it easier to modify game behavior and maintain consistency.
"""
from typing import Tuple
from enum import Enum
# Type aliases for better code clarity
Color = Tuple[int, int, int]
Position = Tuple[int, int]
class GameConfig:
"""Central configuration class for Pong game settings."""
# Display settings
WIDTH: int = 800
HEIGHT: int = 700
FPS: int = 60
WINDOW_TITLE: str = "PONG - Python Edition"
# Colors
WHITE: Color = (255, 255, 255)
BLACK: Color = (0, 0, 0)
GREEN: Color = (19, 58, 38)
DARK_GREEN: Color = (10, 30, 20)
# Ball settings
BALL_RADIUS: int = 7
BALL_MAX_VEL: int = 5
BALL_COLOR: Color = WHITE
# Paddle settings
PADDLE_WIDTH: int = 20
PADDLE_HEIGHT: int = 100
PADDLE_VEL: int = 4
PADDLE_COLOR: Color = WHITE
# Game rules
WINNING_SCORE: int = 5
# UI settings
SCORE_FONT_NAME: str = "comicsans"
SCORE_FONT_SIZE: int = 50
MENU_FONT_SIZE: int = 60
# Divider line settings
DIVIDER_WIDTH: int = 10
DIVIDER_SEGMENT_HEIGHT: int = HEIGHT // 20
@classmethod
def get_paddle_start_pos(cls, is_left: bool) -> Position:
"""
Calculate starting position for a paddle.
Args:
is_left: True for left paddle, False for right paddle
Returns:
Tuple of (x, y) coordinates for paddle starting position
"""
if is_left:
x = 10
else:
x = cls.WIDTH - 10 - cls.PADDLE_WIDTH
y = cls.HEIGHT // 2 - cls.PADDLE_HEIGHT // 2
return (x, y)
@classmethod
def get_ball_start_pos(cls) -> Position:
"""
Get the starting position for the ball (center of screen).
Returns:
Tuple of (x, y) coordinates for ball starting position
"""
return (cls.WIDTH // 2, cls.HEIGHT // 2)
class GameState(Enum):
"""Enumeration of possible game states."""
MENU = "menu"
PLAYING = "playing"
PAUSED = "paused"
GAME_OVER = "game_over"
class Controls:
"""Keyboard controls configuration."""
# Player 1 (Left) controls
P1_UP = "w"
P1_DOWN = "s"
# Player 2 (Right) controls
P2_UP = "up"
P2_DOWN = "down"
# General controls
PAUSE = "escape"
QUIT = "q"