예제 #1
0
파일: main.py 프로젝트: tbjc1magic/tbjcGame
    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
예제 #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)
예제 #3
0
파일: Map.py 프로젝트: tbjc1magic/tbjcGame
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
예제 #4
0
파일: Map.py 프로젝트: tbjc1magic/tbjcGame
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
예제 #5
0
파일: Map.py 프로젝트: tbjc1magic/tbjcGame
    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)
예제 #6
0
파일: Map.py 프로젝트: tbjc1magic/tbjcGame
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
예제 #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)
예제 #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 = []
예제 #9
0
파일: Map.py 프로젝트: tbjc1magic/tbjcGame
    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)
예제 #10
0
 def __init__(self, loc, size):
     EventManager.__init__(self)
     self.size = Vector2D(*size)
     self.loc = Vector2D(*loc)
예제 #11
0
파일: Map.py 프로젝트: tbjc1magic/tbjcGame
 def hoverOver(self, mouse_position):
     self.cursor_pos = Vector2D(*mouse_position)//self.gridSize
예제 #12
0
파일: Map.py 프로젝트: tbjc1magic/tbjcGame
 def markUnoccupied(self, chessPos):
     chessPos = Vector2D(*chessPos)
     self.availability[chessPos[0]][chessPos[1]] = 1
예제 #13
0
from utils.Vector import Vector2D

cell_size = Vector2D(48, 64)
character_refresh_cycle = 4
character_move_speed = 2
예제 #14
0
파일: main.py 프로젝트: tbjc1magic/tbjcGame
 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))
예제 #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}