Exemplo n.º 1
0
def load_main_screen(utility, DISPLAYSURF):
    doesnt_want_to_play = True
    current_coors = Coordinate(0.0, 0.0, 0.0, 0.0)

    pygame.mixer.music.load("./music/main_theme.mp3")
    pygame.mixer.music.play(-1, 0.0)

    #title
    utility.draw_text(DISPLAYSURF, "GAME DEMO", 50, 235, 100, "green", "white")
    #play
    utility.draw_text(DISPLAYSURF, "PLAY", 25, 225, 300, "green", "black")

    while doesnt_want_to_play:  # main game loop
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == MOUSEBUTTONUP:
                x, y = event.pos
                current_coors.setCoordinates(x, y)
                #clicked play
                if current_coors.getX() in range(
                        166, 284) and current_coors.getY() in range(290, 309):
                    doesnt_want_to_play = False
                    pygame.mixer.music.stop()
                    DISPLAYSURF.fill(utility.getColor("white"))
                    time.sleep(0.1)
        pygame.display.update()
Exemplo n.º 2
0
class Bar:
    def __init__(self):
        self.utility = Util()
        self.rect = pygame.Rect(200, 300, 80, 5)
        self.coordinate = Coordinate(0.0, 0.0, 0.0, 0.0)
        self.lives = 3
        self.score = 0

    def draw(self, DISPLAYSURF):
        #(x, y, width, height)
        pygame.draw.rect(DISPLAYSURF, self.utility.getColor("black"),
                         self.rect)
        # draw lives to the screen
        self.drawLives(DISPLAYSURF)
        # draw score to the screen
        self.drawScore(DISPLAYSURF)

    def drawLives(self, DISPLAYSURF):
        # lives
        self.utility.draw_text(DISPLAYSURF, "Lives: " + str(self.lives), 25,
                               465, 390, "black", "white")

    def drawScore(self, DISPLAYSURF):
        # lives
        self.utility.draw_text(DISPLAYSURF, "Score: " + str(self.score), 25,
                               35, 390, "black", "white")

    def move(self, DISPLAYSURF, x):
        pygame.draw.rect(DISPLAYSURF, self.utility.getColor("white"),
                         self.rect)
        if x > 0 and self.rect.x + x <= self.utility.getScreenWidth() - 80:
            self.rect.x = self.rect.x + x
        elif x < 0 and self.rect.x + x >= 0.0:
            self.rect.x = self.rect.x + x

        self.draw(DISPLAYSURF)

    def get_coordinate(self):
        self.coordinate.setCoordinates(self.rect.x, self.rect.y)
        return self.coordinate

    def get_width(self):
        return self.rect.width

    def get_height(self):
        return self.rect.height

    def reduceLives(self):
        self.lives -= 1

    def getLives(self):
        return self.lives

    def updateScore(self, points):
        self.score = self.score + points