예제 #1
0
    def run(this):
        this.app.update()
        pygame.display.flip()

        this.font = pygame.font.SysFont("", 16)

        this.clock = timer.Clock() #pygame.time.Clock()
        done = False
        while not done:
            # Process events
            for ev in pygame.event.get():
                if (ev.type == pygame.QUIT or 
                    ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE):
                    done = True
                else:
                    # Pass the event off to pgu
                    this.app.event(ev)
            # Render the game
            rect = this.app.get_render_area()
            updates = []
            this.disp.set_clip(rect)
            lst = this.render(this.disp, rect)
            if (lst):
                updates += lst
            this.disp.set_clip()

            # Cap it at 30fps
            this.clock.tick(30)

            # Give pgu a chance to update the display
            lst = this.app.update()
            if (lst):
                updates += lst
            pygame.display.update(updates)
            pygame.time.wait(10)
예제 #2
0
파일: engine.py 프로젝트: DrSLDR/mgmag-proj
    def __init__(self):
        self.updateables = []
        self.framerateThrottle = 0  # 0 for no throttle

        # Get logger
        self.log = logging.getLogger("GameEngine")

        self.log.debug("Creating game clock")
        self.clock = timer.Clock()  #pygame.time.Clock()
        self.log.debug("%s returning", self.__init__.__name__)
예제 #3
0
    def run(self):

        self.app.update()
        pygame.display.flip()

        self.font = pygame.font.SysFont("", 16)

        self.clock = timer.Clock()  #pygame.time.Clock()
        done = False
        while not done:
            # Process events
            for ev in pygame.event.get():
                if (ev.type == pygame.QUIT or ev.type == pygame.KEYDOWN
                        and ev.key == pygame.K_ESCAPE):
                    done = True
                else:
                    # Pass the event off to pgu
                    self.app.event(ev)
            # Render the game
            self.state = self.eng.get_next_state(self.state)
            self.counter += 1
            rect = self.app.get_render_area()
            updates = []
            self.disp.set_clip(rect)
            lst = self.render(self.disp, rect)
            print("c", lst)
            if lst:
                updates.append(lst)
                print("1", updates)
                print("COUNTER:", self.counter)
            self.disp.set_clip()

            # Cap it at 30fps
            self.clock.tick(1)

            # Give pgu a chance to update the display
            lst = self.app.update()
            if lst:
                print("2a", updates)
                updates += lst
                print("2b", updates)

            pygame.display.update(updates)
예제 #4
0
    def run(self):
        """
        Цикл отрисовки
        :return:
        """
        self.app.update()
        pygame.display.flip()
        self.font = self.app.font
        self.clock = timer.Clock()
        done = False
        # self.ai.run()
        while not done:
            for ev in pygame.event.get():
                if (ev.type == pygame.QUIT or ev.type == pygame.KEYDOWN
                        and ev.key == pygame.K_ESCAPE):
                    done = True
                elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_SPACE:
                    for _ in range(self.steps):
                        self.move_robot()
                else:
                    self.app.event(ev)
            rect = self.app.get_render_area()
            updates = []
            self.display.set_clip(rect)
            try:
                lst = self.render(self.display, rect)
            except pygame.error:
                lst = None
            if lst:
                updates += lst
            self.display.set_clip()

            self.clock.tick(30)

            lst = self.app.update()
            if lst:
                updates += lst
            pygame.display.update(updates)
            pygame.time.wait(10)
        self.ai.stop()
