예제 #1
0
파일: game_scene.py 프로젝트: tcreeds/PyCut
    def createToppingOptionsWithFractions(self):
        """
        Create the ui for the fractions options
        """

        X = 590
        Y = 620
        K = 4
        height = 50
        textOffset = 6

        toppings = ["Cheese", "Pepperoni", "Mushroom", "Pineapple"]
        for i in range(0, len(toppings)):
            text = Text(self.context, toppings[i])
            text.setPen(self.context.font)
            text.setColor((0, 0, 0))
            text.setLocation(X, 620 + i * height + textOffset)
            self.texts.append(text)

        X = X + 130

        increaseCallbacks = [
            self.increaseCheeseTopping, self.increaseMushroomTopping,
            self.increasePepperoniTopping, self.increasePineappleTopping
        ]
        decreaseCallbacks = [
            self.decreaseCheeseTopping, self.decreaseMushroomTopping,
            self.decreasePepperoniTopping, self.decreasePineappleTopping
        ]

        self.fractionTexts = []

        for i in range(0, 4):
            leftButton = Button(self.context, "<")
            leftButton.setBackgroundImg(self.context.button_bg, STATE.NORMAL)
            leftButton.setBackgroundImg(self.context.button_bg_active,
                                        STATE.ACTIVE)
            leftButton.setOnLeftClick(decreaseCallbacks[i])
            leftButton.setLocation(X + K * 3, Y + height * i)
            leftButton.width = 30
            leftButton.dirty = True

            fracText = Text(self.context, "0")
            fracText.centered = True
            fracText.setLocation(
                leftButton.location[0] + leftButton.width + 35,
                Y + textOffset + height * i)
            rightButton = Button(self.context, ">")
            rightButton.setBackgroundImg(self.context.button_bg, STATE.NORMAL)
            rightButton.setBackgroundImg(self.context.button_bg_active,
                                         STATE.ACTIVE)
            rightButton.setOnLeftClick(increaseCallbacks[i])
            rightButton.setLocation(leftButton.location[0] + 100,
                                    Y + height * i)
            rightButton.width = 30
            rightButton.dirty = True

            self.fractionTexts += [fracText]
            self.buttons += [leftButton, rightButton]
예제 #2
0
 def __init__(self, context):
     SceneBase.__init__(self, context)
     self.level = self.context.level
     self.game_over = False
     self.leveling_up = False
     self.buttons = []
     self.bad_pizzas = []
     self.good_pizzas = []
     self.game_toppings = self.context.game_toppings
     self.characters = self.context.game_characters
     self.current_pizza = None
     self.createGameMenu()
     self.createMessageBubble()
     self.buildPizzas()
     self.createToppingOptions()
     self.pizza_count_msg = Text(self.context,
                                 "{} Pizzas left".format(len(self.pizzas)))
     self.pizza_count_msg.setPen(self.context.font)
     self.pizza_count_msg.setColor((0, 0, 0))
     self.pizza_count_msg.setLocation(350, 675)
     self.game_over_msg = Text(self.context, "Game Over!!!")
     self.game_over_msg.setPen(self.context.bold_font_large)
     self.game_over_msg.setColor((255, 140, 0))
     self.game_over_msg.setLocation(
         (self.screen.get_width() / 2) - (self.restart_button.width / 2),
         300)
     self.level_up_msg = Text(self.context, "New Level reached")
     self.level_up_msg.setPen(self.context.bold_font_large)
     self.level_up_msg.setColor((255, 140, 0))
     self.level_up_msg.setLocation(
         (self.screen.get_width() / 2) - (self.restart_button.width / 2),
         300)
     self.continue_button = Button(self.context, "continue")
     self.continue_button.setBackgroundImg(self.context.button_bg,
                                           STATE.NORMAL)
     self.continue_button.setBackgroundImg(self.context.button_bg_active,
                                           STATE.ACTIVE)
     self.continue_button.setOnLeftClick(self.handleContinueButtonClick)
     self.continue_button.setLocation(
         (self.screen.get_width() / 2) - (self.continue_button.width / 2),
         (self.screen.get_height() / 2) - (self.continue_button.height / 2))
     self.createTrashCan()
     self.addCookingButton()
     self.generateCurrentPizzaRequirements()
     self.count = 0  #for debugging
