def update(self, level):
     if self.resolution != Options.getOption("RESOLUTION"):
         self.resolution = Options.getOption("RESOLUTION")
     self.fades.update()
     self.updateCamera(level.player)
     self.updateSpriteList()
     self.updateBg(level)
    def __init__(self, screen):
        self.screen = screen

        self.gridFont = RessourceLoader.load_font('courier_new.ttf', 15)

        self.fades = self.Fades(self.screen)

        self.resolution = Options.getOption("RESOLUTION")
Beispiel #3
0
    def __init__(self):
        self.dialogManager = self.DialogManager()
        self.schriftart = RessourceLoader.load_font("courier_new.ttf", 15)
        self.bar = pygame.Surface((Options.getOption("RESOLUTION")[0], 17))
        self.bar.fill((130, 130, 130))

        self.score = 0
        self.fps = 0
        self.playLife = 0
Beispiel #4
0
    def handleInput(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.stateManager.endGame()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.stateManager.endGame()

                elif event.key == pygame.K_SPACE:
                    if not self.levelManager.curLevel.cutSceneState:
                        self.levelManager.curLevel.player.jump()
                elif event.key == pygame.K_LEFT:
                    if not self.levelManager.curLevel.cutSceneState:
                        self.levelManager.curLevel.player.walkLeft()
                elif event.key == pygame.K_RIGHT:
                    if not self.levelManager.curLevel.cutSceneState:
                        self.levelManager.curLevel.player.walkRight()
                elif event.key == pygame.K_p:
                    Event().raiseCstmEvent(
                        Event.SWITCHSTATE,
                        argDict={"state": StateManager.PAUSESTATE})
                elif event.key == pygame.K_m:
                    Event().raiseCstmEvent(
                        Event.SWITCHSTATE,
                        argDict={"state": StateManager.MENUSTATE})

            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT:
                    if not self.levelManager.curLevel.cutSceneState:
                        self.levelManager.curLevel.player.walkStop(dir=-1)
                elif event.key == pygame.K_RIGHT:
                    if not self.levelManager.curLevel.cutSceneState:
                        self.levelManager.curLevel.player.walkStop(dir=1)

            elif event.type == pygame.MOUSEBUTTONDOWN:
                if Options.getOption("ISDEBUG"):
                    print "The current cursor position is: ", Vector(
                        event.pos[0],
                        event.pos[1]) + self.gameRenderer.getCamera()

            #custom events:
            elif event.type == Event().ACTIVATETRIGGER:
                self.levelManager.curLevel.triggerManager.addTrigger(
                    event.tObject)
            elif event.type == Event().NEWDIALOG:
                self.interface.dialogManager.addDialog(event.msg, self)
            elif event.type == Event().LEVELFINISHED:
                self.levelManager.curLevel.setFinished()
            elif event.type == Event().SWITCHSTATE:
                self.stateManager.switchState(event.state)

        #Trigger input:
        if self.levelManager.curLevel.triggerManager.isNewEvents():
            self.levelManager.curLevel.triggerManager.next().action()
Beispiel #5
0
 def render(self, screen):
     screen.blit(self.bar, (0, 0))
     screen.blit(
         self.schriftart.render('Score:' + str(self.score), 1, [0, 0, 0]),
         (0 + 20, 0))
     screen.blit(
         self.schriftart.render('Life:' + str(self.playLife), 1, [0, 0, 0]),
         (0 + 120, 0))
     screen.blit(
         self.schriftart.render('FPS:' + str(round(self.fps, 2)), 1,
                                [0, 0, 0]),
         (Options.getOption("RESOLUTION")[0] - 100, 0))
    def renderBg(self, map):
        self.screen.fill((0, 0, 0))
        for bgLayer in map.bgLayers.values():

            # offset left
            self.screen.blit(bgLayer.getGraphic(),
                             (0, (Options.getOption("RESOLUTION")[1] -
                                  bgLayer.getDimensions()[1])),
                             area=pygame.Rect(
                                 bgLayer.getDimensions()[0] -
                                 bgLayer.getScrollPosition()[0], 0,
                                 bgLayer.getDimensions()[0],
                                 bgLayer.getDimensions()[1]))

            for i in range(bgLayer.getNeededGraphics() + 2):
                self.screen.blit(bgLayer.getGraphic(),
                                 (bgLayer.getScrollPosition()[0] +
                                  i * bgLayer.getDimensions()[0],
                                  (Options.getOption("RESOLUTION")[1] -
                                   bgLayer.getDimensions()[1])),
                                 area=pygame.Rect(0, 0,
                                                  bgLayer.getDimensions()[0],
                                                  bgLayer.getDimensions()[1]))
Beispiel #7
0
    def __init__(self):
        '''

        @param resolution: screen resolution
        '''
        Options.options = {
            "RESOLUTION": Options.resolutionList[1],
            "ISFULLSCR": False,
            "ISDEBUG": False,
            "VOLUME": Options.volumeList[5]
        }

        pygame.display.set_caption("The Adventures of Flip")
        pygame.display.set_icon(
            pygame.image.load(
                os.path.join(RessourceLoader.basepath, "data", "icon.png")))
        pygame.mouse.set_visible(False)

        if Options().getOption("ISFULLSCR"):
            self.screen = pygame.display.set_mode(
                Options.getOption("RESOLUTION"), pygame.FULLSCREEN)
        else:
            self.screen = pygame.display.set_mode(
                Options.getOption("RESOLUTION"))

        self.stateList = []
        self.stateList.append(GameState(self))
        self.stateList.append(MenuState(self))
        self.stateList.append(PauseState(self))

        self.switchState(self.MENUSTATE)

        self.run = True

        self.clock = pygame.time.Clock()

        intro.Opening().play()
Beispiel #8
0
    def render(self):
        #TODO: maybe move other another place
        if self.interface.dialogManager.isNewDialog():
            self.interface.dialogManager.next().execute()

        self.gameRenderer.renderBg(self.levelManager.curLevel.map)
        self.gameRenderer.renderMapLayer(0, self.levelManager.curLevel.map)
        self.gameRenderer.renderMapLayer(1, self.levelManager.curLevel.map)
        self.gameRenderer.renderSprites()
        self.gameRenderer.renderMapLayer(2, self.levelManager.curLevel.map)
        if Options.getOption("ISDEBUG"):
            self.gameRenderer.renderGrid(self.levelManager.curLevel.map)
            self.gameRenderer.renderBoundingBoxes(
                self.physicManager.colShapeList)
        self.gameRenderer.renderInterface(self.interface)

        if self.levelManager.curLevel.cutSceneState:
            self.gameRenderer.renderBlackBars()
 def update(self):
     if self.resolution != Options.getOption("RESOLUTION"):
         self.resolution = Options.getOption("RESOLUTION")
 def calcItemsPerPage(self, menu):
     return (Options.getOption("RESOLUTION")[1] - 150) // 50
        def __init__(self, screen):
            self.screen = screen

            self.resolution = Options.getOption("RESOLUTION")
Beispiel #12
0
    def handleInput(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.stateManager.endGame()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.stateManager.endGame()
                elif event.key == pygame.K_UP:
                    self.menuManager.curMenu.moveUp()
                elif event.key == pygame.K_DOWN:
                    self.menuManager.curMenu.moveDown()
                elif event.key == pygame.K_RETURN:
                    self.menuManager.curMenu.execute()

                elif event.key == pygame.K_m:
                    # only change if there is a level loaded
                    if self.stateManager.stateList[
                            StateManager.
                            GAMESTATE].levelManager.curLevel != None:
                        Event().raiseCstmEvent(
                            Event.SWITCHSTATE,
                            argDict={"state": StateManager.GAMESTATE})
            #custom events
            elif event.type == Event().NEWGAME:
                self.stateManager.switchState(self.stateManager.GAMESTATE)
                gameState = self.stateManager.getGameState()
                gameState.levelManager.loadLevel(
                    gameState.levelManager.FIRSTLEVEL)
            elif event.type == Event().SWITCHMENU:
                self.menuManager.loadMenu(event.mIndex)
            elif event.type == Event().SWITCHSTATE:
                self.stateManager.switchState(event.state)
            elif event.type == Event().SWITCHLEVEL:
                self.stateManager.getGameState().levelManager.loadLevel(
                    event.levelIndex)
                Event().raiseCstmEvent(Event().SWITCHSTATE, {"state": 0})
            elif event.type == Event().OPTIONSWITCH:
                itemChanged = False
                if event.option == "ISFULLSCR" or event.option == "ISDEBUG" or event.option == "ISSOUND":
                    if Options.getOption(event.option) == False:
                        Options.setOption(event.option, True)
                        itemChanged = True
                    elif Options.getOption(event.option) == True:
                        Options.setOption(event.option, False)
                        itemChanged = True
                elif event.option == "VOLUME" or event.option == "RESOLUTION":
                    list = []
                    if event.option == "VOLUME": list = Options.volumeList
                    elif event.option == "RESOLUTION":
                        list = Options.resolutionList
                    valFound = False
                    for i in range(0, len(list) - 1):
                        if list[i] == Options.getOption(event.option):
                            valFound = True
                            Options.setOption(event.option,
                                              list[i + 1 % len(list)])
                            itemChanged = True
                            break
                    if not valFound:
                        Options.setOption(event.option, list[0])
                        itemChanged = True

                if itemChanged:
                    if event.option == "ISFULLSCR" or event.option == "RESOLUTION":
                        if Options.getOption("ISFULLSCR"):
                            self.screen = pygame.display.set_mode(
                                Options.getOption("RESOLUTION"),
                                pygame.FULLSCREEN)
                        else:
                            self.screen = pygame.display.set_mode(
                                Options.getOption("RESOLUTION"))
                    elif event.option == "VOLUME":
                        SoundManager.updateVolumes()
Beispiel #13
0
 def _calcGraphicCount(self):
     self.neededGraphics = Options.getOption(
         "RESOLUTION")[0] // self.getDimensions()[0]
 def jump(self):
     if not self.jumplock:
         if Options.getOption("RESOLUTION"): self.jumpSound.play()
         self.jumplock = True
         self.velocity += self.jumpspeed
Beispiel #15
0
 def getCaption(self):
     return self.caption + str(Options.getOption(self.eventArgs["option"]))
Beispiel #16
0
 def updateVolumes(SoundManager):
     for sound in SoundManager.sounds:
         print sound
         SoundManager.setVolSound(sound, Options.getOption("VOLUME"))