@glench/

Python Play pong game demo

Pygame

A simple pong game using Python Play.

fork
loading
Files
  • main.py
  • nohup.out
  • requirements.txt

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.41538593892420406","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHBsYXkgIyB0aGlzIHNob3VsZCBhbHdheXMgYmUgdGhlIGZpcnN0IGxpbmUKCmJveCA9IHBsYXkubmV3X2JveChjb2xvcj0nYmxhY2snLCB4PTM1MCwgeT0wLCB3aWR0aD0zMCwgaGVpZ2h0PTEyMCkKCm90aGVyX2JveCA9IHBsYXkubmV3X2JveChjb2xvcj0nYmxhY2snLCB4PS0zNTAsIHk9MCwgd2lkdGg9MzAsIGhlaWdodD0xMjApCm90aGVyX2JveC5keSA9IDMKCmJhbGwgPSBwbGF5Lm5ld19ib3goY29sb3I9J2RhcmsgcmVkJywgeD0wLCB5PTAsIHdpZHRoPTIwLCBoZWlnaHQ9MjApCmJhbGwuZHggPSAyCmJhbGwuZHkgPSAtMQoKQHBsYXkud2hlbl9rZXlfcHJlc3NlZCgndXAnKQphc3luYyBkZWYgZG8oa2V5KToKICAgIGJveC55ICs9IDEwCgpAcGxheS53aGVuX2tleV9wcmVzc2VkKCdkb3duJykKYXN5bmMgZGVmIGRvKGtleSk6CiAgICBib3gueSAtPSAxMAoKIyBtYWtlIHRoZSBiYWxsIG1vdmUKQHBsYXkucmVwZWF0X2ZvcmV2ZXIKYXN5bmMgZGVmIGRvKCk6CiAgICBiYWxsLnggKz0gYmFsbC5keAogICAgYmFsbC55ICs9IGJhbGwuZHkKCiMgbWFrZSB0aGUgYmFsbCBib3VuY2Ugb2ZmIHRoZSBwbGF5ZXIncyBwYWRkbGUKQHBsYXkucmVwZWF0X2ZvcmV2ZXIKYXN5bmMgZGVmIGRvKCk6CiAgICBpZiAoYmFsbC5yaWdodCA+PSBib3gubGVmdCkgYW5kIChiYWxsLnRvcCA+PSBib3guYm90dG9tKSBhbmQ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vcCA+PSBwbGF5LnNjcmVlbi50b3A6CiAgICAgICAgYmFsbC5keSA9IC0xCgpwbGF5LnN0YXJ0X3Byb2dyYW0oKSAjIHRoaXMgc2hvdWxkIGFsd2F5cyBiZSB0aGUgbGFzdCBsaW5l"},"asBuffer":null},"loaded":true}}
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
import play # this should always be the first line

box = play.new_box(color='black', x=350, y=0, width=30, height=120)

other_box = play.new_box(color='black', x=-350, y=0, width=30, height=120)
other_box.dy = 3

ball = play.new_box(color='dark red', x=0, y=0, width=20, height=20)
ball.dx = 2
ball.dy = -1

@play.when_key_pressed('up')
async def do(key):
    box.y += 10

@play.when_key_pressed('down')
async def do(key):
    box.y -= 10

# make the ball move
@play.repeat_forever
async def do():
    ball.x += ball.dx
    ball.y += ball.dy

# make the ball bounce off the player's paddle
@play.repeat_forever
async def do():
    if (ball.right >= box.left) and (ball.top >= box.bottom) and (ball.bottom <= box.top) and (ball.left < box.left):
        ball.dx = -2

# make the computer player follow the ball
@play.repeat_forever
async def do():
    if ball.x < 0 and abs(ball.y-other_box.y) > other_box.dy:
        if other_box.y < ball.y:
            other_box.y += other_box.dy
        elif other_box.y > ball.y:
            other_box.y -= other_box.dy

# make the ball bounce off the computer player's paddle
@play.repeat_forever
async def do():
    if (ball.left <= other_box.right) and (ball.top >= other_box.bottom) and (ball.bottom <= other_box.top) and (ball.right > other_box.right):
        other_box.dy = play.random_number(1, 4)
        ball.dx = 2

# make ball bounce off bottom and top walls
@play.repeat_forever
async def do():
    if ball.bottom <= play.screen.bottom:
        ball.dy = 1
    elif ball.top >= play.screen.top:
        ball.dy = -1

play.start_program() # this should always be the last line