예제 #3
0
    def createTitle(self):
        """
        Create the title for this page
        """

        self.title = Text(self.context, "Choose Difficulty")
        self.title.setColor((244, 101, 36))
        self.title.setPen(self.context.bold_font_large)
        self.title.centered = True
        self.title.setLocation( self.context.width / 2, 300)
예제 #4
0
파일: game_scene.py 프로젝트: tcreeds/PyCut
    def createGameMenu(self):
        """
        Create the in-game menu
        """

        P, K, Y = 300, 5, 30
        currX = P
        self.quit_button = Button(self.context, "Quit")
        self.quit_button.setPen(self.context.font)
        self.quit_button.setColor((255, 255, 255))
        self.quit_button.setBackgroundImg(self.context.button_bg, STATE.NORMAL)
        self.quit_button.setBackgroundImg(self.context.button_bg_active,
                                          STATE.ACTIVE)
        self.quit_button.setOnLeftClick(self.handleQuitButtonClick)
        self.quit_button.setOnHover(self.handleQuitButtonHover)
        self.quit_button.setLocation(P, Y)
        currX += self.quit_button.width
        self.restart_button = Button(self.context, "Restart")
        self.restart_button.setPen(self.context.font)
        self.restart_button.setColor((255, 255, 255))
        self.restart_button.setBackgroundImg(self.context.button_bg,
                                             STATE.NORMAL)
        self.restart_button.setBackgroundImg(self.context.button_bg_active,
                                             STATE.ACTIVE)
        self.restart_button.setOnLeftClick(self.handleRestartButtonClick)
        self.restart_button.setLocation(currX + K, Y)
        currX += self.restart_button.width + K
        self.home_button = Button(self.context, "Menu/Home")
        self.home_button.setPen(self.context.font)
        self.home_button.setColor((255, 255, 255))
        self.home_button.setBackgroundImg(self.context.button_bg, STATE.NORMAL)
        self.home_button.setBackgroundImg(self.context.button_bg_active,
                                          STATE.ACTIVE)
        self.home_button.setOnLeftClick(self.handleHomeButtonClick)
        self.home_button.setLocation(currX + K, Y)
        currX += self.home_button.width + K
        self.levelDisplay = Text(self.context, "Level: {}".format(self.level))
        self.levelDisplay.setPen(self.context.bold_font)
        self.levelDisplay.setLocation(currX + K, Y + 5)
        self.levelDisplay.setColor((0, 0, 0))
        self.buttons += [
            self.quit_button, self.restart_button, self.home_button,
            self.levelDisplay
        ]
