-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprites_classes.py
115 lines (95 loc) · 4.06 KB
/
sprites_classes.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from principal import *
import constantes as const
from random import randrange, randint
class Dino(pygame.sprite.Sprite):
def __init__(self, spritesheet):
pygame.sprite.Sprite.__init__(self)
self.imagens_dinossauro = []
for index in range(4):
img = spritesheet.subsurface((index * 32, 0), (32, 32))
img = pygame.transform.scale(img, (32 * 3, 32 * 3))
self.imagens_dinossauro.append(img)
self.indice_lista = 0
self.image = self.imagens_dinossauro[self.indice_lista]
self.rect = self.image.get_rect()
self.rect.center = (100, const.ALTURA - 64)
self.mask = pygame.mask.from_surface(self.image)
self.pos_y_inicial = const.ALTURA - 64 - 96 // 2
self.pulo = False
def update(self):
if self.pulo:
if self.rect.y < 200:
self.pulo = False
self.rect.y -= 13
else:
if self.rect.y < self.pos_y_inicial:
self.rect.y += 12
else:
self.rect.y = self.pos_y_inicial
if self.indice_lista > 2:
self.indice_lista = 0
self.indice_lista += 0.15
self.image = self.imagens_dinossauro[int(self.indice_lista)]
class Chao(pygame.sprite.Sprite):
def __init__(self, sprite_sheet, pos_x):
pygame.sprite.Sprite.__init__(self)
self.image = sprite_sheet.subsurface((6 * 32, 0), (32, 32))
self.image = pygame.transform.scale(self.image, (32 * 2, 32 * 2))
self.rect = self.image.get_rect()
self.rect.topleft = (pos_x * 61, const.ALTURA - 64)
def update(self):
if self.rect.topright[0] < 0:
self.rect.x = const.LARGURA
self.rect.x -= const.VELOCIDADE_JOGO
class Cacto(pygame.sprite.Sprite):
def __init__(self, sprite_sheet):
pygame.sprite.Sprite.__init__(self)
self.image = sprite_sheet.subsurface((5 * 32, 0), (32, 32))
self.image = pygame.transform.scale(self.image, (32 * 2, 32 * 2))
self.rect = self.image.get_rect()
self.mask = pygame.mask.from_surface(self.image)
self.escolha = const.ESCOLHA_OBSTACULO
self.rect.center = (const.LARGURA, const.ALTURA - 64)
self.rect.x = const.LARGURA
def update(self):
if self.escolha == 0:
if self.rect.topright[0] < 0:
self.rect.x = const.LARGURA
self.rect.x -= const.VELOCIDADE_JOGO
class Nuvem(pygame.sprite.Sprite):
def __init__(self, sprite_sheet):
pygame.sprite.Sprite.__init__(self)
self.image = sprite_sheet.subsurface((7 * 32, 0), (32, 32))
self.image = pygame.transform.scale(self.image, (32 * 3, 32 * 3))
self.rect = self.image.get_rect()
self.rect.y = randrange(50, 200, 50)
self.rect.x = const.LARGURA - randrange(30, 300, 90)
def update(self):
if self.rect.topright[0] < 0:
self.rect.x = randint(const.LARGURA, const.LARGURA * 2)
self.rect.y = randrange(50, 200, 50)
self.rect.x -= 5
class DinoVoador(pygame.sprite.Sprite):
def __init__(self, sprite_sheet):
pygame.sprite.Sprite.__init__(self)
self.imagens_dinossauro = []
for index in range(3, 5):
img = sprite_sheet.subsurface((index * 32, 0), (32, 32))
img = pygame.transform.scale(img, (32 * 3, 32 * 3))
self.imagens_dinossauro.append(img)
self.index_lista = 0
self.image = self.imagens_dinossauro[self.index_lista]
self.mask = pygame.mask.from_surface(self.image)
self.escolha = const.ESCOLHA_OBSTACULO
self.rect = self.image.get_rect()
self.rect.center = (const.LARGURA, 300)
self.rect.x = const.LARGURA
def update(self):
if self.escolha == 1:
if self.index_lista > 1.9:
self.index_lista = 0
if self.rect.topright[0] < 0:
self.rect.x = const.LARGURA
self.rect.x -= const.VELOCIDADE_JOGO + 2
self.index_lista += 0.15
self.image = self.imagens_dinossauro[int(self.index_lista)]