console-pong 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CheezeDeveloper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: console-pong
3
+ Version: 1.0.0
4
+ Summary: A fully featured Pong game right in your terminal
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/CheezeDeveloper/console-pong
7
+ Keywords: pong,game,terminal,console,cli
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: End Users/Desktop
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Games/Entertainment :: Arcade
15
+ Requires-Python: >=3.7
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ Hi! This is CheezeDev.
21
+
22
+ This is a very cool, playable Ping Pong game, which has trail effects, CPUs, etc!
23
+
24
+ No need for dependencies.
25
+
26
+ To insall, you can use pip install console-pong.
@@ -0,0 +1,7 @@
1
+ Hi! This is CheezeDev.
2
+
3
+ This is a very cool, playable Ping Pong game, which has trail effects, CPUs, etc!
4
+
5
+ No need for dependencies.
6
+
7
+ To insall, you can use pip install console-pong.
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "console-pong"
7
+ version = "1.0.0"
8
+ description = "A fully featured Pong game right in your terminal"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.7"
12
+ keywords = ["pong", "game", "terminal", "console", "cli"]
13
+ classifiers = [
14
+ "Development Status :: 5 - Production/Stable",
15
+ "Environment :: Console",
16
+ "Intended Audience :: End Users/Desktop",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: Games/Entertainment :: Arcade",
21
+ ]
22
+
23
+ [project.scripts]
24
+ pong = "console_pong:main"
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/CheezeDeveloper/console-pong"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ from .game import PongGame
2
+
3
+
4
+ def main():
5
+ game = PongGame()
6
+ game.run()
@@ -0,0 +1,3 @@
1
+ from console_pong import main
2
+
3
+ main()
@@ -0,0 +1,855 @@
1
+ import sys
2
+ import os
3
+ import time
4
+ import random
5
+ import math
6
+
7
+ WINDOWS = os.name == 'nt'
8
+
9
+ if WINDOWS:
10
+ import msvcrt
11
+ else:
12
+ import tty
13
+ import termios
14
+ import select
15
+
16
+
17
+ class PongGame:
18
+ def __init__(self):
19
+ self.width = 60
20
+ self.height = 22
21
+
22
+ # Paddles
23
+ self.paddle_h = 5
24
+ self.paddle_h_p2 = 5
25
+ self.p1_y = 0.0
26
+ self.p2_y = 0.0
27
+
28
+ # Ball
29
+ self.ball_x = 0.0
30
+ self.ball_y = 0.0
31
+ self.ball_dx = 0.0
32
+ self.ball_dy = 0.0
33
+ self.ball_speed = 1.0
34
+ self.max_speed = 2.5
35
+
36
+ # Trail effect
37
+ self.ball_trail = []
38
+ self.max_trail = 4
39
+
40
+ # Particles
41
+ self.particles = []
42
+
43
+ # Scores
44
+ self.p1_score = 0
45
+ self.p2_score = 0
46
+ self.win_score = 7
47
+
48
+ # State
49
+ self.running = True
50
+ self.paused = False
51
+ self.game_over = False
52
+ self.winner = ""
53
+ self.state = "MENU"
54
+
55
+ # Game mode
56
+ self.mode = "PVP"
57
+ self.cpu_difficulty = 2
58
+ self.cpu_reaction_timer = 0
59
+
60
+ # Powerups
61
+ self.powerup_x = -1
62
+ self.powerup_y = -1
63
+ self.powerup_type = ""
64
+ self.powerup_timer = 0
65
+ self.powerup_active = ""
66
+ self.powerup_active_timer = 0
67
+ self.powerup_active_owner = 0
68
+
69
+ # Stats
70
+ self.rallies = 0
71
+ self.longest_rally = 0
72
+ self.current_rally = 0
73
+ self.total_time = 0
74
+ self.start_time = 0
75
+
76
+ # Timing
77
+ self.tick_rate = 0.045
78
+ self.ball_move_accum = 0.0
79
+
80
+ # Countdown
81
+ self.countdown = 0
82
+ self.countdown_timer = 0.0
83
+
84
+ # Screen shake
85
+ self.shake_frames = 0
86
+ self.shake_offset_x = 0
87
+ self.shake_offset_y = 0
88
+
89
+ # Combo
90
+ self.p1_combo = 0
91
+ self.p2_combo = 0
92
+
93
+ # Flash
94
+ self.flash_frames = 0
95
+ self.flash_char = ""
96
+
97
+ # Menu
98
+ self.menu_selection = 0
99
+ self.mode_selection = 0
100
+ self.difficulty_selection = 1
101
+
102
+ # Terminal
103
+ if not WINDOWS:
104
+ self.old_settings = termios.tcgetattr(sys.stdin)
105
+ tty.setcbreak(sys.stdin.fileno())
106
+
107
+ def cleanup(self):
108
+ if not WINDOWS:
109
+ termios.tcsetattr(sys.stdin, termios.TCSADRAIN, self.old_settings)
110
+ sys.stdout.write('\033[?25h')
111
+ sys.stdout.flush()
112
+
113
+ def get_key(self):
114
+ if WINDOWS:
115
+ if msvcrt.kbhit():
116
+ ch = msvcrt.getch()
117
+ if ch in (b'\x00', b'\xe0'):
118
+ msvcrt.getch()
119
+ return None
120
+ try:
121
+ return ch.decode('utf-8').lower()
122
+ except:
123
+ return None
124
+ return None
125
+ else:
126
+ if select.select([sys.stdin], [], [], 0)[0]:
127
+ ch = sys.stdin.read(1)
128
+ return ch.lower()
129
+ return None
130
+
131
+ def read_keys(self):
132
+ keys = []
133
+ for _ in range(15):
134
+ key = self.get_key()
135
+ if key is None:
136
+ break
137
+ keys.append(key)
138
+ return keys
139
+
140
+ def hide_cursor(self):
141
+ sys.stdout.write('\033[?25l')
142
+ sys.stdout.flush()
143
+
144
+ def move_home(self):
145
+ sys.stdout.write('\033[H')
146
+
147
+ def clear(self):
148
+ os.system('cls' if WINDOWS else 'clear')
149
+
150
+ # ── Particle System ──────────────────────────────────────
151
+
152
+ def spawn_particles(self, x, y, count=6, chars=None):
153
+ if chars is None:
154
+ chars = ['*', '+', '.', '·', ':', '~']
155
+ for _ in range(count):
156
+ self.particles.append({
157
+ 'x': float(x),
158
+ 'y': float(y),
159
+ 'dx': random.uniform(-2, 2),
160
+ 'dy': random.uniform(-1.5, 1.5),
161
+ 'life': random.randint(3, 8),
162
+ 'char': random.choice(chars)
163
+ })
164
+
165
+ def spawn_score_particles(self, x, y):
166
+ chars = ['★', '!', '*', '●', '◆', '+']
167
+ for _ in range(12):
168
+ self.particles.append({
169
+ 'x': float(x),
170
+ 'y': float(y),
171
+ 'dx': random.uniform(-3, 3),
172
+ 'dy': random.uniform(-2, 2),
173
+ 'life': random.randint(4, 12),
174
+ 'char': random.choice(chars)
175
+ })
176
+
177
+ def update_particles(self):
178
+ alive = []
179
+ for p in self.particles:
180
+ p['x'] += p['dx']
181
+ p['y'] += p['dy']
182
+ p['life'] -= 1
183
+ p['dy'] += 0.1
184
+ if p['life'] > 0:
185
+ alive.append(p)
186
+ self.particles = alive
187
+
188
+ # ── Power-up System ──────────────────────────────────────
189
+
190
+ def spawn_powerup(self):
191
+ self.powerup_x = random.randint(self.width // 4, 3 * self.width // 4)
192
+ self.powerup_y = random.randint(2, self.height - 3)
193
+ self.powerup_type = random.choice(["BIG", "FAST", "SLOW", "TINY"])
194
+ self.powerup_timer = 200
195
+
196
+ def collect_powerup(self, player):
197
+ self.powerup_active = self.powerup_type
198
+ self.powerup_active_timer = 150
199
+ self.powerup_active_owner = player
200
+
201
+ if self.powerup_type == "BIG":
202
+ if player == 1:
203
+ self.paddle_h = 7
204
+ else:
205
+ self.paddle_h_p2 = 7
206
+ elif self.powerup_type == "TINY":
207
+ if player == 1:
208
+ self.paddle_h_p2 = 3
209
+ else:
210
+ self.paddle_h = 3
211
+ elif self.powerup_type == "FAST":
212
+ self.ball_speed = min(self.ball_speed * 1.5, self.max_speed)
213
+ elif self.powerup_type == "SLOW":
214
+ self.ball_speed = max(self.ball_speed * 0.6, 0.5)
215
+
216
+ self.spawn_particles(self.powerup_x, self.powerup_y, 10, ['★', '✦', '◆', '●'])
217
+ self.powerup_x = -1
218
+ self.powerup_y = -1
219
+ self.powerup_type = ""
220
+
221
+ def clear_powerup_effect(self):
222
+ self.powerup_active = ""
223
+ self.powerup_active_owner = 0
224
+ self.paddle_h = 5
225
+ self.paddle_h_p2 = 5
226
+ self.ball_speed = max(0.8, min(self.ball_speed, 1.5))
227
+
228
+ # ── CPU AI ───────────────────────────────────────────────
229
+
230
+ def update_cpu(self):
231
+ if self.mode != "CPU":
232
+ return
233
+
234
+ self.cpu_reaction_timer += 1
235
+
236
+ react_every = {1: 6, 2: 3, 3: 1}[self.cpu_difficulty]
237
+ if self.cpu_reaction_timer % react_every != 0:
238
+ return
239
+
240
+ target_y = self.ball_y
241
+ ph = self.paddle_h_p2
242
+ paddle_center = self.p2_y + ph / 2.0
243
+
244
+ if self.cpu_difficulty == 1:
245
+ target_y += random.uniform(-4, 4)
246
+ elif self.cpu_difficulty == 2:
247
+ target_y += random.uniform(-1.5, 1.5)
248
+
249
+ if self.ball_dx > 0 or self.cpu_difficulty == 3:
250
+ diff = target_y - paddle_center
251
+ move_speed = {1: 1, 2: 2, 3: 2}[self.cpu_difficulty]
252
+ if abs(diff) > 1:
253
+ if diff > 0:
254
+ self.p2_y = min(self.height - ph, self.p2_y + move_speed)
255
+ else:
256
+ self.p2_y = max(0, self.p2_y - move_speed)
257
+
258
+ # ── Game Logic ───────────────────────────────────────────
259
+
260
+ def init_game(self):
261
+ self.paddle_h = 5
262
+ self.paddle_h_p2 = 5
263
+ self.p1_y = float(self.height // 2 - self.paddle_h // 2)
264
+ self.p2_y = float(self.height // 2 - self.paddle_h // 2)
265
+ self.p1_score = 0
266
+ self.p2_score = 0
267
+ self.game_over = False
268
+ self.winner = ""
269
+ self.paused = False
270
+ self.rallies = 0
271
+ self.longest_rally = 0
272
+ self.current_rally = 0
273
+ self.particles = []
274
+ self.ball_trail = []
275
+ self.p1_combo = 0
276
+ self.p2_combo = 0
277
+ self.powerup_x = -1
278
+ self.powerup_active = ""
279
+ self.powerup_active_timer = 0
280
+ self.start_time = time.time()
281
+ self.reset_ball()
282
+
283
+ def reset_ball(self, direction=None):
284
+ self.ball_x = float(self.width // 2)
285
+ self.ball_y = float(self.height // 2)
286
+ self.ball_speed = 1.0
287
+ if direction is None:
288
+ direction = random.choice([-1, 1])
289
+ angle = random.uniform(-0.5, 0.5)
290
+ self.ball_dx = float(direction)
291
+ self.ball_dy = angle
292
+ self.ball_trail = []
293
+ self.countdown = 3
294
+ self.countdown_timer = time.time()
295
+ self.current_rally = 0
296
+ self.ball_move_accum = 0.0
297
+
298
+ def update_ball(self):
299
+ if self.paused or self.game_over or self.countdown > 0:
300
+ return
301
+
302
+ self.ball_move_accum += self.ball_speed
303
+ while self.ball_move_accum >= 1.0:
304
+ self.ball_move_accum -= 1.0
305
+ self._step_ball()
306
+
307
+ def _step_ball(self):
308
+ # Trail
309
+ self.ball_trail.append((self.ball_x, self.ball_y))
310
+ if len(self.ball_trail) > self.max_trail:
311
+ self.ball_trail.pop(0)
312
+
313
+ new_x = self.ball_x + self.ball_dx
314
+ new_y = self.ball_y + self.ball_dy
315
+
316
+ # ── WALL BOUNCE ──────────────────────────────────
317
+ # The playable vertical range is 1.0 to height-2.0
318
+ # We never allow the ball to sit on row 0 or row height-1
319
+ top_limit = 1.0
320
+ bottom_limit = float(self.height - 2)
321
+
322
+ bounce_count = 0
323
+ while (new_y < top_limit or new_y > bottom_limit) and bounce_count < 10:
324
+ bounce_count += 1
325
+ if new_y < top_limit:
326
+ new_y = 2 * top_limit - new_y # reflect off top
327
+ self.ball_dy = abs(self.ball_dy)
328
+ if abs(self.ball_dy) < 0.3:
329
+ self.ball_dy = 0.3
330
+ self.spawn_particles(new_x, 0, 3, ['─', '~', '.'])
331
+ if new_y > bottom_limit:
332
+ new_y = 2 * bottom_limit - new_y # reflect off bottom
333
+ self.ball_dy = -abs(self.ball_dy)
334
+ if abs(self.ball_dy) < 0.3:
335
+ self.ball_dy = -0.3
336
+ self.spawn_particles(new_x, self.height - 1, 3, ['─', '~', '.'])
337
+
338
+ # Hard clamp as absolute last resort — force away from edges
339
+ if new_y <= top_limit:
340
+ new_y = top_limit + 0.5
341
+ self.ball_dy = abs(self.ball_dy)
342
+ if abs(self.ball_dy) < 0.3:
343
+ self.ball_dy = 0.3
344
+ if new_y >= bottom_limit:
345
+ new_y = bottom_limit - 0.5
346
+ self.ball_dy = -abs(self.ball_dy)
347
+ if abs(self.ball_dy) < 0.3:
348
+ self.ball_dy = -0.3
349
+
350
+ by = int(round(new_y))
351
+ # Clamp the integer position too
352
+ by = max(1, min(self.height - 2, by))
353
+ p1h = self.paddle_h
354
+ p2h = self.paddle_h_p2
355
+
356
+ # Left paddle
357
+ if new_x <= 2 and self.ball_dx < 0:
358
+ p1_top = int(self.p1_y)
359
+ if p1_top <= by < p1_top + p1h:
360
+ new_x = 3.0
361
+ self.ball_dx = abs(self.ball_dx)
362
+ center = self.p1_y + p1h / 2.0
363
+ offset = (by - center) / (p1h / 2.0)
364
+ self.ball_dy = offset * 1.0
365
+ # Enforce minimum vertical movement so ball never goes flat
366
+ if abs(self.ball_dy) < 0.3:
367
+ self.ball_dy = 0.3 if self.ball_dy >= 0 else -0.3
368
+ # Cap max so it doesn't go too steep
369
+ if self.ball_dy > 0.9:
370
+ self.ball_dy = 0.9
371
+ elif self.ball_dy < -0.9:
372
+ self.ball_dy = -0.9
373
+ self.ball_speed = min(self.ball_speed + 0.08, self.max_speed)
374
+ self.current_rally += 1
375
+ self.p1_combo += 1
376
+ self.p2_combo = 0
377
+ self.spawn_particles(3, by, 4)
378
+ self.shake_frames = 2
379
+
380
+ if self.powerup_x >= 0:
381
+ bx_int = int(round(new_x))
382
+ if abs(bx_int - self.powerup_x) < 2 and abs(by - self.powerup_y) < 2:
383
+ self.collect_powerup(1)
384
+ elif new_x < 0:
385
+ self._score(2)
386
+ return
387
+
388
+ # Right paddle
389
+ if new_x >= self.width - 3 and self.ball_dx > 0:
390
+ p2_top = int(self.p2_y)
391
+ if p2_top <= by < p2_top + p2h:
392
+ new_x = float(self.width - 4)
393
+ self.ball_dx = -abs(self.ball_dx)
394
+ center = self.p2_y + p2h / 2.0
395
+ offset = (by - center) / (p2h / 2.0)
396
+ self.ball_dy = offset * 1.0
397
+ if abs(self.ball_dy) < 0.3:
398
+ self.ball_dy = 0.3 if self.ball_dy >= 0 else -0.3
399
+ if self.ball_dy > 0.9:
400
+ self.ball_dy = 0.9
401
+ elif self.ball_dy < -0.9:
402
+ self.ball_dy = -0.9
403
+ self.ball_speed = min(self.ball_speed + 0.08, self.max_speed)
404
+ self.current_rally += 1
405
+ self.p2_combo += 1
406
+ self.p1_combo = 0
407
+ self.spawn_particles(self.width - 4, by, 4)
408
+ self.shake_frames = 2
409
+
410
+ if self.powerup_x >= 0:
411
+ bx_int = int(round(new_x))
412
+ if abs(bx_int - self.powerup_x) < 2 and abs(by - self.powerup_y) < 2:
413
+ self.collect_powerup(2)
414
+ elif new_x >= self.width:
415
+ self._score(1)
416
+ return
417
+
418
+ # Powerup collection by ball passing through
419
+ if self.powerup_x >= 0:
420
+ bx_int = int(round(new_x))
421
+ by_int = int(round(new_y))
422
+ if abs(bx_int - self.powerup_x) <= 1 and abs(by_int - self.powerup_y) <= 1:
423
+ owner = 1 if self.ball_dx > 0 else 2
424
+ self.collect_powerup(owner)
425
+
426
+ self.ball_x = new_x
427
+ self.ball_y = new_y
428
+
429
+ def _score(self, player):
430
+ if player == 1:
431
+ self.p1_score += 1
432
+ self.spawn_score_particles(self.width - 2, self.height // 2)
433
+ self.shake_frames = 5
434
+ else:
435
+ self.p2_score += 1
436
+ self.spawn_score_particles(2, self.height // 2)
437
+ self.shake_frames = 5
438
+
439
+ self.longest_rally = max(self.longest_rally, self.current_rally)
440
+ self.rallies += 1
441
+ self.clear_powerup_effect()
442
+
443
+ if self.p1_score >= self.win_score:
444
+ self.game_over = True
445
+ self.winner = "PLAYER 1"
446
+ self.total_time = time.time() - self.start_time
447
+ self.state = "GAME_OVER"
448
+ self.spawn_score_particles(self.width // 2, self.height // 2)
449
+ elif self.p2_score >= self.win_score:
450
+ self.game_over = True
451
+ p2name = "CPU" if self.mode == "CPU" else "PLAYER 2"
452
+ self.winner = p2name
453
+ self.total_time = time.time() - self.start_time
454
+ self.state = "GAME_OVER"
455
+ self.spawn_score_particles(self.width // 2, self.height // 2)
456
+ else:
457
+ direction = -1 if player == 1 else 1
458
+ self.reset_ball(direction)
459
+
460
+ # ── Rendering ────────────────────────────────────────────
461
+
462
+ def build_game_frame(self):
463
+ lines = []
464
+
465
+ # Shake offset
466
+ sx = 0
467
+ if self.shake_frames > 0:
468
+ sx = random.choice([-1, 0, 1])
469
+ self.shake_frames -= 1
470
+
471
+ # Score bar with visual flair
472
+ p2name = "CPU" if self.mode == "CPU" else "P2"
473
+ speed_bar = "●" * min(int(self.ball_speed * 3), 8)
474
+ header = f" P1 [{self.p1_score}] {'◈' * self.p1_combo if self.p1_combo > 1 else ''}"
475
+ header2 = f"{'◈' * self.p2_combo if self.p2_combo > 1 else ''} [{self.p2_score}] {p2name}"
476
+ mid_info = f"Speed:{speed_bar}"
477
+ gap = self.width + 2 - len(header) - len(header2) - len(mid_info)
478
+ half = max(gap // 2, 1)
479
+ score_line = header + " " * half + mid_info + " " * half + header2
480
+ lines.append(score_line[:self.width + 2])
481
+
482
+ # Powerup status
483
+ if self.powerup_active:
484
+ pwr_line = f" ★ {self.powerup_active} active ({self.powerup_active_timer // 20 + 1}s) - P{self.powerup_active_owner}"
485
+ elif self.powerup_x >= 0:
486
+ pwr_line = f" ◆ Powerup: {self.powerup_type} available!"
487
+ else:
488
+ pwr_line = ""
489
+ lines.append(pwr_line.ljust(self.width + 2))
490
+
491
+ # Top border
492
+ lines.append("╔" + "═" * self.width + "╗")
493
+
494
+ # Build field
495
+ bx = int(round(self.ball_x))
496
+ by = int(round(self.ball_y))
497
+ # Clamp display position too
498
+ by = max(1, min(self.height - 2, by))
499
+ mid_x = self.width // 2
500
+ p1h = self.paddle_h
501
+ p2h = self.paddle_h_p2
502
+
503
+ # Pre-compute trail positions
504
+ trail_positions = set()
505
+ trail_chars = {}
506
+ trail_syms = ['·', '∙', '◦', '○']
507
+ for i, (tx, ty) in enumerate(self.ball_trail):
508
+ txi = int(round(tx))
509
+ tyi = int(round(ty))
510
+ tyi = max(1, min(self.height - 2, tyi))
511
+ trail_positions.add((txi, tyi))
512
+ idx = min(i, len(trail_syms) - 1)
513
+ trail_chars[(txi, tyi)] = trail_syms[idx]
514
+
515
+ # Pre-compute particle positions
516
+ particle_map = {}
517
+ for p in self.particles:
518
+ px = int(round(p['x']))
519
+ py = int(round(p['y']))
520
+ if 0 <= px < self.width and 0 <= py < self.height:
521
+ particle_map[(px, py)] = p['char']
522
+
523
+ for y in range(self.height):
524
+ row = ["║"]
525
+ for x in range(self.width):
526
+ drawn = False
527
+
528
+ # Particles (top priority visual)
529
+ if (x, y) in particle_map:
530
+ row.append(particle_map[(x, y)])
531
+ drawn = True
532
+
533
+ # Ball
534
+ if not drawn and x == bx and y == by and (self.countdown == 0 or (self.countdown > 0 and int(time.time() * 4) % 2 == 0)):
535
+ row.append("●")
536
+ drawn = True
537
+
538
+ # Trail
539
+ if not drawn and (x, y) in trail_positions and self.countdown == 0:
540
+ row.append(trail_chars.get((x, y), '·'))
541
+ drawn = True
542
+
543
+ # Powerup
544
+ if not drawn and x == self.powerup_x and y == self.powerup_y:
545
+ powerup_syms = {"BIG": "⊕", "FAST": "⊗", "SLOW": "⊘", "TINY": "⊖"}
546
+ sym = powerup_syms.get(self.powerup_type, "◆")
547
+ if int(time.time() * 3) % 2 == 0:
548
+ row.append(sym)
549
+ else:
550
+ row.append("◆")
551
+ drawn = True
552
+
553
+ # Left paddle
554
+ if not drawn and x == 1 and int(self.p1_y) <= y < int(self.p1_y) + p1h:
555
+ if y == int(self.p1_y) or y == int(self.p1_y) + p1h - 1:
556
+ row.append("▐")
557
+ else:
558
+ row.append("█")
559
+ drawn = True
560
+
561
+ # Right paddle
562
+ if not drawn and x == self.width - 2 and int(self.p2_y) <= y < int(self.p2_y) + p2h:
563
+ if y == int(self.p2_y) or y == int(self.p2_y) + p2h - 1:
564
+ row.append("▌")
565
+ else:
566
+ row.append("█")
567
+ drawn = True
568
+
569
+ # Center net
570
+ if not drawn and x == mid_x:
571
+ if y % 2 == 0:
572
+ row.append("│")
573
+ else:
574
+ row.append(" ")
575
+ drawn = True
576
+
577
+ if not drawn:
578
+ row.append(" ")
579
+
580
+ row.append("║")
581
+ line = "".join(row)
582
+
583
+ # Apply shake
584
+ if sx > 0:
585
+ line = " " + line[:-1]
586
+ elif sx < 0:
587
+ line = line[1:] + " "
588
+
589
+ lines.append(line)
590
+
591
+ # Bottom border
592
+ lines.append("╚" + "═" * self.width + "╝")
593
+
594
+ # Status line
595
+ if self.countdown > 0:
596
+ status = f" >>> Get ready... {self.countdown} <<<"
597
+ elif self.current_rally >= 5:
598
+ status = f" 🔥 RALLY: {self.current_rally} hits!"
599
+ else:
600
+ status = ""
601
+
602
+ controls = " W/S:P1"
603
+ if self.mode == "PVP":
604
+ controls += " I/K:P2"
605
+ controls += " P:Pause Q:Quit R:Restart"
606
+ lines.append(controls)
607
+ lines.append(status.ljust(self.width + 2))
608
+
609
+ # Pad
610
+ for _ in range(2):
611
+ lines.append(" " * (self.width + 2))
612
+
613
+ return "\n".join(lines)
614
+
615
+ def build_menu_frame(self):
616
+ items = ["Play vs Player (PVP)", "Play vs CPU", "Quit"]
617
+ lines = []
618
+ lines.append("")
619
+ lines.append(" ╔══════════════════════════════════════════════════════╗")
620
+ lines.append(" ║ ║")
621
+ lines.append(" ║ ____ ___ _ _ ____ _ ║")
622
+ lines.append(" ║ | _ \\ / _ \\ | \\ | | / ___| | | ║")
623
+ lines.append(" ║ | |_) || | | || \\| | | | _ | | ║")
624
+ lines.append(" ║ | __/ | |_| || |\\ | | |_| | |_| ║")
625
+ lines.append(" ║ |_| \\___/ |_| \\_| \\____| (_) ║")
626
+ lines.append(" ║ ║")
627
+ lines.append(" ║ ═══ CONSOLE EDITION ═══ ║")
628
+ lines.append(" ║ ║")
629
+
630
+ for i, item in enumerate(items):
631
+ if i == self.menu_selection:
632
+ lines.append(f" ║ ► {item:<40} ║")
633
+ else:
634
+ lines.append(f" ║ {item:<40} ║")
635
+
636
+ lines.append(" ║ ║")
637
+ lines.append(" ║ Controls: ║")
638
+ lines.append(" ║ W/S or I/K - Move paddle ║")
639
+ lines.append(" ║ P - Pause Q - Quit R - Restart ║")
640
+ lines.append(" ║ ↑/↓ or W/S - Navigate menu ║")
641
+ lines.append(" ║ SPACE/ENTER - Select ║")
642
+ lines.append(" ║ ║")
643
+ lines.append(" ║ Features: ║")
644
+ lines.append(" ║ ★ Powerups ● Ball trails ◈ Combos ║")
645
+ lines.append(" ║ ✦ Particles ⊕ Screen shake ║")
646
+ lines.append(" ║ ║")
647
+ lines.append(" ╚══════════════════════════════════════════════════════╝")
648
+ lines.append("")
649
+
650
+ for _ in range(5):
651
+ lines.append(" " * 60)
652
+
653
+ return "\n".join(lines)
654
+
655
+ def build_difficulty_frame(self):
656
+ diffs = ["Easy - CPU is sleepy", "Medium - A fair match", "Hard - CPU is relentless"]
657
+ lines = []
658
+ lines.append("")
659
+ lines.append(" ╔══════════════════════════════════════════════════════╗")
660
+ lines.append(" ║ ║")
661
+ lines.append(" ║ SELECT CPU DIFFICULTY ║")
662
+ lines.append(" ║ ║")
663
+
664
+ for i, d in enumerate(diffs):
665
+ if i == self.difficulty_selection:
666
+ lines.append(f" ║ ► {d:<42}║")
667
+ else:
668
+ lines.append(f" ║ {d:<42}║")
669
+
670
+ lines.append(" ║ ║")
671
+ lines.append(" ║ W/S to select, SPACE/ENTER to confirm ║")
672
+ lines.append(" ║ ║")
673
+ lines.append(" ╚══════════════════════════════════════════════════════╝")
674
+
675
+ for _ in range(20):
676
+ lines.append(" " * 60)
677
+
678
+ return "\n".join(lines)
679
+
680
+ def build_game_over_frame(self):
681
+ elapsed = int(self.total_time)
682
+ mins = elapsed // 60
683
+ secs = elapsed % 60
684
+
685
+ lines = []
686
+ lines.append("")
687
+ lines.append(" ╔══════════════════════════════════════════════════════╗")
688
+ lines.append(" ║ ║")
689
+ lines.append(" ║ ★ GAME OVER ★ ║")
690
+ lines.append(" ║ ║")
691
+ lines.append(f" ║ {self.winner:^42} ║")
692
+ lines.append(" ║ WINS! ║")
693
+ lines.append(" ║ ║")
694
+ p2label = 'CPU' if self.mode == 'CPU' else 'P2'
695
+ lines.append(f" ║ Final Score: P1 [{self.p1_score}] - [{self.p2_score}] {p2label} ║")
696
+ lines.append(" ║ ║")
697
+ lines.append(" ║ ── Stats ────────────────────────── ║")
698
+ lines.append(f" ║ Time: {mins}m {secs:02d}s ║")
699
+ lines.append(f" ║ Total Rallies: {self.rallies:<36}║")
700
+ lines.append(f" ║ Longest Rally: {self.longest_rally} hits{' ' * 30}║")
701
+ lines.append(" ║ ║")
702
+ lines.append(" ║ [R] Play Again [M] Menu [Q] Quit ║")
703
+ lines.append(" ║ ║")
704
+ lines.append(" ╚══════════════════════════════════════════════════════╝")
705
+
706
+ for _ in range(12):
707
+ lines.append(" " * 60)
708
+
709
+ return "\n".join(lines)
710
+
711
+ # ── Input Handlers ───────────────────────────────────────
712
+
713
+ def handle_menu_input(self, keys):
714
+ for key in keys:
715
+ if key == 'q':
716
+ self.running = False
717
+ elif key in ('w', 'i'):
718
+ self.menu_selection = (self.menu_selection - 1) % 3
719
+ elif key in ('s', 'k'):
720
+ self.menu_selection = (self.menu_selection + 1) % 3
721
+ elif key in (' ', '\r', '\n'):
722
+ if self.menu_selection == 0:
723
+ self.mode = "PVP"
724
+ self.state = "PLAYING"
725
+ self.init_game()
726
+ elif self.menu_selection == 1:
727
+ self.mode = "CPU"
728
+ self.state = "DIFFICULTY"
729
+ elif self.menu_selection == 2:
730
+ self.running = False
731
+
732
+ def handle_difficulty_input(self, keys):
733
+ for key in keys:
734
+ if key == 'q':
735
+ self.state = "MENU"
736
+ elif key in ('w', 'i'):
737
+ self.difficulty_selection = (self.difficulty_selection - 1) % 3
738
+ elif key in ('s', 'k'):
739
+ self.difficulty_selection = (self.difficulty_selection + 1) % 3
740
+ elif key in (' ', '\r', '\n'):
741
+ self.cpu_difficulty = self.difficulty_selection + 1
742
+ self.state = "PLAYING"
743
+ self.init_game()
744
+
745
+ def handle_game_input(self, keys):
746
+ for key in keys:
747
+ if key == 'q':
748
+ self.running = False
749
+ elif key == 'p':
750
+ self.paused = not self.paused
751
+ elif key == 'r':
752
+ self.init_game()
753
+ elif not self.paused and not self.game_over:
754
+ p1h = self.paddle_h
755
+ p2h = self.paddle_h_p2
756
+ if key == 'w':
757
+ self.p1_y = max(0, self.p1_y - 2)
758
+ elif key == 's':
759
+ self.p1_y = min(self.height - p1h, self.p1_y + 2)
760
+ if self.mode == "PVP":
761
+ if key == 'i':
762
+ self.p2_y = max(0, self.p2_y - 2)
763
+ elif key == 'k':
764
+ self.p2_y = min(self.height - p2h, self.p2_y + 2)
765
+
766
+ def handle_gameover_input(self, keys):
767
+ for key in keys:
768
+ if key == 'q':
769
+ self.running = False
770
+ elif key == 'r':
771
+ self.init_game()
772
+ self.state = "PLAYING"
773
+ elif key == 'm':
774
+ self.state = "MENU"
775
+
776
+ # ── Main Loop ────────────────────────────────────────────
777
+
778
+ def run(self):
779
+ try:
780
+ self.hide_cursor()
781
+ self.clear()
782
+
783
+ while self.running:
784
+ start = time.time()
785
+ keys = self.read_keys()
786
+
787
+ if self.state == "MENU":
788
+ self.handle_menu_input(keys)
789
+ frame = self.build_menu_frame()
790
+
791
+ elif self.state == "DIFFICULTY":
792
+ self.handle_difficulty_input(keys)
793
+ frame = self.build_difficulty_frame()
794
+
795
+ elif self.state == "PLAYING":
796
+ self.handle_game_input(keys)
797
+
798
+ if not self.paused and not self.game_over:
799
+ # Countdown
800
+ if self.countdown > 0:
801
+ if time.time() - self.countdown_timer >= 1.0:
802
+ self.countdown -= 1
803
+ self.countdown_timer = time.time()
804
+
805
+ self.update_ball()
806
+ self.update_cpu()
807
+ self.update_particles()
808
+
809
+ # Powerup spawning
810
+ if self.powerup_x >= 0:
811
+ self.powerup_timer -= 1
812
+ if self.powerup_timer <= 0:
813
+ self.powerup_x = -1
814
+ elif random.random() < 0.003 and self.countdown == 0:
815
+ self.spawn_powerup()
816
+
817
+ # Active powerup timer
818
+ if self.powerup_active_timer > 0:
819
+ self.powerup_active_timer -= 1
820
+ if self.powerup_active_timer <= 0:
821
+ self.clear_powerup_effect()
822
+
823
+ frame = self.build_game_frame()
824
+
825
+ if self.paused:
826
+ frame += "\n\n >>> PAUSED - Press P to resume <<<"
827
+
828
+ elif self.state == "GAME_OVER":
829
+ self.handle_gameover_input(keys)
830
+ self.update_particles()
831
+ frame = self.build_game_over_frame()
832
+
833
+ else:
834
+ frame = ""
835
+
836
+ self.move_home()
837
+ sys.stdout.write(frame)
838
+ sys.stdout.flush()
839
+
840
+ elapsed = time.time() - start
841
+ sleep = self.tick_rate - elapsed
842
+ if sleep > 0:
843
+ time.sleep(sleep)
844
+
845
+ except KeyboardInterrupt:
846
+ pass
847
+ finally:
848
+ self.cleanup()
849
+ self.clear()
850
+ print("\n Thanks for playing PONG! 🏓\n")
851
+
852
+
853
+ if __name__ == "__main__":
854
+ game = PongGame()
855
+ game.run()
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: console-pong
3
+ Version: 1.0.0
4
+ Summary: A fully featured Pong game right in your terminal
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/CheezeDeveloper/console-pong
7
+ Keywords: pong,game,terminal,console,cli
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: End Users/Desktop
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Games/Entertainment :: Arcade
15
+ Requires-Python: >=3.7
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ Hi! This is CheezeDev.
21
+
22
+ This is a very cool, playable Ping Pong game, which has trail effects, CPUs, etc!
23
+
24
+ No need for dependencies.
25
+
26
+ To insall, you can use pip install console-pong.
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/console_pong/__init__.py
5
+ src/console_pong/__main__.py
6
+ src/console_pong/game.py
7
+ src/console_pong.egg-info/PKG-INFO
8
+ src/console_pong.egg-info/SOURCES.txt
9
+ src/console_pong.egg-info/dependency_links.txt
10
+ src/console_pong.egg-info/entry_points.txt
11
+ src/console_pong.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pong = console_pong:main
@@ -0,0 +1 @@
1
+ console_pong