예제 #5
0
 def createTitle(self):
     self.title = Text(self.context, self.context.title)
     self.title.setPen(self.context.font_large)
     self.title.setLocation((self.context.width - self.title.width) // 2,
                            (self.context.height - self.title.height) // 2)
예제 #6
0
 def createDifficultyText(self):
     self.difficulty_msg = Text(self.context, "Current Difficulty: " + self.context.difficulty)
     self.difficulty_msg.setPen(self.context.bold_font)
     self.difficulty_msg.setColor((244, 101, 36))
     self.difficulty_msg.setLocation((self.context.width - self.difficulty_msg.width) // 2,
                                 ((self.context.height - self.difficulty_msg.height) // 2) + self.title.height + self.start_button.height + self.help_button.height + self.difficulty_button.height + self.score_msg.height + 15)
예제 #7
0
 def createScoreText(self):
     self.score_msg = Text(self.context, "Experience: {} Pizzas".format(self.context.total_good_pizza))
     self.score_msg.setPen(self.context.bold_font)
     self.score_msg.setColor((244, 101, 36))
     self.score_msg.setLocation((self.context.width - self.score_msg.width) // 2,
                                 ((self.context.height - self.score_msg.height) // 2) + self.title.height + self.start_button.height + self.help_button.height + self.difficulty_button.height+ 15)
예제 #8
0
 def createTitle(self):
     self.title = Text(self.context, self.context.title)
     self.title.setColor((244, 101, 36))
     self.title.setPen(self.context.bold_font_large)
     self.title.centered = True
     self.title.setLocation( self.context.width / 2, 300 )
예제 #9
0
파일: game_scene.py 프로젝트: tcreeds/PyCut
    def __init__(self, context):
        SceneBase.__init__(self, context)
        #self.c = cProfile.Profile()
        #self.c.enable()
        self.override_render = True
        self.level = self.context.level
        self.game_over = False
        self.leveling_up = False
        self.context.fractions = [0, 0.25, 0.5, 0.75, 1]
        self.context.fractionStrings = ["0", "1/4", "1/2", "3/4", "1"]
        self.buttons = []
        self.bad_pizzas = []
        self.good_pizzas = []
        self.texts = []
        self.game_toppings = self.context.game_toppings
        self.characters = []
        for character in self.context.game_characters:
            if self.context.difficulty == "Advanced":
                self.characters.append(
                    pygame.transform.scale(character,
                                           (character.get_width() / 2,
                                            character.get_height() / 2)))
            else:
                self.characters.append(character)
        self.current_pizza = None

        self.createGameMenu()
        self.buildPizzas()
        if self.context.difficulty == "Easy":
            self.createToppingOptions()
            self.num_customers = 1
            self.createMessageBubble()
        else:
            self.createToppingOptionsWithFractions()
            self.num_customers = 4
            self.createMessageBubbles(self.num_customers)

        self.pizza_count_msg = Text(self.context,
                                    "{} Pizzas left".format(len(self.pizzas)))
        self.pizza_count_msg.setPen(self.context.font)
        self.pizza_count_msg.setColor((0, 0, 0))
        self.pizza_count_msg.setLocation(350, 675)

        self.game_over_msg = Text(self.context, "Game Over!!!")
        self.game_over_msg.centered = True
        self.game_over_msg.setPen(self.context.bold_font_large)
        self.game_over_msg.setColor((255, 140, 0))
        self.game_over_msg.setLocation(self.context.width / 2, 300)

        self.level_up_msg = Text(self.context, "New Level reached")
        self.level_up_msg.centered = True
        self.level_up_msg.setPen(self.context.bold_font_large)
        self.level_up_msg.setColor((255, 140, 0))
        self.level_up_msg.setLocation(self.context.width / 2, 300)

        self.continue_button = Button(self.context, "continue")
        self.continue_button.setBackgroundImg(self.context.button_bg,
                                              STATE.NORMAL)
        self.continue_button.setBackgroundImg(self.context.button_bg_active,
                                              STATE.ACTIVE)
        self.continue_button.setOnLeftClick(self.handleContinueButtonClick)
        self.continue_button.setLocation(
            (self.screen.get_width() / 2) - (self.continue_button.width / 2),
            (self.screen.get_height() / 2) - (self.continue_button.height / 2))

        self.createTrashCan()
        self.addCookingButton()
        self.generateCurrentPizzaRequirements()
        self.count = 0  #for debugging

        self.static_surface = pygame.Surface(
            (self.context.width, self.context.height), pygame.SRCALPHA)

        # The game scene is just a blank blue screen
        self.static_surface.fill((244, 101, 36))
        self.static_surface.blit(self.context.shop_background, (0, 0))
        if self.context.difficulty == "Advanced":
            self.static_surface.blit(self.characters[0], (150, 255))
            self.static_surface.blit(self.characters[1], (594, 255))
            self.static_surface.blit(self.characters[2], (150, 380))
            self.static_surface.blit(self.characters[3], (594, 380))
        else:
            self.static_surface.blit(
                self.characters[self.level % len(self.characters)], (850, 255))
        self.static_surface.blit(self.context.counter_top, (0, 0))

        pygame.display.flip()