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
| def main_loop(): c_x, c_y = 0, 0 p1_y, p2_y = 200, 200 p1 = 0 p2 = 0 b_x, b_y = -1, -1 while True: if p1 >= 6 or p2 >= 6: break scr.fill((0,0,0)) for eve in pg.event.get(): if eve.type == QUIT: sys.exit() keys = pg.key.get_pressed() p1_y, p2_y = draw_p(p1_y, p2_y) draw_socre_zone()
printtext(zt30, "Player 1: " + str(p1), 100, 10, (255,255,255)) printtext(zt30, "Player 2: " + str(p2), 370, 10, (255,255,255)) printtext(zt24, "press R to serve again", 200, 30, (255,255,255))
if (b_x == -1 and b_y) == -1 or keys[K_r]: b_x, b_y, vx, vy = init_ball(2) else: b_x, b_y, vx, vy = update_ball(b_x, b_y, vx, vy, p1_y, p2_y) if b_x in range(0,80) and b_y in range(75, 325): p2 += 1 printtext(zt30, "Player 2 got 1 point!", 220, 200, (255,255,255)) pg.display.update() sleep(1.5) b_x, b_y, vx, vy = init_ball(2) elif b_x in range(520,600) and b_y in range(75, 325): p1 += 1 printtext(zt30, "Player 1 got 1 point!", 220, 200, (255,255,255)) pg.display.update() sleep(1.5) b_x, b_y, vx, vy = init_ball(2) pg.display.update() sleep(0.005) scr.fill((0,0,0)) printtext(zt40, "Player %d got 1 point!"%(1 if p1 > p2 else 2), 220, 200, (255,255,255)) printtext(zt30, "press R to restart", 200, 30, (255,255,255)) pg.display.update()
keys = pg.key.get_pressed() scr.fill((0,0,0))
while not keys[K_r]: for eve in pg.event.get(): if eve.type == QUIT: sys.exit() keys = pg.key.get_pressed()
printtext(zt40, "Player %d WIN!!! Woooo Lololo"%(1 if p1 > p2 else 2), 130, 200, (255,255,255)) printtext(zt30, "press R to restart", 200, 30, (255,255,255)) pg.display.update()
|