Пример #1
0
 def __init__(self, map):
     self.UP = self.DOWN = self.LEFT = self.RIGHT = self.RUNNING = self.CLICK = False
     self.camleft = self.camright = False
     self.scrollup = self.scrolldown = False
     # 'bind' classes to the playstate class, for later use,
     # instead of leaving them floating in the 'global' realm
     self.player = Tittle()
     self.map = maploader.map('2')
     self.TILES, self.tiles = self.map.build()
     self.camera = camera(complex_camera, self.map.width(), self.map.height())
Пример #2
0
 def run(self):
     playtime = 0
     clock = pygame.time.Clock()
     
     while True:
         ms = clock.tick(FPS) 
         playtime += ms / 1000.0
         
         action = keyhandler.get_action(self, pygame.event.get())
         if action == 'newplayer':
             del self.player
             self.player = Tittle()
             
         elif action == 'fullscreen':
             render.toggleFullscreen()
                 
         pygame.display.set_caption('FPS: {0:.2f}'.format(clock.get_fps())) 
                 
         self.runframe()
Пример #3
0
class playState(object):
    
    """
    Define all of the object's variables in the __init__
    """
    def __init__(self, map):
        self.UP = self.DOWN = self.LEFT = self.RIGHT = self.RUNNING = self.CLICK = False
        self.camleft = self.camright = False
        self.scrollup = self.scrolldown = False
        # 'bind' classes to the playstate class, for later use,
        # instead of leaving them floating in the 'global' realm
        self.player = Tittle()
        self.map = maploader.map('2')
        self.TILES, self.tiles = self.map.build()
        self.camera = camera(complex_camera, self.map.width(), self.map.height())

    """
    Draw the tiles that are in the array 'tiles'
    """
    def drawTiles(self):
        for t in self.tiles:
            screen.blit(t.image, self.camera.apply(t))
            
    """
    Routine operations happening each tick, from filling the screen to updating
    and drawing new player information
    """
    def runframe(self):
        screen.blit(background, (0, 0))

        self.camera.move(self.camleft, self.camright)
        self.camera.update(self.player)
        
        self.player.update(self.UP, self.DOWN, self.LEFT, self.RIGHT, self.RUNNING, self.TILES)
        mouse.update(pygame.mouse.get_pos(), self.CLICK)
        if mtext:
            mtext.update(pygame.mouse.get_pos())     
        
        self.drawTiles()
        
        screen.blit(self.player.image, self.camera.apply(self.player))
        screen.blit(mouse.image, mouse.rect)
        if mtext:
            screen.blit(mtext.image, mtext.rect)
        
        pygame.display.update()
        
    """
    Handles the input from all sources, and translates to movements or events
    May be moved to own module
    """            
    def run(self):
        playtime = 0
        clock = pygame.time.Clock()
        
        while True:
            ms = clock.tick(FPS) 
            playtime += ms / 1000.0
            
            action = keyhandler.get_action(self, pygame.event.get())
            if action == 'newplayer':
                del self.player
                self.player = Tittle()
                
            elif action == 'fullscreen':
                render.toggleFullscreen()
                    
            pygame.display.set_caption('FPS: {0:.2f}'.format(clock.get_fps())) 
                    
            self.runframe()