예제 #1
0
 def bomb(self, current_tick):
     if self.bomb_interval + self.last_bomb < current_tick:
         rect = Rect(self.rect.midbottom, (32, 32))
         rect.midtop = self.rect.midbottom
         bomb = Bomb(image=None, rect=rect)
         bomb.x_velocity = self.x_velocity
         bomb.y_velocity = self.y_velocity
         bomb.x_acceleration = 0
         bomb.max_velocity = self.max_velocity * 10
         bomb.falling = True
         self.bombs.add(bomb)
         self.last_bomb = current_tick
예제 #2
-1
def startGame():
    background = pygame.surface.Surface(RESOLUTION)
    background = pygame.image.load(BACKGROUND).convert()
    screen.blit(background, ((0, 0),RESOLUTION))

    # Create title from image
    titleSize = ((int(RESOLUTION[0] * .75)), (int(RESOLUTION[0] * .3)))
    titleRect = Rect((0, 0), titleSize)
    titleRect.midtop = (screen.get_rect().centerx, 20)
    titleSurf = pygame.surface.Surface(titleSize)
    title = Widget(titleSurf, titleRect)
    tempImage = pygame.image.load('images/title.png').convert()
    tempImage = pygame.transform.scale(tempImage, titleSize)
    tempImage.set_colorkey(PUCE, RLEACCEL)
    title.image = tempImage

    # Create animated bomb on screen
    bombRect = Rect((0, 0), (200, 200))
    bombRect.centerx = screen.get_rect().centerx
    bombRect.centery = screen.get_rect().centery
    bombSurf = pygame.surface.Surface((200, 200))
    bomb = Widget(bombSurf, bombRect)
    tempImage = pygame.image.load('images/bomb/bomb_strip_title.png').convert()
    bombFrames = createFrames(tempImage)
    bomb.image = bombFrames[0]

    # Create 'Press any Key' message from image
    pressKeySize = ((int(RESOLUTION[0] * .75)), (int(RESOLUTION[0] * .15)))
    pressKeySurf = pygame.surface.Surface(pressKeySize)
    pressKeyRect = Rect((0, 0), pressKeySize)
    pressKeyRect.midbottom = screen.get_rect().midbottom
    pressKey = Widget(pressKeySurf, pressKeyRect)
    tempImage = pygame.image.load('images/press_key.png').convert()
    tempImage = pygame.transform.scale(tempImage, pressKeySize)
    tempImage.set_colorkey(PUCE, RLEACCEL)
    pressKey.image = tempImage

    myGroup = SpriteGroup()
    myGroup.add(title)
    myGroup.add(bomb)
    myGroup.add(pressKey)

    pygame.display.flip()

    i = 0
    MaxFR = 15
    lastUpdate = t.time()
    frameTime = 1.0 / float(MaxFR)
    while 1:
        pygame.event.pump()
        for event in pygame.event.get():
            if event.type == KEYDOWN or event.type == JOYBUTTONDOWN:
                return
            if event.type == QUIT:
                s.exit()

        bomb.image = bombFrames[i]
        myGroup.clear(screen, background)
        myGroup.update()
        dirty = myGroup.draw(screen)
        pygame.display.update(dirty)
        if t.time() > lastUpdate + frameTime:
            i = (i+1) % 4
            lastUpdate = t.time()