class canvasTest(Scene): def __init__(self, *args): super(canvasTest, self).__init__(*args) # self.can = canvas(color(0, 0, 0), vec2(800, 600)) # self.brush = brush(self.can, (255, 255, 255, 0.5), 1) # self.painter = Painter(self.can.surface()) self.blend = pygame.Surface((300, 300)).convert() self.blend.fill((255, 255, 255)) self.blend.set_alpha(80) self.sceneCanvas = pygame.Surface((self.width, self.height)) self.sceneCanvas.fill((255, 255, 255)) self.sceneCanvas.set_alpha(100) self.__E_FPS = TextElement(pygame.Rect(self.width - 80, 0, 80, 20), 'FPS:', gl_Font, 18, (0, 255, 0), 1) def draw(self): # self.can.fill(color(0, 0, 0)) # self.brush.drawLine((0, 0), (700, 500)) # self.painter.Lines([point2(), point2(500, 700)], (255, 255, 255, 100), 1, 0) # # self.__E_FPS.draw(self.can.surface()) # self.screen.blit(self.can.surface(), (0, 0)) self.screen.blit(self.blend, (0, 0)) self.screen.blit(self.sceneCanvas, (0, 0)) self.__E_FPS.draw(self.screen) def doClockEvent(self, NowClock): fps = 'FPS:' + str(self.FPS) self.__E_FPS.setText(fps)
def __init__(self, screen, config, time): super(AstartTest, self).__init__(screen, config, time) self.cols, self.rows = 100, 100 self.grid = [] self.openSet, self.closeSet = [], [] self.start, self.end = None, None self.w, self.h = screen.get_width() / self.cols, screen.get_height( ) / self.rows self.path = [] self.done = False self.noSolution = False self.points = [] self.__E_TEXT = TextElement( pygame.Rect(centeredXPos(self.width, 220), 260, 220, 60), '', gl_Font, 50, (255, 255, 0), 1) for i in range(0, self.cols): self.grid.append([]) for i in range(0, self.cols): for j in range(0, self.rows): self.grid[i].append(Spot(i, j)) for i in range(0, self.cols): for j in range(0, self.rows): self.grid[i][j].addNeighbors(self.cols, self.rows, self.grid) self.start = self.grid[0][0] self.end = self.grid[self.cols - 1][self.rows - 1] self.start.wall = False self.end.wall = False self.openSet.append(self.start)
def __init__(self, screen, config, startClock): super(RobotRunScene, self).__init__(screen, config, startClock) self.w, self.h = self.screen.get_width(), self.screen.get_height() self.__As_MAP = AStarArea(Rectangle(0, 0, 800, 600), 80, 60) self.caption = 'Actor与A*结合测试场景' self.__containers = [] for i in range(0, 6): x = int(random.randint(100, self.w - 150) / 10) * 10 y = int(random.randint(100, self.h - 150) / 10) * 10 w = int(random.randint(50, 150) / 10) * 10 h = int(random.randint(50, 150) / 10) * 10 self.__containers.append(Container(Rectangle(x, y, w, h))) _x, _y = int(x / self.__As_MAP.unit_w), int(y / self.__As_MAP.unit_h) _w, _h = int(w / self.__As_MAP.unit_w), int(h / self.__As_MAP.unit_h) self.__As_MAP.addObstacleArea(_x, _w, _y, _h) self.__A_Robot = RobotActor(Rectangle(0, 0, 100, 100)) self.__E_Msg = TextElement((600, 0, 200, 60), 'Robotlocal:(0, 0)\nMouselocal:(0, 0)', gl_Font, 12, (255, 255, 255), 1) self.__E_Msg2 = TextElement((600, 40, 200, 600), 'Astart:\n', gl_Font, 10, (255, 255, 255), 1) self.__pathList = [] self.__normalLis = [] self.__build_As_Map() self.__i = 0 self.__end = (0, 0)
def __init__(self, screen, config, startClock): super(testSpriteScene, self).__init__(screen, config, startClock) self.img = pygame.Surface((5, 5)).convert() self.img.fill((255, 255, 255)) self.sprintsGroup1 = SpriteGroup(RectangleRange(0, 0, 800, 600)) self.__E_FPS = TextElement(pygame.Rect(self.width - 80, 0, 80, 20), 'FPS:', gl_Font, 18, (0, 255, 0), 1) for i in range(0, 1000): x, y = random.randint(0, 800), random.randint(0, 600) self.sprintsGroup1.add(CubeSprite(self.img, pygame.Rect(x, y, 5, 5)))
def __init__(self, *args): super(canvasTest, self).__init__(*args) # self.can = canvas(color(0, 0, 0), vec2(800, 600)) # self.brush = brush(self.can, (255, 255, 255, 0.5), 1) # self.painter = Painter(self.can.surface()) self.blend = pygame.Surface((300, 300)).convert() self.blend.fill((255, 255, 255)) self.blend.set_alpha(80) self.sceneCanvas = pygame.Surface((self.width, self.height)) self.sceneCanvas.fill((255, 255, 255)) self.sceneCanvas.set_alpha(100) self.__E_FPS = TextElement(pygame.Rect(self.width - 80, 0, 80, 20), 'FPS:', gl_Font, 18, (0, 255, 0), 1)
def createTextElement(self, text="TextElement", pos=(0, 0), size=18, length=None, color=(255, 255, 255), font=gl_Font, zIndex=999): """ :param text: :param pos: 可以是int型数字代码, 0,上居中 :param size: :param length: :param color: :param font: :param zIndex: :return: """ if length is None: length = len(text) * size _top, _left = 0, self.nextElementY if isinstance(pos, tuple) or isinstance(pos, list): _top, _left = pos[0], self.nextElementY + pos[1] elif isinstance(pos, vec2): _top, _left = pos.x, self.nextElementY + pos.y elif isinstance(pos, int): _top, _left = self.__getPos(pos, length, size) e = TextElement((_top, _left, length * size + 2, size + 2), text, font, size, color, 1) e.zIndex = zIndex self.__CreatedElementList.append(e) self.__render.open() self.__render.add(e) self.__render.close() self.nextElementY += size + 4 self.id += 1 return e
class testSpriteScene(Scene): def __init__(self, screen, config, startClock): super(testSpriteScene, self).__init__(screen, config, startClock) self.img = pygame.Surface((5, 5)).convert() self.img.fill((255, 255, 255)) self.sprintsGroup1 = SpriteGroup(RectangleRange(0, 0, 800, 600)) self.__E_FPS = TextElement(pygame.Rect(self.width - 80, 0, 80, 20), 'FPS:', gl_Font, 18, (0, 255, 0), 1) for i in range(0, 1000): x, y = random.randint(0, 800), random.randint(0, 600) self.sprintsGroup1.add(CubeSprite(self.img, pygame.Rect(x, y, 5, 5))) def draw(self): _dict = self.sprintsGroup1.getCollideDict() for w in _dict.keys(): w.highLight = True self.sprintsGroup1.draw(self.screen) self.sprintsGroup1.update() self.__E_FPS.draw(self.screen) def doClockEvent(self, NowClock): fps = 'FPS:' + str(self.FPS) self.__E_FPS.setText(fps)
def __buildList(self): fs = [] import os for root, dirs, files in os.walk(RECORDFILE_SAVE_PATH): fs += files for name in fs: if name.find(RECORDFILE_SAVE_NAMEHEAD) == 0 and name.find(RECORDFILE_SAVE_EXN) > 0: n = name.replace(RECORDFILE_SAVE_EXN, '') dataList = RecordFile(RECORDFILE_SAVE_PATH, n).getList() if dataList is not None: self.__ElementsList.append( SaveDataElement((83, 30, 636, 114), gl_UIPath + self.__res_n_OPT, 255, dataList)) if len(self.__ElementsList) == 0: self.__ElementsList.append( (TextElement((centeredXPos(800, 220), centeredXPos(600, 35), 220, 35), '未找到游戏记录', gl_Font_oth, 30, (255, 255, 255, 255), self.config.getTextAntiAlias())))
class AstartTest(Scene): def __init__(self, screen, config, time): super(AstartTest, self).__init__(screen, config, time) self.cols, self.rows = 100, 100 self.grid = [] self.openSet, self.closeSet = [], [] self.start, self.end = None, None self.w, self.h = screen.get_width() / self.cols, screen.get_height( ) / self.rows self.path = [] self.done = False self.noSolution = False self.points = [] self.__E_TEXT = TextElement( pygame.Rect(centeredXPos(self.width, 220), 260, 220, 60), '', gl_Font, 50, (255, 255, 0), 1) for i in range(0, self.cols): self.grid.append([]) for i in range(0, self.cols): for j in range(0, self.rows): self.grid[i].append(Spot(i, j)) for i in range(0, self.cols): for j in range(0, self.rows): self.grid[i][j].addNeighbors(self.cols, self.rows, self.grid) self.start = self.grid[0][0] self.end = self.grid[self.cols - 1][self.rows - 1] self.start.wall = False self.end.wall = False self.openSet.append(self.start) def draw(self): current = None if len(self.openSet) > 0: winner = 0 for i in range(0, len(self.openSet)): if self.openSet[i].f < self.openSet[winner].f: winner = i current = self.openSet[winner] if current == self.end: self.done = True if not self.done: self.openSet.remove(current) self.closeSet.append(current) neighbors = current.neighbors for i in range(0, len(neighbors)): neighbor = neighbors[i] if neighbor not in self.closeSet and not neighbor.wall: tempG = current.g + 1 newPath = False if neighbor in self.openSet: if tempG < neighbor.g: neighbor.g = tempG newPath = True else: neighbor.g = tempG newPath = True self.openSet.append(neighbor) if newPath: neighbor.h = heuristic(neighbor, self.end) neighbor.f = neighbor.g + neighbor.h neighbor.previous = current else: self.done = True self.__E_TEXT.setText('寻路失败') self.noSolution = True # self.screen.fill((255, 255, 255)) for i in range(0, self.cols): for j in range(0, self.rows): self.grid[i][j].show(self.screen, (255, 255, 255), self.w, self.h) for i in range(0, len(self.openSet)): self.openSet[i].show(self.screen, (0, 255, 0), self.w, self.h) for i in range(0, len(self.closeSet)): self.closeSet[i].show(self.screen, (255, 0, 0), self.w, self.h) if not self.done: self.path.clear() temp = current self.path.append(temp) while temp is not None and temp.previous: self.path.append(temp.previous) temp = temp.previous elif self.done and not self.noSolution: self.path.append(self.end) self.__E_TEXT.setText('寻路成功') for i in range(0, len(self.path)): e = self.path[i] if e is not None: e.show(self.screen, (0, 0, 255), self.w, self.h) self.__E_TEXT.draw(self.screen)
def __init__(self, *args): super(pickTest, self).__init__(*args) self.__flag_isEnter = False self.__alpha = 0 self.__flag_recordStartTime = False self.__start_time = 0 self.__now_time = 0 self.res_Img_BG_Name = 'OPT_BG.bmp' self.res_Sound_Choose_Name = 'OPT_C.wav' self.res_UI_RightButton = 'OPT_BR.png' self.res_UI_LeftButton = 'OPT_BL.png' self.__Clock = pygame.time.Clock() self.__KV_AA = {} self.__KV_WAVE = {} self.__ElementsMap = {} if self.config.getTextAntiAlias(): self.__KV_AA['key'] = '开' self.__KV_AA['val'] = '1' else: self.__KV_AA['key'] = '关' self.__KV_AA['val'] = '0' self.res_Sound_Choose = pygame.mixer.Sound(gl_SoundPath + self.res_Sound_Choose_Name) self.res_Sound_Choose.set_volume(self.config.getVolumeSound()) self.res_Img_BG = pygame.image.load(gl_ImgPath + self.res_Img_BG_Name) self.__E_BGBlankL1 = OptButtonElement((40, 60, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankL2 = OptButtonElement((40, 110, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankL3 = OptButtonElement((40, 160, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankLRet = OptButtonElement((50, 520, 80, 40), (255, 255, 255, 100)) self.__E_BGBlankLApply = OptButtonElement((150, 520, 80, 40), (255, 255, 255, 100)) self.__E_BGBlankR = TitleConstElement( (260, 60, 510, 500), blankSurface((510, 500), (255, 255, 255, 100))) self.__E_Text_Apply = TextElement( (centeredXPos(80, 40, 150), centeredYPos(40, 20, 520), 120, 20), '应用', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Apply.zIndex = 1 self.__E_Text_Ret = TextElement( (centeredXPos(80, 40, 50), centeredYPos(40, 20, 520), 120, 20), '返回', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Ret.zIndex = 1 self.__E_Text_Draw = TextElement( (centeredXPos(200, 80, 40), centeredYPos(40, 20, 60), 80, 20), '画面设置', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Draw.zIndex = 1 self.__E_Text_AntiAlias = TextElement((270, 70, 120, 20), '抗锯齿:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_AntiAlias.zIndex = 1 self.__E_Text_AA_Val = TextElement( (670, 70, 20, 20), self.__KV_AA['key'], gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_AA_Val.zIndex = 1 self.__E_UI_AA_RightButton = OptUIElement( (700, 70, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_AA_RightButton.zIndex = 1 self.__E_UI_AA_LeftButton = OptUIElement( (640, 70, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_AA_LeftButton.zIndex = 1 self.__E_Text_Wave = TextElement( (centeredXPos(200, 80, 40), centeredYPos(40, 20, 110), 80, 20), '声音设置', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Wave.zIndex = 1 self.__E_Text_BGMVolume = TextElement((270, 70, 120, 20), '音乐音量:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_BGMVolume.zIndex = 1 self.__E_Text_BGM_Val = TextElement((660, 70, 30, 20), str(self.config.VolumeBGM), gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_BGM_Val.zIndex = 1 self.__E_UI_BGM_RightButton = OptUIElement( (700, 70, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_BGM_RightButton.zIndex = 1 self.__E_UI_BGM_LeftButton = OptUIElement( (630, 70, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_BGM_LeftButton.zIndex = 1 self.__E_Text_SoundVolume = TextElement((270, 100, 120, 20), '音效音量:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_SoundVolume.zIndex = 1 self.__E_Text_Sou_Val = TextElement((660, 100, 30, 20), str(self.config.VolumeSound), gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Sou_Val.zIndex = 1 self.__E_UI_Sou_RightButton = OptUIElement( (700, 100, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_Sou_RightButton.zIndex = 1 self.__E_UI_Sou_LeftButton = OptUIElement( (630, 100, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_Sou_LeftButton.zIndex = 1 self.__E_Text_Licence = TextElement( (centeredXPos(200, 120, 40), centeredYPos(40, 20, 160), 120, 20), '开源软件许可', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Licence.zIndex = 1 self.__E_Img_Licence = ImgElement(self.__E_BGBlankR.area, gl_ImgPath + 'OPT_L.lice', 255, (128, 128, 128)) self.__E_Img_Licence.zIndex = 1 # 画面设置绑定事件 self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Draw, True), 1) self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([ self.__E_Text_AntiAlias, self.__E_Text_AA_Val, self. __E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ]), 2) self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Draw, False), 1) # 声音设置绑定事件 self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Wave, True), 1) self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([ self.__E_Text_BGMVolume, self.__E_Text_SoundVolume, self. __E_Text_BGM_Val, self.__E_Text_Sou_Val, self. __E_UI_BGM_RightButton, self.__E_UI_BGM_LeftButton, self. __E_UI_Sou_RightButton, self.__E_UI_Sou_LeftButton ]), 2) self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Wave, False), 1) # 开源软件许可按钮绑定事件 self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Licence, True), 1) self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([self.__E_Img_Licence]), 2) self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Licence, False), 1) # 应用按钮绑定事件 self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Apply, True), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Apply, False), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_OPT_APPLY), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__updConfig(), 2) # 返回按钮绑定事件 self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Ret, True), 1) self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Ret, False), 1) self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_TITLE), 1) # 抗锯齿UI按钮绑定事件 self.__E_UI_AA_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_AA_Txt(), 1) self.__E_UI_AA_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_AA_Txt(), 1) # 改变音量UI按钮绑定事件 self.__E_UI_BGM_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_BGM_Val, False, GLC_INI_PARAM_BGMVOLUME), 1) self.__E_UI_BGM_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_BGM_Val, True, GLC_INI_PARAM_BGMVOLUME), 1) self.__E_UI_Sou_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_Sou_Val, False, GLC_INI_PARAM_SOUNDVOLUME), 1) self.__E_UI_Sou_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_Sou_Val, True, GLC_INI_PARAM_SOUNDVOLUME), 1) self.__ElementsMap['Draw1'] = [ self.__E_BGBlankL1, self.__E_BGBlankL2, self.__E_BGBlankL3, self.__E_BGBlankR, self.__E_Text_Draw, self.__E_Text_Wave, self.__E_Text_Licence, self.__E_BGBlankLApply, self.__E_Text_Apply, self.__E_BGBlankLRet, self.__E_Text_Ret ] self.__ElementsMap['Draw2'] = [ self.__E_Text_AntiAlias, self.__E_Text_AA_Val, self.__E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ] self.__ElementsMap['Interact1'] = [ self.__E_BGBlankL1, self.__E_BGBlankL2, self.__E_BGBlankL3, self.__E_BGBlankLApply, self.__E_BGBlankLRet ] self.__ElementsMap['Interact2'] = [ self.__E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ] self.__ElementsMap[ 'Draw'] = self.__ElementsMap['Draw1'] + self.__ElementsMap['Draw2'] self.__ElementsMap['Interact'] = self.__ElementsMap[ 'Interact1'] + self.__ElementsMap['Interact2'] self.render.add(self.__ElementsMap['Draw1']) self.render.add(self.__ElementsMap['Interact']) self.render.close() # 设定渲染参数 self.__step = 4 self.__frameRate = self.config.getFrameRate() if self.__frameRate: self.__step = 255 / (1.5 * self.__frameRate)
class pickTest(Scene): def __init__(self, *args): super(pickTest, self).__init__(*args) self.__flag_isEnter = False self.__alpha = 0 self.__flag_recordStartTime = False self.__start_time = 0 self.__now_time = 0 self.res_Img_BG_Name = 'OPT_BG.bmp' self.res_Sound_Choose_Name = 'OPT_C.wav' self.res_UI_RightButton = 'OPT_BR.png' self.res_UI_LeftButton = 'OPT_BL.png' self.__Clock = pygame.time.Clock() self.__KV_AA = {} self.__KV_WAVE = {} self.__ElementsMap = {} if self.config.getTextAntiAlias(): self.__KV_AA['key'] = '开' self.__KV_AA['val'] = '1' else: self.__KV_AA['key'] = '关' self.__KV_AA['val'] = '0' self.res_Sound_Choose = pygame.mixer.Sound(gl_SoundPath + self.res_Sound_Choose_Name) self.res_Sound_Choose.set_volume(self.config.getVolumeSound()) self.res_Img_BG = pygame.image.load(gl_ImgPath + self.res_Img_BG_Name) self.__E_BGBlankL1 = OptButtonElement((40, 60, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankL2 = OptButtonElement((40, 110, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankL3 = OptButtonElement((40, 160, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankLRet = OptButtonElement((50, 520, 80, 40), (255, 255, 255, 100)) self.__E_BGBlankLApply = OptButtonElement((150, 520, 80, 40), (255, 255, 255, 100)) self.__E_BGBlankR = TitleConstElement( (260, 60, 510, 500), blankSurface((510, 500), (255, 255, 255, 100))) self.__E_Text_Apply = TextElement( (centeredXPos(80, 40, 150), centeredYPos(40, 20, 520), 120, 20), '应用', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Apply.zIndex = 1 self.__E_Text_Ret = TextElement( (centeredXPos(80, 40, 50), centeredYPos(40, 20, 520), 120, 20), '返回', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Ret.zIndex = 1 self.__E_Text_Draw = TextElement( (centeredXPos(200, 80, 40), centeredYPos(40, 20, 60), 80, 20), '画面设置', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Draw.zIndex = 1 self.__E_Text_AntiAlias = TextElement((270, 70, 120, 20), '抗锯齿:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_AntiAlias.zIndex = 1 self.__E_Text_AA_Val = TextElement( (670, 70, 20, 20), self.__KV_AA['key'], gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_AA_Val.zIndex = 1 self.__E_UI_AA_RightButton = OptUIElement( (700, 70, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_AA_RightButton.zIndex = 1 self.__E_UI_AA_LeftButton = OptUIElement( (640, 70, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_AA_LeftButton.zIndex = 1 self.__E_Text_Wave = TextElement( (centeredXPos(200, 80, 40), centeredYPos(40, 20, 110), 80, 20), '声音设置', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Wave.zIndex = 1 self.__E_Text_BGMVolume = TextElement((270, 70, 120, 20), '音乐音量:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_BGMVolume.zIndex = 1 self.__E_Text_BGM_Val = TextElement((660, 70, 30, 20), str(self.config.VolumeBGM), gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_BGM_Val.zIndex = 1 self.__E_UI_BGM_RightButton = OptUIElement( (700, 70, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_BGM_RightButton.zIndex = 1 self.__E_UI_BGM_LeftButton = OptUIElement( (630, 70, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_BGM_LeftButton.zIndex = 1 self.__E_Text_SoundVolume = TextElement((270, 100, 120, 20), '音效音量:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_SoundVolume.zIndex = 1 self.__E_Text_Sou_Val = TextElement((660, 100, 30, 20), str(self.config.VolumeSound), gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Sou_Val.zIndex = 1 self.__E_UI_Sou_RightButton = OptUIElement( (700, 100, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_Sou_RightButton.zIndex = 1 self.__E_UI_Sou_LeftButton = OptUIElement( (630, 100, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_Sou_LeftButton.zIndex = 1 self.__E_Text_Licence = TextElement( (centeredXPos(200, 120, 40), centeredYPos(40, 20, 160), 120, 20), '开源软件许可', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Licence.zIndex = 1 self.__E_Img_Licence = ImgElement(self.__E_BGBlankR.area, gl_ImgPath + 'OPT_L.lice', 255, (128, 128, 128)) self.__E_Img_Licence.zIndex = 1 # 画面设置绑定事件 self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Draw, True), 1) self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([ self.__E_Text_AntiAlias, self.__E_Text_AA_Val, self. __E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ]), 2) self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Draw, False), 1) # 声音设置绑定事件 self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Wave, True), 1) self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([ self.__E_Text_BGMVolume, self.__E_Text_SoundVolume, self. __E_Text_BGM_Val, self.__E_Text_Sou_Val, self. __E_UI_BGM_RightButton, self.__E_UI_BGM_LeftButton, self. __E_UI_Sou_RightButton, self.__E_UI_Sou_LeftButton ]), 2) self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Wave, False), 1) # 开源软件许可按钮绑定事件 self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Licence, True), 1) self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([self.__E_Img_Licence]), 2) self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Licence, False), 1) # 应用按钮绑定事件 self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Apply, True), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Apply, False), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_OPT_APPLY), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__updConfig(), 2) # 返回按钮绑定事件 self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Ret, True), 1) self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Ret, False), 1) self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_TITLE), 1) # 抗锯齿UI按钮绑定事件 self.__E_UI_AA_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_AA_Txt(), 1) self.__E_UI_AA_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_AA_Txt(), 1) # 改变音量UI按钮绑定事件 self.__E_UI_BGM_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_BGM_Val, False, GLC_INI_PARAM_BGMVOLUME), 1) self.__E_UI_BGM_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_BGM_Val, True, GLC_INI_PARAM_BGMVOLUME), 1) self.__E_UI_Sou_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_Sou_Val, False, GLC_INI_PARAM_SOUNDVOLUME), 1) self.__E_UI_Sou_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_Sou_Val, True, GLC_INI_PARAM_SOUNDVOLUME), 1) self.__ElementsMap['Draw1'] = [ self.__E_BGBlankL1, self.__E_BGBlankL2, self.__E_BGBlankL3, self.__E_BGBlankR, self.__E_Text_Draw, self.__E_Text_Wave, self.__E_Text_Licence, self.__E_BGBlankLApply, self.__E_Text_Apply, self.__E_BGBlankLRet, self.__E_Text_Ret ] self.__ElementsMap['Draw2'] = [ self.__E_Text_AntiAlias, self.__E_Text_AA_Val, self.__E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ] self.__ElementsMap['Interact1'] = [ self.__E_BGBlankL1, self.__E_BGBlankL2, self.__E_BGBlankL3, self.__E_BGBlankLApply, self.__E_BGBlankLRet ] self.__ElementsMap['Interact2'] = [ self.__E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ] self.__ElementsMap[ 'Draw'] = self.__ElementsMap['Draw1'] + self.__ElementsMap['Draw2'] self.__ElementsMap['Interact'] = self.__ElementsMap[ 'Interact1'] + self.__ElementsMap['Interact2'] self.render.add(self.__ElementsMap['Draw1']) self.render.add(self.__ElementsMap['Interact']) self.render.close() # 设定渲染参数 self.__step = 4 self.__frameRate = self.config.getFrameRate() if self.__frameRate: self.__step = 255 / (1.5 * self.__frameRate) # 替换ElementsList2的内容 def __rebuildElementsToList2(self, _list): if _list is None or len(_list) <= 0: return self.__ElementsMap['Draw2'] = _list self.__ElementsMap['Interact2'].clear() for e in _list: if e.Events.getSize() > 0: self.__ElementsMap['Interact2'].append(e) self.__ElementsMap[ 'Draw'] = self.__ElementsMap['Draw1'] + self.__ElementsMap['Draw2'] self.__ElementsMap['Interact'] = self.__ElementsMap[ 'Interact1'] + self.__ElementsMap['Interact2'] # 改变抗锯齿UI所对应的值 def __chVal_AA_Txt(self): if self.__KV_AA['val'] == '1': self.__KV_AA['key'] = '关' self.__KV_AA['val'] = '0' else: self.__KV_AA['key'] = '开' self.__KV_AA['val'] = '1' self.__E_Text_AA_Val.setText(self.__KV_AA['key']) # 改变Wave UI所对应的值 def __chVal_WaveParam_Txt(self, elem, add, para): valF = float(elem.Text) if add: valF += 0.5 if valF > 10: valF = 10.0 else: valF -= 0.5 if valF < 0: valF = 0.0 self.__KV_WAVE[para] = str(valF) elem.setText(self.__KV_WAVE[para]) # 序列化值更新设置文件 def __updConfig(self): updateINI(GLC_INI_NAME, GLC_INI_SECTION_DRAW, GLC_INI_PARAM_ANTIALIAS, self.__KV_AA['val']) for k, v in self.__KV_WAVE.items(): updateINI(GLC_INI_NAME, GLC_INI_SECTION_WAVE, k, v) # 传递信号 def __retSignalIsReadyToEnd(self, SceneNum): self.isReadyToEnd = True self.nextSceneNum = SceneNum def draw(self): blitAlpha(self.screen, self.res_Img_BG, (0, 0), self.__alpha) if not self.__flag_isEnter and not self.isReadyToEnd: self.__alpha += self.__step if self.__alpha >= 255: self.__alpha = 255 self.__flag_isEnter = True elif self.__flag_isEnter and not self.isReadyToEnd: self.__alpha = 255 self.render.render(self.screen) if self.isReadyToEnd: self.isEnd = True
def __init__(self, *args): # 注册场景 super().__init__(*args) self.useDefaultDraw = False from source.config.AppConfig import registerScene registerScene(SCENENUM_GAME_PROLOGUE, Title_PrologueScene) registerScene(SCENENUM_OPT, OptionScene) registerScene(SCENENUM_CONTINUE, Continue_Scene) self.alpha = 0 self.flag = False self.isMusicPlay = False self.wave_bgm = 'titleBackground.wav' self.titleBgName = 'titleBg.bmp' self.titleOptionName = 'titleOpts.bmp' self.titleName = 'titleTop.bmp' self.__res_s_cloud = 'T_S_C.png' self.__ast_name = 'I_T.assets' self.res_wave_bgm = pygame.mixer.Sound(gl_MusicPath + self.wave_bgm) self.res_wave_bgm.set_volume(self.config.getVolumeBGM()) self.bg = pygame.image.load(gl_ImgPath + self.titleBgName) self.res_optionNewGame = pygame.image.load(gl_ImgPath + self.titleOptionName) self.res_title = pygame.image.load(gl_ImgPath + self.titleName) self.__frameRate = self.config.getFrameRate() self.__expBoardText = AssetsFile(os.path.join(gl_AssetsPath, 'TitleScene')).decode( self.__ast_name, AssetsType.EXP) # 创建相应的Element self.__board = TitleConstElement((gl_WindowWidth - 380, gl_WindowHeight - 80, 380, 80), blankSurface((380, 180), (255, 255, 255, 100))) self.__title = TitleConstElement((0, 0, 465, 74), clipResImg(self.res_title, (0, 0, 465, 74), (0, 0, 0))) self.__text = TextElement((gl_WindowWidth - 380, gl_WindowHeight - 80, 380, 80), self.__expBoardText[0], gl_Font, 16, (0, 0, 0), self.config.getTextAntiAlias()) self.__optNewGame = TitleOptElement((140, 140, 116, 30), self.res_optionNewGame, (0, 0, 116, 30), (128, 128, 128)) self.__optContinue = TitleOptElement((125, 180, 116, 30), self.res_optionNewGame, (0, 116, 116, 30), (128, 128, 128)) self.__optOption = TitleOptElement((130, 220, 116, 30), self.res_optionNewGame, (0, 232, 116, 30), (128, 128, 128)) self.__optExit = TitleOptElement((135, 260, 61, 30), self.res_optionNewGame, (0, 348, 61, 30), (128, 128, 128)) self.__spriteCloud = ImgElement((801, -120, 750, 396), gl_ImgPath + self.__res_s_cloud) self.__spriteCloud.zIndex = -1 self.__step = 1 self.render.add(self.__board, self.__title, self.__text, self.__optNewGame, self.__optContinue, self.__optOption, self.__optExit) self.render.close() # 这里绑定和控件有交互的事件 # ---NewGame选项绑定事件--- self.__optNewGame.Events.appendEvent(ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_GAME_PROLOGUE), 1) self.__optNewGame.Events.appendEvent(ioEvent3Enum.mouseIn, lambda: self.__changeBoardText(self.__expBoardText[1]), 1) self.__optNewGame.Events.appendEvent(ioEvent3Enum.mouseOut, lambda: self.__changeBoardText(self.__expBoardText[0]), 1) # ---Continue选项绑定事件--- self.__optContinue.Events.appendEvent(ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_CONTINUE), 1) self.__optContinue.Events.appendEvent(ioEvent3Enum.mouseIn, lambda: self.__changeBoardText(self.__expBoardText[2]), 1) self.__optContinue.Events.appendEvent(ioEvent3Enum.mouseOut, lambda: self.__changeBoardText(self.__expBoardText[0]), 1) # ---Option选项绑定事件--- self.__optOption.Events.appendEvent(ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_OPT), 1) self.__optOption.Events.appendEvent(ioEvent3Enum.mouseIn, lambda: self.__changeBoardText(self.__expBoardText[3]), 1) self.__optOption.Events.appendEvent(ioEvent3Enum.mouseOut, lambda: self.__changeBoardText(self.__expBoardText[0]), 1) # ---Exit选项绑定事件--- self.__optExit.Events.appendEvent(ioEvent3Enum.mouseIn, lambda: self.__changeBoardText(self.__expBoardText[4]), 1) self.__optExit.Events.appendEvent(ioEvent3Enum.mouseOut, lambda: self.__changeBoardText(self.__expBoardText[0]), 1) self.__optExit.Events.appendEvent(ioEvent3Enum.mouseLeftKeyClick, lambda: pygame.event.post(pygame.event.Event(12)), 1) # 渲染参数 self.__step_in = 2 self.__step_out = 5 if self.__frameRate != 0: self.__step_in = 255 / (2 * self.__frameRate) self.__step_out = 255 / (1.5 * self.__frameRate)
def __init__(self, *args): # 初始化场景参数 super().__init__(*args) # resource name self.res_Img1 = 'NG_F_SS_1.bmp' self.res_Img2 = 'NG_F_SS_2.bmp' self.Sound_PourWine = 'NG_F_SS_PW.wav' self.Sound_Cup = 'NG_F_SS_C.wav' self.Sound_Drink = 'NG_F_SS_D.wav' self.Sound_Weak = 'NG_F_SS_W.wav' self.Music_BGM = 'NG_F_SS_BGM.wav' # assets name self.__asf_name1 = 'T_P.assets' self.__asf_name2 = 'T_P_C.assets' # 注册场景 from source.config.AppConfig import registerScene registerScene(SCENENUM_GAME_STARTCG, Prologue_StartCGScene) # 音频 # pygame.mixer.music.load(gl_MusicPath + "TP_F_SS_BGM.mp3") self.res_Sound_PourWine = pygame.mixer.Sound(gl_SoundPath + self.Sound_PourWine) self.res_Sound_PourWine.set_volume(self.config.getVolumeSound()) self.res_Sound_Cup = pygame.mixer.Sound(gl_SoundPath + self.Sound_Cup) self.res_Sound_Cup.set_volume(self.config.getVolumeSound()) self.res_Sound_Drink = pygame.mixer.Sound(gl_SoundPath + self.Sound_Drink) self.res_Sound_Drink.set_volume(self.config.getVolumeSound()) self.res_Sound_Weak = pygame.mixer.Sound(gl_SoundPath + self.Sound_Weak) self.res_Sound_Weak.set_volume(self.config.getVolumeSound()) self.res_Music_BGM = pygame.mixer.Sound(gl_MusicPath + self.Music_BGM) self.res_Music_BGM.set_volume(self.config.getVolumeBGM()) # 其它元素 self.__assetsFile = AssetsFile(os.path.join(gl_AssetsPath, 'PrologueScene')) self.__TextList = self.__assetsFile.decode(self.__asf_name1, AssetsType.SUB) self.__DialogueList = self.__assetsFile.decode(self.__asf_name2, AssetsType.SUB) self.__TextShow = TextElement((200, 460, 270, 18), self.__TextList[0], gl_Font_oth, 16, (255, 255, 255), self.config.getTextAntiAlias()) self.__ImgShow = ImgElement((80, 0, 640, 480), gl_ImgPath + self.res_Img1) self.__DialogueShow = TextElement((0, 500, 430, 18), self.__DialogueList[0], gl_Font_oth, 16, (255, 255, 255), self.config.getTextAntiAlias()) # 注册元素 self.__ElementsList = [] # 设定渲染时的参数 self.__flag_Num = 0 self.__flag_BGMPlayed = False self.now_time, self.interval = None, None self.__TextShow_Interval, self.__DialogueShow_Interval = 5000, 6000 self.__alphaStep_Text, self.__alphaStep_Dia = 0, 0 self.__index, self.__alpha = 0, 0 self.__frameRate = self.config.getFrameRate() if self.__frameRate == 0: self.__alphaStep_Text = self.__TextShow_Interval / 1000 * 0.036 self.__alphaStep_Dia = self.__DialogueShow_Interval / 1000 * 0.416 else: self.__alphaStep_Text = 255 / (((self.__TextShow_Interval - 1500) / 1000) * self.__frameRate) self.__alphaStep_Dia = 255 / self.__frameRate
class Title_PrologueScene(Scene): def __init__(self, *args): # 初始化场景参数 super().__init__(*args) # resource name self.res_Img1 = 'NG_F_SS_1.bmp' self.res_Img2 = 'NG_F_SS_2.bmp' self.Sound_PourWine = 'NG_F_SS_PW.wav' self.Sound_Cup = 'NG_F_SS_C.wav' self.Sound_Drink = 'NG_F_SS_D.wav' self.Sound_Weak = 'NG_F_SS_W.wav' self.Music_BGM = 'NG_F_SS_BGM.wav' # assets name self.__asf_name1 = 'T_P.assets' self.__asf_name2 = 'T_P_C.assets' # 注册场景 from source.config.AppConfig import registerScene registerScene(SCENENUM_GAME_STARTCG, Prologue_StartCGScene) # 音频 # pygame.mixer.music.load(gl_MusicPath + "TP_F_SS_BGM.mp3") self.res_Sound_PourWine = pygame.mixer.Sound(gl_SoundPath + self.Sound_PourWine) self.res_Sound_PourWine.set_volume(self.config.getVolumeSound()) self.res_Sound_Cup = pygame.mixer.Sound(gl_SoundPath + self.Sound_Cup) self.res_Sound_Cup.set_volume(self.config.getVolumeSound()) self.res_Sound_Drink = pygame.mixer.Sound(gl_SoundPath + self.Sound_Drink) self.res_Sound_Drink.set_volume(self.config.getVolumeSound()) self.res_Sound_Weak = pygame.mixer.Sound(gl_SoundPath + self.Sound_Weak) self.res_Sound_Weak.set_volume(self.config.getVolumeSound()) self.res_Music_BGM = pygame.mixer.Sound(gl_MusicPath + self.Music_BGM) self.res_Music_BGM.set_volume(self.config.getVolumeBGM()) # 其它元素 self.__assetsFile = AssetsFile(os.path.join(gl_AssetsPath, 'PrologueScene')) self.__TextList = self.__assetsFile.decode(self.__asf_name1, AssetsType.SUB) self.__DialogueList = self.__assetsFile.decode(self.__asf_name2, AssetsType.SUB) self.__TextShow = TextElement((200, 460, 270, 18), self.__TextList[0], gl_Font_oth, 16, (255, 255, 255), self.config.getTextAntiAlias()) self.__ImgShow = ImgElement((80, 0, 640, 480), gl_ImgPath + self.res_Img1) self.__DialogueShow = TextElement((0, 500, 430, 18), self.__DialogueList[0], gl_Font_oth, 16, (255, 255, 255), self.config.getTextAntiAlias()) # 注册元素 self.__ElementsList = [] # 设定渲染时的参数 self.__flag_Num = 0 self.__flag_BGMPlayed = False self.now_time, self.interval = None, None self.__TextShow_Interval, self.__DialogueShow_Interval = 5000, 6000 self.__alphaStep_Text, self.__alphaStep_Dia = 0, 0 self.__index, self.__alpha = 0, 0 self.__frameRate = self.config.getFrameRate() if self.__frameRate == 0: self.__alphaStep_Text = self.__TextShow_Interval / 1000 * 0.036 self.__alphaStep_Dia = self.__DialogueShow_Interval / 1000 * 0.416 else: self.__alphaStep_Text = 255 / (((self.__TextShow_Interval - 1500) / 1000) * self.__frameRate) self.__alphaStep_Dia = 255 / self.__frameRate def draw(self): self.now_time = pygame.time.get_ticks() self.interval = self.now_time - self.startClock if not self.isReadyToEnd: if self.__flag_Num == 0: # if not pygame.mixer.music.get_busy(): # pygame.mixer.music.play() if self.interval > self.__TextShow_Interval: self.__alpha = 0 self.startClock = pygame.time.get_ticks() self.__index += 1 if self.__index >= len(self.__TextList): self.__index = 0 self.__flag_Num = 1 self.__alpha = 0 pygame.mixer.music.stop() self.__ElementsList = [self.__ImgShow, self.__DialogueShow] else: self.__TextShow.setText(self.__TextList[self.__index]) self.__alpha += self.__alphaStep_Text self.__TextShow.setAlpha(self.__alpha) self.screen.blit(self.__TextShow.res_surface, ( centeredXPos(self.screen.get_width(), len(self.__TextShow.Text) * self.__TextShow.Size), 400)) elif self.__flag_Num == 1: if not self.__flag_BGMPlayed: self.res_Music_BGM.play() self.__flag_BGMPlayed = True if self.__index == 0 or self.__index == 1: self.__alpha += self.__alphaStep_Dia self.__ImgShow.setAlpha(self.__alpha) self.__DialogueShow.setAlpha(self.__alpha - self.__alphaStep_Dia * self.__frameRate) if self.interval > self.__DialogueShow_Interval: self.__alpha = 0 self.startClock = pygame.time.get_ticks() self.__index += 1 if self.__index >= len(self.__DialogueList): self.res_Sound_Cup.play() time.sleep(1.4) self.isReadyToEnd = True else: self.__DialogueShow.setText(self.__DialogueList[self.__index]) if self.__index == 1: self.res_Sound_Weak.play() self.__ImgShow.setPath(gl_ImgPath + self.res_Img2) if self.__index == 2: self.res_Sound_Cup.play() if self.__index == 3: self.res_Sound_PourWine.play() if self.__index == 4: self.res_Sound_Drink.play() self.screen.blit(self.__ImgShow.res_surface, (self.__ImgShow.area.x, self.__ImgShow.area.y)) self.screen.blit(self.__DialogueShow.res_surface, ( centeredXPos(self.screen.get_width(), len(self.__DialogueShow.Text) * self.__DialogueShow.Size), self.__DialogueShow.area.y)) else: self.nextSceneNum = SCENENUM_GAME_STARTCG self.isEnd = True
class RobotRunScene(Scene): def __init__(self, screen, config, startClock): super(RobotRunScene, self).__init__(screen, config, startClock) self.w, self.h = self.screen.get_width(), self.screen.get_height() self.__As_MAP = AStarArea(Rectangle(0, 0, 800, 600), 80, 60) self.caption = 'Actor与A*结合测试场景' self.__containers = [] for i in range(0, 6): x = int(random.randint(100, self.w - 150) / 10) * 10 y = int(random.randint(100, self.h - 150) / 10) * 10 w = int(random.randint(50, 150) / 10) * 10 h = int(random.randint(50, 150) / 10) * 10 self.__containers.append(Container(Rectangle(x, y, w, h))) _x, _y = int(x / self.__As_MAP.unit_w), int(y / self.__As_MAP.unit_h) _w, _h = int(w / self.__As_MAP.unit_w), int(h / self.__As_MAP.unit_h) self.__As_MAP.addObstacleArea(_x, _w, _y, _h) self.__A_Robot = RobotActor(Rectangle(0, 0, 100, 100)) self.__E_Msg = TextElement((600, 0, 200, 60), 'Robotlocal:(0, 0)\nMouselocal:(0, 0)', gl_Font, 12, (255, 255, 255), 1) self.__E_Msg2 = TextElement((600, 40, 200, 600), 'Astart:\n', gl_Font, 10, (255, 255, 255), 1) self.__pathList = [] self.__normalLis = [] self.__build_As_Map() self.__i = 0 self.__end = (0, 0) def __build_As_Map(self): self.__As_MAP.setStart((0, 0)) def __updateMap(self, point): h, w = self.__As_MAP.unit_h, self.__As_MAP.unit_w pos = self.__A_Robot.getLocal() x = int(pos.x / w) y = int(pos.y / h) try: self.__As_MAP.setStart((x, y)) except CoordinateException as e: return e.pos x = int(point[0] / w) y = int(point[1] / h) try: self.__As_MAP.setEnd((x, y)) except CoordinateException as e: return e.pos def __normalList(self): self.__normalLis.clear() h, w = self.__As_MAP.unit_h, self.__As_MAP.unit_w for p in self.__pathList: self.__normalLis.append(point2(p[0] * w, p[1] * h)) if len(self.__normalLis) > 1: self.__normalLis.pop(0) self.__A_Robot.setPathList(self.__normalLis) def draw(self): # for e in self.__As_MAP.getObstaclesList(): # Painter(self.screen).Rect(Rectangle(e[0] * 10, e[1] * 10, 10, 10), (255, 255, 255), 0) for container in self.__containers: container.draw(self.screen) self.__A_Robot.draw(self.screen) self.__E_Msg.draw(self.screen) self.__E_Msg2.draw(self.screen) def doClockEvent(self, NowClock): if self.__i < len(self.__normalLis): if self.__A_Robot.update(self.__normalLis[self.__i], 5, self.__normalLis[-1]): self.__i += 1 p = self.__A_Robot.area.barycenter() p2 = self.__end lis_str = 'A-start:\n' for _p in self.__normalLis: lis_str += str(_p) + '\n' self.__E_Msg.setText('Robotlocal:({}, {})\nMouselocal:({}, {})\n'.format(p.x, p.y, p2[0], p2[1])) self.__E_Msg2.setText(lis_str) def doMouseButtonDownEvent(self, Button): if Button == 1: self.__end = self.mousePos pos = self.__updateMap(self.__end) if pos: return self.__pathList = self.__As_MAP.run() self.__normalList() self.__As_MAP.refresh() self.__i = 0