Beispiel #1
0
    def on_render(self, g):
        # Touch
        if self.show_touch:
            pygame.draw.circle(g.surface, self.color,
                               (int(self.touchx), int(self.touchy)), 10)

        rect = Rect(0, 0, 40, 40)
        rect.width = 40
        rect.height = 40
        rect.centerx = self.aimx
        rect.centery = self.aimy

        pygame.draw.arc(g.surface, (0, 0, 255), rect, 0, 360, 5)

        from giantplay import cfg
        pygame.draw.line(
            g.surface, (0, 0, 255),
            (int(cfg.SCREEN_WIDTH / 2), int(cfg.SCREEN_HEIGHT / 2)),
            (int(cfg.SCREEN_WIDTH / 2 + self.axisx * 100),
             int(cfg.SCREEN_HEIGHT / 2)), 5)
        pygame.draw.line(
            g.surface, (0, 0, 255),
            (int(cfg.SCREEN_WIDTH / 2), int(cfg.SCREEN_HEIGHT / 2)),
            (int(cfg.SCREEN_WIDTH / 2),
             int(cfg.SCREEN_HEIGHT / 2 + self.axisy * 100)), 5)
Beispiel #2
0
 def draw_health_bar(self, screen, target_rect):
     if self.health != self.max_health:
         health_rect = Rect(0, 0, 25, 7)
         health_rect.bottom = target_rect.top - 2
         health_rect.centerx = target_rect.centerx
         pygame.draw.rect(screen, Color('gray'), health_rect)
         health_rect.width *= self.health / self.max_health
         pygame.draw.rect(screen, Color('red'), health_rect)
Beispiel #3
0
def getEndGameSplash(winnerName = None, winnerColor = None):
    """If winningName and winnerColor are both None,
       display a tie game screen.
    """

    screen = Display.get_surface()
    splashGroup = SpriteGroup()
    if(winnerName != None and winnerColor != None):
        # Create winning bomberman image
        fatalityRect = Rect((0, 0, 500, 500))
        fatalityRect.centerx = screen.get_rect().centerx
        fatalityRect.centery = screen.get_rect().centery
        fatalityAnimation = WorldlessWidget(Surface((500, 500)), fatalityRect)
        fatalImage = pygame.image.load('images/fatality.png').convert()
        fatalImage.set_colorkey(LAVENDER)
        bmanColor = Surface((fatalImage.get_width(),
                          fatalImage.get_height()))
        bmanColor.fill(winnerColor)
        bmanColor.blit(fatalImage, bmanColor.get_rect())
        winnerFrames = createFrames(bmanColor)
        fatalityAnimation.startAnimation(winnerFrames, 0, 12)
        splashGroup.add(fatalityAnimation)

        # Create text for winning player
        winnerText = TextBar(winnerName + \
                             ' Wins!', (0, 0, 200, 50), 50)
        imgWidth = winnerText.image.get_width()
        winnerText.rect.left = (screen.get_size()[X]-imgWidth)/2
        splashGroup.add(winnerText)
    else:
        tieText = TextBar('TIE GAME!',
                                 (0, 20, 250, 50), 35)
        imgWidth = tieText.image.get_width()
        tieText.rect.left = (screen.get_size()[X]-imgWidth)/2
        splashGroup.add(tieText)

    escMessage = TextBar("Press Escape to exit.", (0, 60, 250, 50), 25)
    imgWidth = escMessage.image.get_width()
    escMessage.rect.left = (screen.get_size()[X] - imgWidth) / 2
    splashGroup.add(escMessage)

    pressKeyText = TextBar('Press a key or button when ready. Next round will start when everyone is ready.',
                           (0, 90, 250, 50), 25)
    imgWidth = pressKeyText.image.get_width()
    pressKeyText.rect.left = (screen.get_size()[X] - imgWidth) / 2
    splashGroup.add(pressKeyText)

    return splashGroup
