def __init__(self): self.gameWindow = pygame.display.set_mode() x, y, w, h = self.gameWindow.get_rect() self.SCREEN_RES = (w, h) self.musicManager = Audio() # handles music playback self.loading = Loading(self.SCREEN_RES) # Loading object self.game = None self.clock = pygame.time.Clock() self.running = False self.eventmanager = EventManager( ) #Incorporate EventManager to handle player input self.currentMenuState = None self.menuOptions = {} self.menuOptions[menu.Main] = LandingMenu(self.SCREEN_RES) self.menuOptions[menu.Loading] = self.menuOptions[menu.Main] self.menuOptions[menu.NewGame] = GameMenu(self.SCREEN_RES) self.menuOptions[menu.Controls] = ControlsMenu(self.SCREEN_RES) self.menuOptions[menu.ClassInfo] = ClassMenu(self.SCREEN_RES) self.menuOptions[menu.PartySelection] = self.menuOptions[menu.Main] self.bg_color = pygame.color.THECOLORS['black'] self.Party_Load = None self.f_name = "pickle_data.p"
return None if __name__ == "__main__": import os from GameEngine.EventManager import * from Scene.Camera import Camera running = True clock = pygame.time.Clock() os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.init() pygame.font.init() pygame.display.set_caption("Menu Test") screen = pygame.display.set_mode(SCREEN_RES) eventManager = EventManager() dungeon = Dungeon(4) camera = Camera(dungeon) camera.reticle.setPos( (SCREEN_RES[0]//2,SCREEN_RES[1]//2) ) eventManager.addGameObject(camera.reticle) for room in dungeon.rooms: for wall in room.walls.sprites(): eventManager.addGameObject(wall) while running: dt = clock.tick(60) / 1000 running = eventManager.process_input(dt) events = pygame.event.get() for event in events:
""" screen.blit(self.blit_image, (int(self.rect[0] - cameraPos[0]), int(self.rect[1] - cameraPos[1]))) if __name__ == "__main__": import os from GameEngine.EventManager import * from Scene.Tile import * pygame.init() os.environ['SDL_VIDEO_CENTERED'] = '1' bg_color = pygame.color.THECOLORS['black'] window = pygame.display.set_mode(SCREEN_RES) pygame.display.set_caption("PROJECTILE TEST HARNESS") manager = EventManager() tiles = pygame.sprite.Group() bottomY = SCREEN_RES[1] - 32 topY = 0 for i in range(int(SCREEN_RES[0] / 32)): x = i * 32 tileSurf = pygame.Surface((32, 32)) tileSurf.fill(pygame.color.THECOLORS['green']) pygame.draw.rect(tileSurf, pygame.color.THECOLORS['black'], pygame.Rect(0, 0, 32, 32), 2) topRect = pygame.Rect(x, topY, 32, 32) bottomRect = pygame.Rect(x, bottomY, 32, 32) tiles.add(Tile(tileSurf, topRect)) tiles.add(Tile(tileSurf, bottomRect))
class GameManager: def __init__(self): self.gameWindow = pygame.display.set_mode() x, y, w, h = self.gameWindow.get_rect() self.SCREEN_RES = (w, h) self.musicManager = Audio() # handles music playback self.loading = Loading(self.SCREEN_RES) # Loading object self.game = None self.clock = pygame.time.Clock() self.running = False self.eventmanager = EventManager( ) #Incorporate EventManager to handle player input self.currentMenuState = None self.menuOptions = {} self.menuOptions[menu.Main] = LandingMenu(self.SCREEN_RES) self.menuOptions[menu.Loading] = self.menuOptions[menu.Main] self.menuOptions[menu.NewGame] = GameMenu(self.SCREEN_RES) self.menuOptions[menu.Controls] = ControlsMenu(self.SCREEN_RES) self.menuOptions[menu.ClassInfo] = ClassMenu(self.SCREEN_RES) self.menuOptions[menu.PartySelection] = self.menuOptions[menu.Main] self.bg_color = pygame.color.THECOLORS['black'] self.Party_Load = None self.f_name = "pickle_data.p" def LoadMenu(self, menuOption): currentMenu = self.menuOptions[ self. currentMenuState] if self.currentMenuState != None else menu.Main newMenu = self.menuOptions[menuOption] if currentMenu in self.eventmanager.game_objects['game_menus']: self.eventmanager.removeGameMenu(currentMenu) self.eventmanager.addGameMenu(newMenu) self.currentMenuState = menuOption def Launch(self): self.LoadMenu(menu.Main) self.running = True def RunMenuLoop(self): while (self.running): #Check user input self.running = self.eventmanager.process_menu_input() #check user selection and determine state self.determineState(self.menuOptions[self.currentMenuState]) #Draw if self.running: self.gameWindow.fill(self.bg_color) self.menuOptions[self.currentMenuState].draw(self.gameWindow) if self.currentMenuState != menu.Controls and self.currentMenuState != menu.ClassInfo: self.menuOptions[self.currentMenuState].play_sounds() pygame.display.update() def RunDungeon(self): self.loading.draw(self.gameWindow) self.musicManager.set_volume(0.2) self.musicManager.load_music( "Sounds/Music/Final Fantasy Mystic Quest - Lava Dome.mp3") self.musicManager.play_music(0) self.game = DungeonRun(self.eventmanager, self.gameWindow, self.Party_Load) self.game.start_game() self.game.launch_game() self.musicManager.stop_music() self.Party_Load = self.game.party_list.partyInfoToPickle() def startBossFight(self): self.loading.draw(self.gameWindow) self.musicManager.set_volume(0.2) self.musicManager.load_music( "Sounds/Music/Final Fantasy Mystic Quest OST - Battle 2.mp3") self.musicManager.play_music(0) self.game = BossFight(self.eventmanager, self.gameWindow, self.Party_Load) self.game.start_game() self.game.launch_game() self.musicManager.stop_music() self.Party_Load = self.game.party_list.partyInfoToPickle() def rollCredits(self): credits = Credits(self.eventmanager, self.gameWindow) credits.start_credits() credits.begin_sequence() def save_game(self): if self.Party_Load != None: with open(self.f_name, 'wb') as output: # Overwrites any existing file. pickle.dump(self.Party_Load, output, protocol=pickle.HIGHEST_PROTOCOL) def Loadsave(self): with open(self.f_name, 'rb') as input: self.Party_Load = pickle.load(input) def determineState(self, currentMenu): if currentMenu == None: return if currentMenu.selectedOption == None: return selected = currentMenu.getMenuSelection() newMenuOption = None if self.currentMenuState == menu.Main: if selected == "New Game": newMenuOption = menu.NewGame self.Party_Load = None elif selected == "Load Game": self.Loadsave() newMenuOption = menu.NewGame elif selected == "Game Controls": newMenuOption = menu.Controls elif selected == "Class Info": newMenuOption = menu.ClassInfo elif selected == "Credits": self.rollCredits() elif selected == "Exit": self.running = False elif self.currentMenuState == menu.NewGame: if selected == "Main Menu": newMenuOption = menu.Main else: if selected == "Enter Dungeon": self.RunDungeon() self.eventmanager.cleanup() elif selected == "Fight The Boss": #print("Game Manager, line 85: Selected Boss Fight"); self.startBossFight() self.eventmanager.cleanup() elif selected == "Save Game": self.save_game() newMenuOption = menu.NewGame elif self.currentMenuState == menu.ClassInfo: if selected == "Main Menu": newMenuOption = menu.Main elif self.currentMenuState == menu.Loading: if selected == "New Game": newMenuOption = menu.NewGame elif selected == "Load Game": newMenuOption = menu.Loading #TODO:: make method to pull up menu to select game save self.Loadsave() newMenuOption = menu.NewGame elif selected == "Game Controls": newMenuOption = menu.Controls elif selected == "Exit": self.running = False elif self.currentMenuState == menu.Controls: if selected == "Back": newMenuOption = menu.Main currentMenu.Reset() if newMenuOption == None: newMenuOption = menu.Main self.LoadMenu(newMenuOption)
for obj in info: screen.blit(obj[0], obj[1]) self.fadeEffect(screen) def fadeEffect(self, screen): # Fade to Black overlay = pygame.Surface(self.SCREEN_RES) overlay.fill((0, 0, 0)) overlay.set_alpha(self.alphaLevel) screen.blit(overlay, (0, 0)) if __name__ == "__main__": import os from GameEngine.EventManager import * running = True clock = pygame.time.Clock() os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.init() pygame.font.init() pygame.display.set_caption("Menu Test") screen = pygame.display.set_mode() x, y, w, h = screen.get_rect() res = (w, h) eventManager = EventManager() credits = Credits(eventManager, screen) credits.start_credits() credits.begin_sequence()