Beispiel #1
0
    def __init__(self):

        self.gridSize = Constant.cell_size
        nGrid = Vector2D(10, 10)
        super().__init__(self.gridSize * nGrid)
        size = Vector2D(*self.display.get_rect().size)

        ### navigation map
        self.navigationMap = NaviationMap(self.display,
                                          loc=Vector2D(0, 0),
                                          size=size)

        self.registerController(self.navigationMap, animePriority=100)

        ### get a map
        self.mapManager = MapManager(self.display,
                                     loc=Vector2D(0, 0),
                                     size=size,
                                     nGrid=nGrid,
                                     gridMargin=(1, 1),
                                     offset=(1, 1),
                                     fPath='data/map.JPG')

        self.registerController(self.mapManager,
                                animePriority=-100,
                                eventPriority=-100)
        callback = functools.partial(leftClicked, host=self)
        self.mapManager.registerCallBack('left_click', callback)

        self.focus = None
Beispiel #2
0
    def __init__(self, fPath, nSubImages=(1,1)):
        

        self.img = pygame.image.load(fPath)
        self.nSubImages = Vector2D(*nSubImages)

        size = Vector2D(*self.img.get_rect().size)
        self.subImageSize = size/nSubImages
        self.imageOrigin = Vector2D(0,0)
Beispiel #3
0
def _generateFancyGridPaddedMap(mapSize, nGrid, gridMargin=(3,3), offset=(5,5)):
    
    mapSize, nGrid, gridMargin, offset = map(lambda _:Vector2D(*_),
                                                [mapSize,
                                                 nGrid,
                                                 gridMargin,
                                                 offset])

    gridFullSize = (mapSize-2*offset)//nGrid
    gridContentSize = gridFullSize-2*gridMargin

    #print(gridFullSize*nGrid+2*offset, mapSize)
    #assert gridFullSize*nGrid+2*offset == mapSize, "map can not be fully diveided" 

    gridContent = RoundedRect(gridContentSize, color=(0,0,255), radius=0.1)
    gridSurface = pygame.Surface(gridFullSize)
    gridSurface.blit(gridContent, gridMargin)
    gridMapSurface = pygame.Surface(mapSize)


    #return gridSurface
    for r in range(nGrid[0]):
        for c in range(nGrid[1]):
            loc = gridFullSize*(r,c) + offset

            gridMapSurface.blit(gridSurface, loc)

    gridMapSurface.set_alpha(100)

    return gridMapSurface
Beispiel #4
0
def _generateGridPaddedMap(mapSize, nGrid, omit=[]):
    
    mapSize, nGrid = Vector2D(*mapSize), Vector2D(*nGrid)
    gridFullSize = mapSize//nGrid

    gridMapSurface = pygame.Surface(mapSize, pygame.SRCALPHA, 32)
    gridSurface = pygame.Surface(gridFullSize, pygame.SRCALPHA, 32)
    gridSurface.fill((0,0,255,100))

    for r in range(nGrid[0]):
        for c in range(nGrid[1]):
            if (r,c) in omit: continue
            loc = gridFullSize*(r,c)
            gridMapSurface.blit(gridSurface, loc)

    return gridMapSurface
Beispiel #5
0
    def run(self):
        
        clock = pygame.time.Clock()
        self.__display = pygame.display.set_mode((800,600))

        
        mm = MapManager(self.__display,
                        loc=Vector2D(0,0),
                        size=self.__display.get_rect().size, 
                        nGrid=(40,30),
                        gridMargin=(1,1),
                        offset=(1,1),
                        fPath='data/map.JPG'
        )            
        self.__eventManager.registerController(mm)                
        #mm.getChessPosition(Vector2D(90,80))

        runStatus = True
        while runStatus:
            events = pygame.event.get()
            for event in events:
                if event.type == pygame.QUIT:
                    runStatus = False   

            mm.draw()
            pygame.display.update()
            self.__eventManager.processEvents(events) 
            clock.tick(120)
