-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmistery.py
More file actions
44 lines (37 loc) · 1.22 KB
/
mistery.py
File metadata and controls
44 lines (37 loc) · 1.22 KB
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
import pygame
import random
class Mistery(pygame.sprite.Sprite):
def __init__(self, screen):
super(Mistery, self).__init__()
self.screen = screen
self.image = pygame.image.load("icons/mysteryb.ico")
self.rect = self.image.get_rect()
self.rect.x = self.rect.width
self.rect.y = self.rect.height
self.x = float(self.rect.x)
self.y = 40
self.is_appear = False
self.move_x = 2.5
def print(self):
self.screen.blit(self.image, self.rect)
def update(self):
if (not self.is_appear):
if random.randint(0, 1000) == 1:
self.start()
return
if self.rect.x - 30 > self.screen.get_width() or self.rect.x < -30:
self.is_appear = False
self.x += self.move_x
self.rect.x = self.x
def start(self):
self.is_appear = True
if random.randint(0, 2) == 1:
self.x = -30
self.rect.x = self.x
self.rect.y = self.y
self.move_x = abs(self.move_x)
else:
self.x = self.screen.get_width() + 30
self.rect.x = self.x
self.rect.y = self.y
self.move_x = -abs(self.move_x)