Created
April 10, 2022 08:42
-
-
Save Starbuck5/a1516dc8526e9a5d32ac5353f2f29874 to your computer and use it in GitHub Desktop.
Python/pygame pong in 1 line
This file contains 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
while (locals().get("f") or [globals().update(p=__import__("pygame")), p.init(), globals().update(w=p.display.set_mode((800,600))), globals().update(r=[p.Rect(c) for c in [(0, 0, 20, 60), (780, 0, 20, 60), (390, 290, 20, 20)]]), globals().update(b=[5, 5]), locals().update(f=1)]) and [not p.QUIT in [event.type for event in p.event.get()], p.time.wait(10), w.fill(0), [[p.draw.rect, p.draw.ellipse][rx == r[2]](w, "white", rx) for rx in r], p.display.flip(), [r[0].move_ip(0, (p.key.get_pressed()[p.K_s] - p.key.get_pressed()[p.K_w]) * 5), r[1].move_ip(0, (p.key.get_pressed()[p.K_DOWN] - p.key.get_pressed()[p.K_UP]) * 5), r[2].move_ip(*b)], [rect.clamp_ip(w.get_rect()) for rect in r[0:2]], setattr(r[2], "topleft", (390, 290) if r[2].x < 0 or r[2].right > 800 else r[2].topleft)][0]: b[1], b[0] = -b[1] if not 0 < r[2].y < 540 else b[1], -b[0] if r[2].collidelist(r[:2]) >= 0 else b[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by this post: https://www.reddit.com/r/pygame/comments/ty105f/i_compressed_a_pong_game_into_14_lines_of_code/