SHOW:
|
|
- or go back to the newest paste.
1 | import pygame, random | |
2 | ||
3 | class Target(pygame.sprite.Sprite): | |
4 | def __init__(self): | |
5 | super().__init__() | |
6 | self.image = pygame.Surface((45,45)) | |
7 | self.image.fill((255,255,0)) | |
8 | self.rect = self.image.get_rect() | |
9 | self.x = random.randrange(20, 1004) | |
10 | self.y = random.randrange(20, 748) | |
11 | self.rect.center = (self.x, self.y) | |
12 | ||
13 | class crosshair(pygame.sprite.Sprite): | |
14 | def __init__(self): | |
15 | super().__init__() | |
16 | self.image = pygame.Surface((10,10)) | |
17 | self.image.fill((255,0,0)) | |
18 | self.rect = self.image.get_rect() | |
19 | self.rect.center = (0, 0) | |
20 | ||
21 | def update(self): | |
22 | position = pygame.mouse.get_pos() | |
23 | self.rect.center = position | |
24 | ||
25 | pygame.init() | |
26 | window = pygame.display.set_mode((1024, 768)) | |
27 | run = True | |
28 | pygame.mouse.set_visible(False) | |
29 | aim = crosshair() | |
30 | sprites = pygame.sprite.Group() | |
31 | sprites.add(aim) | |
32 | while run: | |
33 | window.fill((0,0,0)) | |
34 | for event in pygame.event.get(): | |
35 | if event.type == pygame.QUIT: | |
36 | run = False | |
37 | sprites.update() | |
38 | sprites.draw(window) | |
39 | pygame.display.update() | |
40 | pygame.quit() | |
41 |