Beispiel #6
0
def main():
    pygame.init()
    gameDisplay = pygame.display.set_mode((800,600))
    
    mm = MapManager(gameDisplay,
                    loc=Vector2D(0,0),
                    size=gameDisplay.get_rect().size, 
                    nGrid=(40,30),
                    gridMargin=(1,1),
                    offset=(1,1),
                    fPath='data/map.JPG'
    )            
                    
    mm.getChessPosition(Vector2D(90,80))
    mm.draw()
    pygame.display.update()
    while pygame.event.wait().type != pygame.QUIT: pass
Beispiel #7
0
    def __init__(self, size):
        SquareShapeController.__init__(self, Vector2D(0, 0), size)
        pygame.init()
        self.display = pygame.display.set_mode(size)
        self.eventManager = EventManager()
        self.animeManager = AnimeManager(self.display)
        self.runStatus = True

        self.eventManager.registerController(self)
Beispiel #8
0
    def __init__(self, display, loc, fPath):

        self.__display = display
        self.__character_size = Constant.cell_size
        self.__canvasSize = self.__subImageSize = Constant.cell_size
        self.__canvas = pygame.Surface(self.__canvasSize, pygame.SRCALPHA, 32)
        self.__showMenus = False

        AnimeElement.__init__(self, self.__canvas, Vector2D(0, 0),
                              Constant.character_refresh_cycle)
        SquareShapeController.__init__(self, loc, self.__subImageSize)

        self.addImage(
            fPath,
            status=['walk_down', 'walk_left', 'walk_right', 'walk_up'],
            nSubImages=Vector2D(4, 4))

        self.__status = 'walk_down'
        self.__moves = []
Beispiel #9
0
    def __init__(self, parentSurface, loc, size, nGrid, fPath, gridMargin=(3,3), offset=(2,2)):
        
        SquareShapeController.__init__(self, loc, size)
        self.parentSurface = parentSurface    
        self.surface = pygame.Surface(size, pygame.SRCALPHA)
        img = pygame.image.load(fPath)
        #self.size = Vector2D(*size)
        self.backgroundImage = pygame.transform.scale(img, size)
        #self.loc = loc
        self.gridSize = Vector2D(*size)/nGrid
        #self.fog = _generateGridPaddedMap(size,nGrid, omit=[])
        self.fog = None
        self.nGrid = nGrid
        self.cursor_pos = None
        self.availability = [[1]*nGrid[1] for _ in range(nGrid[0])]

        self.registerCallBack('hover', self.hoverOver)
Beispiel #10
0
 def __init__(self, loc, size):
     EventManager.__init__(self)
     self.size = Vector2D(*size)
     self.loc = Vector2D(*loc)
Beispiel #11
0
 def hoverOver(self, mouse_position):
     self.cursor_pos = Vector2D(*mouse_position)//self.gridSize
Beispiel #12
0
 def markUnoccupied(self, chessPos):
     chessPos = Vector2D(*chessPos)
     self.availability[chessPos[0]][chessPos[1]] = 1
Beispiel #13
0
from utils.Vector import Vector2D

cell_size = Vector2D(48, 64)
character_refresh_cycle = 4
character_move_speed = 2
Beispiel #14
0
 def setUpGame(self):
     callback = functools.partial(rightClicked, host=self)
     self.registerCallBack('right_click', callback)
     infantry = self.initializeCharacter(Infantry, Vector2D(2, 2))
     rider = self.initializeCharacter(Rider, Vector2D(3, 3))
Beispiel #15
0
    def addImage(self, fPath, status=[], nSubImages=Vector2D(1,1)):
        nSubImages = Vector2D(*nSubImages)
        im = ImageManager(fPath, nSubImages)

        for i,s in enumerate(status):
            self.__imageDict[s] = {'shift':Vector2D(0,i),'imageManager':im, 'nFrames': nSubImages.w}