예제 #5
0
    def run(this):
        this.app.update()
        pygame.display.flip()

        this.font = pygame.font.SysFont("", 16)
        this.clock = timer.Clock()  #pygame.time.Clock()
        done = False
        while not done:
            # Process events
            for ev in pygame.event.get():
                if (ev.type == pygame.QUIT or ev.type == pygame.KEYDOWN
                        and ev.key == pygame.K_ESCAPE):
                    pygame.quit()
                    sys.exit()
                else:
                    # handle MOUSEBUTTONUP
                    if pygame.mouse.get_pressed()[0]:
                        pos = pygame.mouse.get_pos()
                        #print(pos)
                        Visualize.SpawnClick(1, pos[0], pos[1])
                    else:
                        Visualize.spray = False
                    # Pass the event off to pgu
                    this.app.event(ev)
            # Render the game
            rect = this.app.get_render_area()
            updates = []
            this.disp.set_clip(rect)
            lst = Visualize.main()
            if (lst):
                updates += lst

            this.disp.set_clip()

            # Cap it at 30fps
            this.clock.tick(20)

            # Give pgu a chance to update the display
            lst = this.app.update()
예제 #6
0
 def run(self):
     self.gui.update()
     pygame.display.flip()
     self.font = pygame.font.SysFont("", 16)
     self.clock = timer.Clock() #pygame.time.Clock()
     
     # Main program loop
     done = False
     while not done:
         startTime = self.clock.get_time() #Time since last loop
                  
         #Update the game state
         if not self.clock.paused and self.virtualCore != None: 
             ret = self.virtualCore.tick()
             if(ret != None): #player out
                 if(ret.playerID != -1):
                     print "Player " + str(ret.playerID) + " who loaded " + self.programNames[ret.playerID] + " lost. There are " + str(ret.playersLeft) + " players remaining"
                 else:
                     print "Time Up"
         
         #Will put this in its own method! Was experimenting! Do not delete!      
         for event in pygame.event.get():
                 if (event.type == pygame.QUIT or 
                     event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                     done = True 
                 if event.type == pygame.VIDEORESIZE:
                     self.display = pygame.display.set_mode(event.dict['size'],pygame.RESIZABLE)
                     self.drawArea = pygame.Surface(event.dict['size']).convert_alpha()
                     self.screenWidth = event.dict['size'][0]
                     self.screenHeight = event.dict['size'][1]
                     self.gui.updateSize(event.dict['size'])#TODO rewrite so menu is fixed height
                     pygame.display.update()
                     print self.screenWidth,self.screenHeight
                     self.gui.event(event)
                     self.doResize()
                 else:
                     # Pass the event off to pgu
                     self.gui.event(event)
                 
         self.rect = self.gui.get_render_area()              
         # Render the game
         updates = []
         self.display.set_clip(self.rect)
         lst = self.partRender()
         if (lst):
             updates += lst
             
         self.display.set_clip()
         
         # Give pgu a chance to update the display (menu)
         lst = self.gui.update()
         if (lst):
             updates += lst
         pygame.display.update(updates)    
             
         #Poll for events and render the screen AFAP until time for next tick
         while (not done) and ((self.clock.get_time() - startTime) < 0.1):   
             # Process events
             
             for event in pygame.event.get():
                 if (event.type == pygame.QUIT or 
                     event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                     done = True 
                 if event.type == pygame.VIDEORESIZE:
                     self.display = pygame.display.set_mode(event.dict['size'],pygame.RESIZABLE)
                     self.drawArea = pygame.Surface(event.dict['size']).convert_alpha()
                     self.screenWidth = event.dict['size'][0]
                     self.screenHeight = event.dict['size'][1]
                     self.gui.updateSize(event.dict['size'])#TODO rewrite so menu is fixed height
                     pygame.display.update()
                     print self.screenWidth,self.screenHeight
                     self.gui.event(event)
                     self.doResize()
                 else:
                     # Pass the event off to pgu
                     self.gui.event(event)
                 
             self.rect = self.gui.get_render_area()              
             # Render the game
             updates = []
             self.display.set_clip(self.rect)
             lst = self.partRender()
             if (lst):
                 updates += lst
                 
             self.display.set_clip()
             
             # Give pgu a chance to update the display (menu)
             lst = self.gui.update()
             if (lst):
                 updates += lst
             pygame.display.update(updates)