def drawAdditionalContent(self, data, appendButtons=[]): self.allSprites = [] text = Text(text="Player %s Win!" % (data + 1), fontSize=50, alignment=CENTER_MIDDLE, location=(self.pageSize[POS_X]/2, self.pageSize[POS_Y]/4), basePoint=self.popUpPageBasePoint) self.allSprites.append(text) for appendButton in appendButtons: buttonSprite = Button(appendButton["func"], buttonSize=(150, 40), text=appendButton["name"], fontSize=30, location=(self.pageSize[POS_X] if appendButton["location"][POS_X] == PARENT_SIZE_WIDTH else appendButton["location"][POS_X], self.pageSize[POS_Y] if appendButton["location"][POS_Y] == PARENT_SIZE_HEIGHT else appendButton["location"][POS_Y]), alignment=appendButton["alignment"], basePoint=self.popUpPageBasePoint) buttonSprite.listen(appendButton["listener"]) self.allSprites.append(buttonSprite)
def process(self): # Load Image slitherPosterImg = utility.loadImage("2017_slither_poster") slitherPosterImg = utility.resizeImage(slitherPosterImg, (800, 600)) slitherPosterRect = slitherPosterImg.get_rect() slitherPosterRect.center = SCREEN_MID # Load Sound introBMG = utility.loadSound("BGM") introBMG.set_volume(0.3) # event mEventDistributor = pygameEventDistributor(GAME_INTRO_LISTENING_EVENT) mEventDistributor.listen( Request("GameIntro_quit", self._quit, addtionalTarget=pygame.QUIT)) mTickEventHandler = tickEventHandler.TickEventHandler( mEventDistributor) # button settings buttonSize = (150, 40) fontSize = 30 padding_x = 150 padding_y = 150 # make button player1Btn = Button(self.returnP1HS, text="1 player", alignment=BOTTOM_LEFT, location=(0 + padding_x, SCREEN_HEIGHT - padding_y), buttonSize=buttonSize, fontSize=fontSize) player1Btn.listen(mTickEventHandler) player2Btn = Button(self.returnP2C, text="2 players", alignment=BOTTOM_RIGHT, location=(SCREEN_WIDTH - padding_x, SCREEN_HEIGHT - padding_y), buttonSize=buttonSize, fontSize=fontSize) player2Btn.listen(mTickEventHandler) quitBtn = Button(self._quit, text="quit", alignment=BOTTOM_MIDDLE, location=(SCREEN_WIDTH / 2, SCREEN_HEIGHT), buttonSize=buttonSize, fontSize=fontSize, backgroundColor=RED) quitBtn.listen(mTickEventHandler) # make text title = Text(color=BLUE, text="Slither Game by Enjoeyland", fontSize=40, location=(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4), alignment=TOP_MIDDLE) # merge(make intro page) groupIntro = pygame.sprite.Group() groupIntro.add(player1Btn) groupIntro.add(player2Btn) groupIntro.add(quitBtn) groupIntro.add(title) utility.playSound(introBMG, loops=PLAY_INFINITELY) while self.__changedGameState == None: mEventDistributor.distribute() self.screen.fill(SCREEN_BACKGROUND) self.screen.blit(slitherPosterImg, (0, 0)) groupIntro.update() groupIntro.draw(self.screen) pygame.display.update() pygame.time.Clock().tick(10) introBMG.fadeout(2) return self.__changedGameState