Beispiel #4
0
def getEndGameSplash(winnerName=None, winnerColor=None):
    """If winningName and winnerColor are both None,
       display a tie game screen.
    """

    screen = Display.get_surface()
    splashGroup = SpriteGroup()
    if winnerName != None and winnerColor != None:
        # Create winning bomberman image
        fatalityRect = Rect((0, 0, 500, 500))
        fatalityRect.centerx = screen.get_rect().centerx
        fatalityRect.centery = screen.get_rect().centery
        fatalityAnimation = WorldlessWidget(Surface((500, 500)), fatalityRect)
        fatalImage = pygame.image.load("images/fatality.png").convert()
        fatalImage.set_colorkey(LAVENDER)
        bmanColor = Surface((fatalImage.get_width(), fatalImage.get_height()))
        bmanColor.fill(winnerColor)
        bmanColor.blit(fatalImage, bmanColor.get_rect())
        winnerFrames = createFrames(bmanColor)
        fatalityAnimation.startAnimation(winnerFrames, 0, 12)
        splashGroup.add(fatalityAnimation)

        # Create text for winning player
        winnerText = TextBar(winnerName + " Wins!", (0, 0, 200, 50), 50)
        imgWidth = winnerText.image.get_width()
        winnerText.rect.left = (screen.get_size()[X] - imgWidth) / 2
        splashGroup.add(winnerText)
    else:
        tieText = TextBar("TIE GAME!", (0, 20, 250, 50), 35)
        imgWidth = tieText.image.get_width()
        tieText.rect.left = (screen.get_size()[X] - imgWidth) / 2
        splashGroup.add(tieText)

    escMessage = TextBar("Press Escape to exit.", (0, 60, 250, 50), 25)
    imgWidth = escMessage.image.get_width()
    escMessage.rect.left = (screen.get_size()[X] - imgWidth) / 2
    splashGroup.add(escMessage)

    pressKeyText = TextBar(
        "Press a key or button when ready. Next round will start when everyone is ready.", (0, 90, 250, 50), 25
    )
    imgWidth = pressKeyText.image.get_width()
    pressKeyText.rect.left = (screen.get_size()[X] - imgWidth) / 2
    splashGroup.add(pressKeyText)

    return splashGroup
def adjust_rect(rect: Rect,
                x: int,
                y: int,
                align: str = "center",
                vertical_align: str = "middle") -> Rect:
    if align == "left":
        rect.left = x
    elif align == "right":
        rect.right = x
    else:
        rect.centerx = x

    if vertical_align == "top":
        rect.top = y
    elif vertical_align == "bottom":
        rect.bottom = y
    else:
        rect.centery = y
    return rect
Beispiel #6
0
    def draw(self, screen):
        super().draw(screen)
        mark_rect = Rect(self.absolute_bounds.x, self.absolute_bounds.y, self.mark_size, self.mark_size)
        for unit in self.game.sprites:
            shape = unit.cls_dict.get('mark_shape', 'quad')

            pos = self.worldpos_to_minimap(unit.pos.x, unit.pos.y)
            mark_rect.centerx = self.absolute_bounds.x + pos[0]
            mark_rect.centery = self.absolute_bounds.y + pos[1]

            if shape == 'circle':
                pygame.draw.ellipse(screen, self.mark_color, mark_rect)
                pygame.draw.ellipse(screen, unit.team_color, mark_rect, 2)
            if shape == 'quad':
                pygame.draw.rect(screen, self.mark_color, mark_rect)
                pygame.draw.rect(screen, unit.team_color, mark_rect, 3)

        camera_rect = Rect(
            (self.game.world_size - self.game.camera.offset_x) * self.world_ratio_width,
            (self.game.world_size - self.game.camera.offset_y) * self.world_ratio_height,
            config['screen']['size'][0] * self.world_ratio_width,
            config['screen']['size'][1] * self.world_ratio_height
        )
        pygame.draw.rect(screen, Color('yellow'), camera_rect.move(self.absolute_bounds.x, self.absolute_bounds.y), 1)
Beispiel #7
-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()