def new_game(self, event): player = {'name': 'Test', 'class': 'warrior'} self.screen.blit(pygame.image.load('../res/gui/loading_screen.png'), (WIDTH / 2 - 110, HEIGHT / 2 - 17)) pygame.display.flip() self.world = World(player) self.world.update(self.camera) self.ui = GuiHandler(self.world) self.console = Console() self.tooltip = Tooltip(self.world)
def __init__(self): pygame.init() get_item_sprite('test', 0) self.event_manager = EventManager() self.screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.HWACCEL) self.world_screen = pygame.Surface((WIDTH - MENU_WIDTH, HEIGHT - CONSOLE_HEIGHT)) self.clock = GameClock(40) self.camera = self.world_screen.get_rect().copy() self.events = None self.console = Console() self.menu = Menu() register_handler(MENU_NEW_GAME, self.new_game)
def __init__(self): ShowBase.__init__(self) # Disable the camera trackball controls. self.disableMouse() # Load the environment model. self.environ = self.loader.loadModel("models/environment") # Reparent the model to render. self.environ.reparentTo(self.render) # Apply scale and position transforms on the model. self.environ.setScale(0.25, 0.25, 0.25) self.environ.setPos(-8, 42, 0) # Add the spinCameraTask procedure to the task manager. self.taskMgr.add(self.spinCameraTask, "SpinCameraTask") # Load and transform the panda actor. self.pandaActor = Actor(models="models/panda-model", anims={"walk": "models/panda-walk4"}) self.pandaActor.setScale(0.005, 0.005, 0.005) self.pandaActor.reparentTo(self.render) # Loop its animation. self.pandaActor.loop("walk") # Create the four lerp intervals needed for the panda to # walk back and forth. A = Point3(0, 10, 0) B = Point3(0, -10, 0) pandaPosInterval1 = self.pandaActor.posInterval(13, B, startPos=A) pandaPosInterval2 = self.pandaActor.posInterval(13, A, startPos=B) pandaHprInterval1 = self.pandaActor.hprInterval(3, Point3(180, 0, 0), startHpr=Point3( 0, 0, 0)) pandaHprInterval2 = self.pandaActor.hprInterval(3, Point3(0, 0, 0), startHpr=Point3( 180, 0, 0)) # Create and play the sequence that coordinates the intervals. self.pandaPace = Sequence(pandaPosInterval1, pandaHprInterval1, pandaPosInterval2, pandaHprInterval2, name="pandaPace") self.pandaPace.loop() self.teapot = self.loader.loadModel('models/teapot') self.teapot.reparentTo(self.render) self.console = Console(self) self.filters = CommonFilters(self.win, self.cam) self.filters.setCartoonInk() self.filters.setAmbientOcclusion() self.filters.setBloom()
def __init__(self): ShowBase.__init__(self) # Load the environment model. self.environ = self.loader.loadModel("/model ttf/para.egg") # Reparent the model to render. self.environ.reparentTo(self.render) # Apply scale and position transforms on the model. self.environ.setScale(0.25, 0.25, 0.25) # Add the spinCameraTask procedure to the task manager. self.taskMgr.add(self.spinCameraTask, "SpinCameraTask") self.console = Console(self)
class Game(object): ''' Main core of the main. ''' def __init__(self): pygame.init() get_item_sprite('test', 0) self.event_manager = EventManager() self.screen = pygame.display.set_mode((WIDTH, HEIGHT)) self.world_screen = pygame.Surface( (WIDTH - MENU_WIDTH, HEIGHT - CONSOLE_HEIGHT)) self.clock = GameClock(40) self.camera = self.world_screen.get_rect().copy() self.events = None self.menu = Menu() register_handler(MENU_NEW_GAME, self.new_game) def new_game(self, event): player = {'name': 'Test', 'class': 'warrior'} self.screen.blit(pygame.image.load('../res/gui/loading_screen.png'), (WIDTH / 2 - 110, HEIGHT / 2 - 17)) pygame.display.flip() self.world = World(player) self.world.update(self.camera) self.ui = GuiHandler(self.world) self.console = Console() self.tooltip = Tooltip(self.world) def run(self): """ Handles the looping of the main with a clock that follows a set amount of ticks per second. Also prints out the current fps, ups and polls the latest inputs. """ while True: pygame.display.set_caption("FPS: {0}, UPS: {1}".format( self.clock.get_fps(), self.clock.get_ups())) print "FPS: {0}, UPS: {1}".format(self.clock.get_fps(), self.clock.get_ups()) dt = self.clock.tick() if self.clock.update_ready: self.event_manager.update() self.events = self.event_manager.events for event in self.events: if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: if not self.menu.main: self.menu.active = not self.menu.active if not self.menu.active: if pygame.mouse.get_focused(): self.update() if self.clock.frame_ready: if self.menu.active: self.menu.draw(self.screen) else: self.draw() pygame.display.flip() def update(self): ''' Main update loop. ''' self.world.update(self.camera) self.camera.centerx = int(self.world.player.x) * 32 self.camera.centery = int(self.world.player.y) * 32 if self.camera.x < 0: self.camera.x = 0 if self.camera.x + self.camera.w > self.world.map.width: self.camera.x = self.world.map.width - self.camera.w if self.camera.y < 0: self.camera.y = 0 if self.camera.y + self.camera.h > self.world.map.height: self.camera.y = self.world.map.height - self.camera.h self.ui.update(self.world) self.tooltip.update(self.world, self.camera) def draw(self): ''' Main draw loop. ''' self.world.draw(self.world_screen, self.camera) self.screen.blit(self.world_screen, (0, 0)) self.ui.draw(self.screen) self.console.draw(self.screen) self.tooltip.draw(self.screen)
class Game(object): ''' Main core of the main. ''' def __init__(self): pygame.init() get_item_sprite('test', 0) self.event_manager = EventManager() self.screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.HWACCEL) self.world_screen = pygame.Surface((WIDTH - MENU_WIDTH, HEIGHT - CONSOLE_HEIGHT)) self.clock = GameClock(40) self.camera = self.world_screen.get_rect().copy() self.events = None self.menu = Menu() register_handler(MENU_NEW_GAME, self.new_game) def new_game(self, event): player = {'name': 'Test', 'class': 'warrior'} self.screen.blit(pygame.image.load('../res/gui/loading_screen.png'), (WIDTH / 2 - 110, HEIGHT / 2 - 17)) pygame.display.flip() self.world = World(player) self.world.update(self.camera) self.ui = GuiHandler(self.world) self.console = Console() self.tooltip = Tooltip(self.world) def run(self): """ Handles the looping of the main with a clock that follows a set amount of ticks per second. Also prints out the current fps, ups and polls the latest inputs. """ while True: pygame.display.set_caption("FPS: {0}, UPS: {1}".format(self.clock.get_fps(), self.clock.get_ups())) dt = self.clock.tick() if self.clock.update_ready: self.event_manager.update() self.events = self.event_manager.events for event in self.events: if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: if not self.menu.main: self.menu.active = not self.menu.active if not self.menu.active: if pygame.mouse.get_focused(): self.update() if self.clock.frame_ready: if self.menu.active: self.menu.draw(self.screen) else: self.draw() pygame.display.flip() def update(self): ''' Main update loop. ''' self.world.update(self.camera) self.camera.centerx = int(self.world.player.x) * 32 self.camera.centery = int(self.world.player.y) * 32 if self.camera.x < 0: self.camera.x = 0 if self.camera.x + self.camera.w > self.world.map.width: self.camera.x = self.world.map.width - self.camera.w if self.camera.y < 0: self.camera.y = 0 if self.camera.y + self.camera.h > self.world.map.height: self.camera.y = self.world.map.height - self.camera.h self.ui.update(self.world) self.tooltip.update(self.world, self.camera) def draw(self): ''' Main draw loop. ''' self.screen.fill((0, 0, 0)) self.world.draw(self.world_screen, self.camera) self.screen.blit(self.world_screen, (0, 0)) self.ui.draw(self.screen) self.console.draw(self.screen) self.tooltip.draw(self.screen)