Pythonpip
~
:
''''''
class Mole(pygame.sprite.Sprite):
def __init__(self, image_paths, position, **kwargs):
pygame.sprite.Sprite.__init__(self)
self.images = [pygame.transform.scale(pygame.image.load(image_paths[
0]), (101, 103)),
pygame.transform.scale(pygame.image.load(image_paths[-
1]), (101, 103))]
self.image = self.images[0]
self.rect = self.image.get_rect()
self.mask = pygame.mask.from_surface(self.image)
self.setPosition(position)
self.is_hammer = False
''''''
def setPosition(self, pos):
self.rect.left, self.rect.top = pos
''''''
def setBeHammered(self):
self.is_hammer = True
''''''
def draw(self, screen):
if self.is_hammer: self.image = self.images[1]
screen.blit(self.image, self.rect)
''''''
def reset(self):
self.image = self.images[0]
self.is_hammer = False
(
)
class Hammer(pygame.sprite.Sprite):
def __init__(self, image_paths, position, **kwargs):
pygame.sprite.Sprite.__init__(self)
self.images = [pygame.image.load(image_paths[0]), pygame.image.l
oad(image_paths[1])]
self.image = self.images[0]
self.rect = self.image.get_rect()
self.mask = pygame.mask.from_surface(self.images[1])
self.rect.left, self.rect.top = position
#
self.hammer_count = 0
self.hammer_last_time = 4
self.is_hammering = False
''''''
def setPosition(self, pos):
self.rect.centerx, self.rect.centery = pos
'''hammering'''
def setHammering(self):
self.is_hammering = True
''''''
def draw(self, screen):
if self.is_hammering:
self.image = self.images[1]
self.hammer_count += 1
if self.hammer_count > self.hammer_last_time:
self.is_hammering = False
self.hammer_count = 0
else:
self.image = self.images[0]
screen.blit(self.image, self.rect)
OK
''''''
def initGame():
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode(cfg.SCREENSIZE)
pygame.display.set_caption
return screen
- 1
- 2
前往页