def draw(self): party_avatar = self.map_model.party_avatar # Draw the background if party_avatar: party_pos = party_avatar.position movement_offset = self.calc_object_movement_offset(party_avatar) party_x_offset, party_y_offset = movement_offset else: party_pos = Position(0, 0) party_x_offset, party_y_offset = 0, 0 self.bg_topleft = self.camera_mode.calc_bg_slice_topleft( party_pos, party_x_offset, party_y_offset) bg_rect = pygame.Rect(self.bg_topleft, g_cfg.screen_dimensions) phase = self.phase / g_cfg.animation_frame_period get_screen().blit(self.backgrounds[phase], (0, 0), bg_rect) # Draw the map objects self.draw_object_layer(self.map_model.below_objects) self.draw_object_layer(self.map_model.obstacle_objects) self.draw_object_layer(self.map_model.above_objects) # Draw the foreground get_screen().blit(self.foreground, (0, 0), bg_rect) # Update phase self.phase = (self.phase + 1) % (ANIMATION_PERIOD * g_cfg.animation_frame_period)
def draw(self): surface = self.font.render("Object#: %d" % (self.amount), True, dialog_config.font_color) get_screen().blit(surface, (20, 20)) surface = self.font.render( "Party: (%d, %d)" % (self.party_pos.x, self.party_pos.y), True, dialog_config.font_color ) get_screen().blit(surface, (20, 40))
def draw(self): surface = self.font.render("Object#: %d" % (self.amount), True, dialog_config.font_color) get_screen().blit(surface, (20, 20)) surface = self.font.render( "Party: (%d, %d)" % (self.party_pos.x, self.party_pos.y), True, dialog_config.font_color) get_screen().blit(surface, (20, 40))
def draw_object_layer(self, object_layer): if g_cfg.object_width > g_cfg.tile_size or\ g_cfg.object_height > g_cfg.tile_size: object_layer.sort(key=lambda x: x.position) for obj in object_layer: obj_x_offset, obj_y_offset = self.calc_object_movement_offset(obj) obj_topleft = self.camera_mode.\ calc_object_topleft(self.bg_topleft, obj.position, obj.image.width, obj.image.height, obj_x_offset, obj_y_offset) obj_rect = pygame.Rect(obj_topleft, g_cfg.object_dimensions) get_screen().blit(obj.get_surface(), obj_rect)
def draw(self): scr = get_screen() scr.blit(self.bg.get_surface(), (self.x, self.y)) Div.draw(self) Div.render(self, scr, self.x, self.y) if self.cursor is not None: self.cursor.draw() self.cursor.render(scr)
def gameloop(self, current=None): """ This method transfers the control flow to the ContextStack, which will keep its stacked Contexts running until one of them calls ContextStack.stop() or they are all removed from the ContextStack. The ContextStack will cap the cycles/second at game_config.fps. In each cycle, the following will happen: 1) For each active context in the map, bottom-up: a) The update() method of that Context will be called b) The draw() method of that Context will be drawn 2) The screen will be flipped so that the screen receives all the updates at once. 3) For each incoming event: a) For each context, top-down: i) The event will be offered to the context. ii) The context will choose to pass down or hold the event, no matter if it was actually used or not. iii) If the context chose not to pass down, continue to do 3. 4) If anyone called ContextStack.stop() or if there are no Contexts in the stack, stop. """ #print 'gameloop(%s)' % current self.keep_going = True self.clock = pygame.time.Clock() while self.stack and self.keep_going: # Limit FPS self.clock.tick(game_config.fps) get_metronome().step() Input.update_mouse(pygame.mouse.get_pressed(), pygame.mouse.get_pos()) Input.add_events(pygame.event.get()) if current is not None: current.update() else: # Update contexts in reverse order stop = False for context in reversed(self.stack): if context.active: #print 'updating %s' % context stop = context.update() if stop: break # Draw active contexts in normal order for context in self.stack: context.draw() if Input.isset('QUIT'): exit() Input.update() # Flip display get_screen().flip() if current is not None and current not in self.stack: self.keep_going = False # print 'gameloop ended' self.keep_going = True