def update(self, td): # Pause the game if the player presses the pause button if inputs.getPausePress(): statemgr.switch("pause") self.scene.update(td) self.energy_bar.update()
def __init__(self): self.config = assets.getData("config.json") self.scale = self.config["scale"] self.width = metrics.SCREEN_WIDTH * self.scale self.height = metrics.SCREEN_HEIGHT * self.scale assets.setVolume(float(self.config["volume"]) / 100.0) fullscreen = 0 if self.config["fullscreen"]: fullscreen = pygame.FULLSCREEN # Changing some of the mixer settings reduces the delay before playing sound effects pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() pygame.display.set_caption("Gunmetal Gray") # TODO: Come up with better name #pygame.display.set_icon(pygame.image.load(assets.path("graphics/icon.png"))) pygame.mouse.set_visible(False) self.display = pygame.display.set_mode((self.width, self.height), pygame.HWSURFACE | pygame.DOUBLEBUF | fullscreen) self.surface = pygame.Surface((metrics.SCREEN_WIDTH, metrics.SCREEN_HEIGHT), pygame.HWSURFACE) self.clock = pygame.time.Clock() inputs.init(self.config) statemgr.init() statemgr.switch("title") self.playing = True self.debug_mode = False
def update(self, td): self.delay -= td if self.delay < 0: if self.direction == OUT: statemgr.switch(self.new_state, *self.args, **self.kwargs) statemgr.next_transition() elif self.direction == IN: statemgr.next_transition() else: if self.direction == OUT: self.surface.fill(self.color + (int(((self.max_delay-self.delay) / self.max_delay)*255),)) else: self.surface.fill(self.color + (int((self.delay / self.max_delay)*255),))
def update(self, td): self.delay -= td if self.delay < 0: if self.direction == OUT: statemgr.switch(self.new_state, *self.args, **self.kwargs) statemgr.next_transition() elif self.direction == IN: statemgr.next_transition() else: if self.direction == OUT: self.surface.fill(self.color) pygame.draw.circle(self.surface, (0,0,0,0), self.surface.get_rect().center, int((self.delay/self.max_delay) * self.max_size)) else: self.surface.fill(self.color) pygame.draw.circle(self.surface, (0,0,0,0), self.surface.get_rect().center, int(((self.max_delay-self.delay) / self.max_delay) * self.max_size))
def interact(self, obj): statemgr.switch("dialog", self.filename) return True
def btnNewGame(self): """Called when the player selects New Game. Clear state variables, save them, then starts playing.""" statevars.variables = {} statevars.save("saves/save_1.json") statemgr.switch("play")
def btnContinue(self): """Called when player selects Continue. Loads the old save file then starts playing.""" statevars.load("saves/save_1.json") statemgr.switch("play")
def update(self, td): """Update the UI""" if self.dialog.update(td): statemgr.switch(self.old_state_name)
def btnCredits(self): statemgr.switch("dialog", filename="dialogs/credits.json")
def update(self, td): """If the player presses the pause button, unpause the game.""" if inputs.getPausePress(): statemgr.switch(self.old_state_name)
def update(self, td): if self.direction == OUT: statemgr.switch(self.new_state, *self.args, **self.kwargs) statemgr.next_transition() elif self.direction == IN: statemgr.next_transition()
def event(self, event): """Should return true if game is still playing and false if the window should close""" if event.type == pygame.KEYDOWN: if event.key == pygame.K_F1: statemgr.switch("dialog", text=self.help_text) return True