def enter(self): self.redraw = True # temporary hack so that game bypasses the title screen menu if self.game is None: self.new_game() return if self.game: self.menu = Menu(20, -5, 'vertical', 100, [('New Game', self.new_game), ('Continue', self.continue_game), #('Save', self.save_game), #('Reload', self.load_game), #('Save and Quit', self.savequit_game), ('Quit', self.quit_game)], font="visitor1.ttf", font_size=20) else: self.menu = Menu(20, -5, 'vertical', 100, [('New Game', self.new_game), #('Continue', self.load_game), ('Introduction', self.show_intro), ('Quit', self.quit_game)], font="visitor1.ttf", font_size=20) self.menu.rect = pygame.Rect(12,12,20,100)
def enter(self): if self.game: self.menu = Menu(20, -5, 'vertical', 100, [('New Game', self.new_game), ('Continue', self.continue_game), #('Save', self.save_game), #('Reload', self.load_game), #('Save and Quit', self.savequit_game), ('Quit', self.quit_game)], font="visitor1.ttf", font_size=20) else: self.menu = Menu(20, -5, 'vertical', 100, [('New Game', self.new_game), #('Continue', self.load_game), ('Introduction', self.show_intro), ('Quit', self.quit_game)], font="visitor1.ttf", font_size=20) self.menu.rect = pygame.Rect(12,12,20,100) self.redraw = True
class TitleScreen(game.GameContext): def init(self): self.borderImage = Image("lpc-border0.png", colorkey=True) self.background = (109, 109, 109) self.border = draw.GraphicBox(self.borderImage) self.counter = 0 self.game = None def enter(self): self.redraw = True # temporary hack so that game bypasses the title screen menu if self.game is None: self.new_game() return if self.game: self.menu = Menu(20, -5, 'vertical', 100, [('New Game', self.new_game), ('Continue', self.continue_game), #('Save', self.save_game), #('Reload', self.load_game), #('Save and Quit', self.savequit_game), ('Quit', self.quit_game)], font="visitor1.ttf", font_size=20) else: self.menu = Menu(20, -5, 'vertical', 100, [('New Game', self.new_game), #('Continue', self.load_game), ('Introduction', self.show_intro), ('Quit', self.quit_game)], font="visitor1.ttf", font_size=20) self.menu.rect = pygame.Rect(12,12,20,100) def handle_command(self, cmd): self.menu.handle_command(cmd) def draw(self, surface): if self.redraw: self.redraw = False #if self.game: self.border.draw(surface, surface.get_rect(), fill=200) self.menu.draw(surface) def new_game(self): if self.game: [ i.unload() for i in self.game.getChildren() ] self.game.unload() self.game = None res.fadeoutMusic(1000) self.game = world.build() level = self.game.getChildByGUID(5001) self.parent.append(LevelState(level)) def save_game(self): path = os.path.join("resources", "saves", "save") [ i.unload() for i in self.game.getChildren() ] self.game.save(path) self.continue_game() def load_game(self): if self.game: [ i.unload() for i in self.game.getChildren() ] self.game.unload() self.game = None try: path = os.path.join("resources", "saves", "save") self.game = loadObject(path) except IOError: return self.new_game() level = self.game.getChildByGUID(5001) self.parent.append(LevelState(level)) def continue_game(self): res.fadeoutMusic(1000) level = self.game.getChildByGUID(5001) self.parent.append(LevelState(level)) def show_intro(self): self.parent.start_restart(InstructionScreen()) def savequit_game(self): if self.game: path = os.path.join("resources", "saves", "save") [ i.unload() for i in self.game.getChildren() ] self.game.save(path) self.quit_game() def quit_game(self): self.parent.remove(self)
class TitleScreen(GameState): borderImage = Image("lpc-border0.png", colorkey=True) def activate(self): self.background = (109, 109, 109) self.border = draw.GraphicBox(self.borderImage) self.counter = 0 self.game = None self.activated = True #self.reactivate() self.new_game() def deactivate(self): GameState.deactivate(self) def reactivate(self): if self.game: self.menu = Menu(20, -5, 'vertical', 100, [('New Game', self.new_game), ('Continue', self.continue_game), #('Save', self.save_game), #('Reload', self.load_game), #('Save and Quit', self.savequit_game), ('Quit', self.quit_game)], font="visitor1.ttf", font_size=20) else: self.menu = cMenu(20, -5, 'vertical', 100, [('New Game', self.new_game), #('Continue', self.load_game), ('Introduction', self.show_intro), ('Quit', self.quit_game)], font="visitor1.ttf", font_size=20) self.menu.rect = pygame.Rect(12,12,20,100) self.redraw = True #res.playMusic("oneslymove.ogg") def handle_event(self, event): self.menu.handle_event(event) def draw(self, surface): if self.redraw: self.redraw = False if self.game: self.border.draw(surface, surface.get_rect(), 200) self.menu.draw(surface) def new_game(self): res.fadeoutMusic(1000) self.game = world.build() level = self.game.getChildByGUID(5001) self.parent.start(LevelState(self.parent, level)) def save_game(self): path = os.path.join("resources", "saves", "save") [ i.unload() for i in self.game.getChildren() ] self.game.save(path) self.continue_game() def load_game(self): try: path = os.path.join("resources", "saves", "save") self.game = loadObject(path) except IOError: return self.new_game() level = self.game.getChildByGUID(5001) self.parent.start(LevelState(level)) def continue_game(self): res.fadeoutMusic(1000) level = self.game.getChildByGUID(5001) self.parent.start(LevelState(level)) def show_intro(self): self.parent.start_restart(InstructionScreen()) def savequit_game(self): if self.game: path = os.path.join("resources", "saves", "save") [ i.unload() for i in self.game.getChildren() ] self.game.save(path) self.quit_game() def quit_game(self): self.parent.done()