-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame8.py
57 lines (46 loc) · 1.18 KB
/
game8.py
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
import pygame
from pygame.locals import *
import random
# setup display surface
pygame.init()
surface_size = (800,800)
main_surface = pygame.display.set_mode(surface_size)
my_clock = pygame.time.Clock()
# setup colors
BLACK = (0,0,0)
GRAY = (127,127,127)
WHITE = (255,255,255)
RED = (255,0,0)
violet = (150,0,255)
BLUE = (0,0,255)
# draw on the main surface
def draw_circle(pos):
x = pos[0]
y = pos[1]
pygame.draw.circle(main_surface, BLUE, (x,y), 10, 0)
def draw_rectangle(pos):
x = pos[0]
y = pos[1]
pygame.draw.rect(main_surface, WHITE, [x, y, 10, 10], 0)
def random_generate():
random_x = random.randint(0, 800)
random_y = random.randint(0, 800)
random_shape = random.choice([draw_circle, draw_rectangle])
random_shape((random_x, random_y))
# game loop
while True:
my_clock.tick(60)
# handle pygame events
ev = pygame.event.poll()
if ev.type == QUIT:
# exit the game loop
break
# add background
main_surface.fill(GRAY)
# draw on the main surface
pos_x, pos_y = pygame.mouse.get_pos()
draw_rectangle([pos_x, pos_y])
random_generate()
# update screen
pygame.display.flip()
pygame.quit()