Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import pygame as pg
  2. import random
  3.  
  4. def make_points(N, W, H):
  5. points = []
  6. for i in range(N):
  7. x = random.randint(0, W)
  8. y = random.randint(0, H)
  9. points.append([x, y])
  10. return points
  11.  
  12. def dist(x1, y1, x2, y2):
  13. x = x2 - x1
  14. y = y2 - y1
  15. d = (x**2 + y**2)**(1/2)
  16. return d
  17.  
  18.  
  19. pg.init()
  20.  
  21. W, H = 640, 480
  22.  
  23. win = pg.display.set_mode([W, H])
  24.  
  25. pg.display.set_caption("DENISOV ANDREY")
  26.  
  27. x = 100
  28. y = 100
  29. r = 20
  30.  
  31.  
  32.  
  33. x_s = 1
  34. y_s = 1
  35.  
  36. N = 15
  37. red_points = make_points(N, W, H)
  38. green_points = make_points(N, W, H)
  39.  
  40. bg = pg.image.load("bg.jpg.jpg")
  41.  
  42. S = 0
  43.  
  44.  
  45.  
  46. while True:
  47. for event in pg.event.get():
  48. if event.type == pg.QUIT:
  49. break
  50.  
  51. win.fill([255,255,255])
  52. pg.draw.circle(win, [255, 0, 0], (x,y), r)
  53.  
  54. for p in green_points:
  55. pg.draw.circle(win, [0, 255, 0], (p[0], p[1]), 5)
  56. if dist(x,y,p[0],p[1]) <= r+5:
  57. S = S+1
  58. print(S)
  59. green_points.remove([p[0],p[1]])
  60.  
  61.  
  62.  
  63. for p in red_points:
  64. pg.draw.circle(win, [255, 0, 0], (p[0], p[1]), 5)
  65. if dist(x,y,p[0],p[1]) <= r+5:
  66. S = S-1
  67. print(S)
  68. red_points.remove([p[0],p[1]])
  69.  
  70. keys = pg.key.get_pressed()
  71.  
  72. if keys[pg.K_UP] and y > 0 + r :
  73. y -= y_s
  74. if keys[pg.K_DOWN] and y < H - r :
  75. y+= y_s
  76. if keys[pg.K_LEFT] and x > 0 + r :
  77. x-= x_s
  78. if keys[pg.K_RIGHT] and x < W - r :
  79. x+= x_s
  80.  
  81.  
  82. pg.display.update()
  83.  
  84.  
  85.  
  86. pg.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement