Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame,sys
- from pygame.locals import*
- pygame.init()
- SF=pygame.display.set_mode((600,600), pygame.DOUBLEBUF)
- pygame.display.set_caption('A-Ping Pong (Idea by Hackermakduf)')
- SF.fill((0, 0, 0))
- FPS=60
- pygame.mouse.set_visible(False)
- ball={"rect":[SF.get_rect().centerx, SF.get_rect().centery, 20, 20],
- "dir_vector" : [-5, 3],
- "radius" : 10,
- "color": (0, 255, 0)}
- plate_1={"rect": [250, SF.get_height()-25, 100, 50],
- "color": (255, 0, 0), "speed":10}
- plate_2={"rect": [250, -25, 100, 50],
- "color": (0, 0, 255), "speed":10}
- FPS_CLOCK=pygame.time.Clock()
- RIGHT1, RIGHT2, LEFT1, LEFT2 = False, False, False, False
- while True:
- for event in pygame.event.get():
- if event.type==QUIT:
- pygame.quit()
- sys.exit()
- if event.type==KEYDOWN:
- if event.key==K_RIGHT:
- RIGHT1= True
- if event.key==K_d:
- RIGHT2= True
- if event.key==K_LEFT:
- LEFT1=True
- if event.key==K_a:
- LEFT2=True
- if event.type==KEYUP:
- if event.key==K_RIGHT:
- RIGHT1= False
- if event.key==K_d:
- RIGHT2= False
- if event.key==K_LEFT:
- LEFT1=False
- if event.key==K_a:
- LEFT2=False
- SF.fill((0, 0, 0))
- #Check_For_Collision:
- if ball["rect"][0]-ball["radius"] <= 10 or ball["rect"][0]+ball["radius"] >= SF.get_width()-10:
- ball["dir_vector"][0]*=-1
- if ball["rect"][1] <= 5 or ball["rect"][1]+ball["radius"] >= SF.get_height()-10:
- ball["dir_vector"][1]*=-1
- #Check_For_Collision_end:
- #Add_Velocities:
- ball["rect"][0]+=ball["dir_vector"][0]
- if ball["rect"][0]-ball["radius"] < 10:
- ball["rect"][0]=10+ball["radius"]
- elif ball["rect"][0]+ball["radius"] > SF.get_width()-10:
- ball["rect"][0]=SF.get_width()-10-ball["radius"]
- ball["rect"][1]+=ball["dir_vector"][1]
- #Add_Velocities_end:
- #Draw_Borders:
- pygame.draw.line(SF, (255, 255, 255),(5, SF.get_height()), (5, 0), 10)
- pygame.draw.line(SF, (255, 255, 255),(SF.get_width()-5, SF.get_height()), (SF.get_width()-5, 0), 10)
- #Draw_Borders_end:
- #Draw_Ball:
- pygame.draw.circle(SF, ball["color"], (ball["rect"][0], ball["rect"][1]),
- ball["radius"], 4)
- #Draw_Ball_end:
- #Draw_Plate_1:
- pygame.draw.arc(SF, plate_1["color"], plate_1["rect"], 20, 160, 10)
- #Draw_Plate_2:
- pygame.draw.arc(SF, plate_2["color"], plate_2["rect"], 20, 160, 10)
- if RIGHT1:
- plate_1["rect"][0]+=plate_1["speed"]
- if LEFT1:
- plate_1["rect"][0]-=plate_1["speed"]
- if RIGHT2:
- plate_2["rect"][0]+=plate_2["speed"]
- if LEFT2:
- plate_2["rect"][0]-=plate_2["speed"]
- pygame.display.flip()
- FPS_CLOCK.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement