Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame as pg
- import random
- def make_points(N, W, H):
- points = []
- for i in range(N):
- x = random.randint(0, W)
- y = random.randint(0, H)
- points.append([x, y])
- return points
- def dist(x1, y1, x2, y2):
- x = x2 - x1
- y = y2 - y1
- d = (x**2 + y**2)**(1/2)
- return d
- pg.init()
- W, H = 640, 480
- win = pg.display.set_mode([W, H])
- pg.display.set_caption("DENISOV ANDREY")
- x = 100
- y = 100
- r = 20
- x_s = 1
- y_s = 1
- N = 15
- red_points = make_points(N, W, H)
- green_points = make_points(N, W, H)
- bg = pg.image.load("bg.jpg.jpg")
- S = 0
- while True:
- for event in pg.event.get():
- if event.type == pg.QUIT:
- break
- win.fill([255,255,255])
- pg.draw.circle(win, [255, 0, 0], (x,y), r)
- for p in green_points:
- pg.draw.circle(win, [0, 255, 0], (p[0], p[1]), 5)
- if dist(x,y,p[0],p[1]) <= r+5:
- S = S+1
- print(S)
- green_points.remove([p[0],p[1]])
- for p in red_points:
- pg.draw.circle(win, [255, 0, 0], (p[0], p[1]), 5)
- if dist(x,y,p[0],p[1]) <= r+5:
- S = S-1
- print(S)
- red_points.remove([p[0],p[1]])
- keys = pg.key.get_pressed()
- if keys[pg.K_UP] and y > 0 + r :
- y -= y_s
- if keys[pg.K_DOWN] and y < H - r :
- y+= y_s
- if keys[pg.K_LEFT] and x > 0 + r :
- x-= x_s
- if keys[pg.K_RIGHT] and x < W - r :
- x+= x_s
- pg.display.update()
- pg.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement