Пример #1
0
 def __init__( self, parentState, width, height ):
     Button.__init__( self, None, None, parentState, True )
     self.width = width
     self.height = height
     self.scale = None
     self.image = self.generateImage()
     self.rect = self.image.get_rect()
     if self.pos is None:
          MiniMap.pos = ( getResolution()[0]-width, getResolution()[1]-height )
     self.rect.topleft = self.pos
     self.held = False
     self.heldPos = None
     self.dragging = False
     self.panning = False
Пример #2
0
 def __init__(self, parentState, width, height):
     Button.__init__(self, None, None, parentState, True)
     self.width = width
     self.height = height
     self.scale = None
     self.image = self.generateImage()
     self.rect = self.image.get_rect()
     if self.pos is None:
         MiniMap.pos = (getResolution()[0] - width,
                        getResolution()[1] - height)
     self.rect.topleft = self.pos
     self.held = False
     self.heldPos = None
     self.dragging = False
     self.panning = False
Пример #3
0
 def generateImage( self ):
     floor = self.getFloor()
     rightMostPoint = max( [ each.rect.right for each in floor.layers ] )
     leftMostPoint = min( [ each.rect.left for each in floor.layers ] )
     topMostPoint = min( [ each.rect.top for each in floor.layers ] )
     bottomMostPoint = max( [ each.rect.bottom for each in floor.layers ] )
     worldWidth = rightMostPoint-leftMostPoint
     worldHeight = bottomMostPoint-topMostPoint
     sizeRect = pygame.Rect( 0, 0, worldWidth, worldHeight )
     playState = self.parentState.menu.playState
     img = pygame.Surface( (sizeRect.w, sizeRect.h) ).convert()
     for eachLayer in floor.layers:
         loc = (eachLayer.rect.left-leftMostPoint, eachLayer.rect.top-topMostPoint)
         img.blit( eachLayer.image, loc )
     scale = 1.0
     if worldWidth > worldHeight:
         scale = float(self.width)/worldWidth
     else:
         scale = float(self.height)/worldHeight
     self.scale = scale
     img = pygame.transform.rotozoom(img, 0.0, scale ).convert()
     screenW, screenH = getResolution()
     viewRect = pygame.Rect( (-leftMostPoint)*scale, (-topMostPoint)*scale, screenW*scale, screenH*scale )
     finalImage = pygame.Surface( (self.width, self.height) ).convert()
     finalImage.blit( img, (0, 0) )
     pygame.draw.rect( finalImage, pygame.Color( 255, 0, 0 ), viewRect, 1 )
     pygame.draw.rect( finalImage, pygame.Color( 255, 0, 0 ), pygame.Rect( 0, 0, self.width, self.height ), 1 )
     return finalImage
Пример #4
0
 def pan(self, point):
     dx = float(point[0] - self.rect.left)
     dy = float(point[1] - self.rect.top)
     playState = self.parentState.menu.playState
     screenW, screenH = getResolution()
     playState.setPan(-int(dx / self.scale) + (screenW / 2),
                      -int(dy / self.scale) + (screenH / 2))
Пример #5
0
 def generateImage(self):
     floor = self.getFloor()
     rightMostPoint = max([each.rect.right for each in floor.layers])
     leftMostPoint = min([each.rect.left for each in floor.layers])
     topMostPoint = min([each.rect.top for each in floor.layers])
     bottomMostPoint = max([each.rect.bottom for each in floor.layers])
     worldWidth = rightMostPoint - leftMostPoint
     worldHeight = bottomMostPoint - topMostPoint
     sizeRect = pygame.Rect(0, 0, worldWidth, worldHeight)
     playState = self.parentState.menu.playState
     img = pygame.Surface((sizeRect.w, sizeRect.h)).convert()
     for eachLayer in floor.layers:
         loc = (eachLayer.rect.left - leftMostPoint,
                eachLayer.rect.top - topMostPoint)
         img.blit(eachLayer.image, loc)
     scale = 1.0
     if worldWidth > worldHeight:
         scale = float(self.width) / worldWidth
     else:
         scale = float(self.height) / worldHeight
     self.scale = scale
     img = pygame.transform.rotozoom(img, 0.0, scale).convert()
     screenW, screenH = getResolution()
     viewRect = pygame.Rect((-leftMostPoint) * scale,
                            (-topMostPoint) * scale, screenW * scale,
                            screenH * scale)
     finalImage = pygame.Surface((self.width, self.height)).convert()
     finalImage.blit(img, (0, 0))
     pygame.draw.rect(finalImage, pygame.Color(255, 0, 0), viewRect, 1)
     pygame.draw.rect(finalImage, pygame.Color(255, 0, 0),
                      pygame.Rect(0, 0, self.width, self.height), 1)
     return finalImage
Пример #6
0
 def setPan( self, x, y ):
     screenW, screenH = getResolution()
     if self.limitX1 is not None:
         x = min( -self.limitX1, x )
     if self.limitX2 is not None:
         x = max( -(self.limitX2-screenW), x )
     if self.limitY1 is not None:
         y = min( -(self.limitY1), y )
     if self.limitY2 is not None:
         y = max( -(self.limitY2-screenH), y )
     self.panX, self.panY = x, y
Пример #7
0
 def setPan(self, x, y):
     screenW, screenH = getResolution()
     if self.limitX1 is not None:
         x = min(-self.limitX1, x)
     if self.limitX2 is not None:
         x = max(-(self.limitX2 - screenW), x)
     if self.limitY1 is not None:
         y = min(-(self.limitY1), y)
     if self.limitY2 is not None:
         y = max(-(self.limitY2 - screenH), y)
     self.panX, self.panY = x, y
Пример #8
0
 def moveTo( self, x, y ):
     w, h = getResolution()
     if x-self.x+self.panel.rect.left < 0:
         x -= x-self.x+self.panel.rect.left
     elif x-self.x+self.panel.rect.right > w:
         x -= x-self.x+self.panel.rect.right-w
     if y-self.y+self.panel.rect.top < 0:
         y -= y-self.y+self.panel.rect.top
     elif y-self.y+self.panel.rect.bottom > h:
         y -= y-self.y+self.panel.rect.bottom-h
     dx, dy = x-self.x,y-self.y
     self.x, self.y = x, y
     for each in [ sprite for sprite in self.sprites if not sprite.fixed ]:
         each.rect.topleft = each.rect.x+dx, each.rect.y+dy
Пример #9
0
 def moveTo(self, x, y):
     w, h = getResolution()
     if x - self.x + self.panel.rect.left < 0:
         x -= x - self.x + self.panel.rect.left
     elif x - self.x + self.panel.rect.right > w:
         x -= x - self.x + self.panel.rect.right - w
     if y - self.y + self.panel.rect.top < 0:
         y -= y - self.y + self.panel.rect.top
     elif y - self.y + self.panel.rect.bottom > h:
         y -= y - self.y + self.panel.rect.bottom - h
     dx, dy = x - self.x, y - self.y
     self.x, self.y = x, y
     for each in [sprite for sprite in self.sprites if not sprite.fixed]:
         each.rect.topleft = each.rect.x + dx, each.rect.y + dy
Пример #10
0
 def __init__( self, menu, sprites=[], miniMap=True ):
     self.sprites = sprites
     self.buttons = []
     self.menu = menu
     for eachSprite in self.sprites:
         if eachSprite.button:
             self.buttons.append( eachSprite )
         eachSprite.parentState = self
             #eachSprite.menu = menu
     self.keyInput = ""
     self.keyboardEnabled = False
     self.deleteLastChar = False
     self.x, self.y = 0, 0
     self.fileNameLabel = Label( self, menu.playState.fileName, (0,getResolution()[1]-32) )
     self.addSprite( self.fileNameLabel )
     self.usingMiniMap = miniMap
     if miniMap:
         self.addMiniMap()
     self.miniMapFlip = False
Пример #11
0
 def __init__(self, menu, sprites=[], miniMap=True):
     self.sprites = sprites
     self.buttons = []
     self.menu = menu
     for eachSprite in self.sprites:
         if eachSprite.button:
             self.buttons.append(eachSprite)
         eachSprite.parentState = self
         #eachSprite.menu = menu
     self.keyInput = ""
     self.keyboardEnabled = False
     self.deleteLastChar = False
     self.x, self.y = 0, 0
     self.fileNameLabel = Label(self, menu.playState.fileName,
                                (0, getResolution()[1] - 32))
     self.addSprite(self.fileNameLabel)
     self.usingMiniMap = miniMap
     if miniMap:
         self.addMiniMap()
     self.miniMapFlip = False
Пример #12
0
    def __init__( self, playState, text, box=None ):
        sheet = loadImageNoAlpha( self.sheetFileName )
        self.originFrames = splitFrames( sheet, (32, 32) )
        if box is None:
            w, h = getResolution()
            box = pygame.Rect( (0, (7.0/12)*h), (w, (5.0/12)*h ) )
        
        img = pygame.Surface( (box.w, box.h) ).convert()
        #img.fill( pygame.Color( 0, 0, 0, 0 ) )

        for x in range( 32, box.w, 32 ):
            img.blit( self.originFrames[1], (x, 0) )
            img.blit( self.originFrames[7], (x, box.h-32) )

        for y in range( 32, box.h, 32 ):
            img.blit( self.originFrames[3], (0, y) )
            img.blit( self.originFrames[5], (box.w-32, y) )

        for x in range( box.x+32, box.w+box.x-32, 32 ):
            for y in range( 32, box.h-32, 32 ):
                img.blit( self.originFrames[4], (x,y) )
        
        img.blit( self.originFrames[0], ( 0, 0 ) )
        img.blit( self.originFrames[2], (box.w-32, 0) )
        img.blit( self.originFrames[6], (0, box.h-32) )
        img.blit( self.originFrames[8], (box.w-32, box.h-32) )

        wLimit = box.w-64

        subStrings = []
        lastIndex = 0
        for eachIndex in range( len( text ) ):
            eachSub = text[lastIndex:eachIndex]
            if text[eachIndex] == "\n":
                subStrings.append( eachSub )
                lastIndex = eachIndex + 1
            elif self.font.size( eachSub )[0] > wLimit:
                subStrings.append( eachSub[:-1] )
                lastIndex = eachIndex - 1
            elif eachIndex == ( len( text ) - 1 ):
                subStrings.append( eachSub+text[-1] )
        if len( subStrings ) is  0:
            subStrings = [ text ]

        curIndex = 0
        curY = 32
        while curY < box.h-32 and curIndex < len( subStrings ):
            eachImg = self.font.render( subStrings[curIndex], True, pygame.Color( 0, 0, 0 ) )
            img.blit( eachImg, ( 32, curY ) )
            curY += eachImg.get_height()
            curIndex += 1

        HudElement.__init__( self, playState, box.topleft, img, False )
        self.image.set_colorkey( self.colourKey )

        self.dying = False
        self.removed = False
        self.removeTime = 0.5
        self.removeTimer = 0.0

        self.borning = True
        self.bornTime = 0.25
        self.bornTimer = 0.0
Пример #13
0
 def pan( self, point ):
     dx = float(point[0]-self.rect.left)
     dy = float(point[1]-self.rect.top)
     playState = self.parentState.menu.playState
     screenW, screenH = getResolution()
     playState.setPan( -int(dx/self.scale)+(screenW/2), -int(dy/self.scale)+(screenH/2) )
Пример #14
0
    def __init__(self, playState, text, box=None):
        sheet = loadImageNoAlpha(self.sheetFileName)
        self.originFrames = splitFrames(sheet, (32, 32))
        if box is None:
            w, h = getResolution()
            box = pygame.Rect((0, (7.0 / 12) * h), (w, (5.0 / 12) * h))

        img = pygame.Surface((box.w, box.h)).convert()
        #img.fill( pygame.Color( 0, 0, 0, 0 ) )

        for x in range(32, box.w, 32):
            img.blit(self.originFrames[1], (x, 0))
            img.blit(self.originFrames[7], (x, box.h - 32))

        for y in range(32, box.h, 32):
            img.blit(self.originFrames[3], (0, y))
            img.blit(self.originFrames[5], (box.w - 32, y))

        for x in range(box.x + 32, box.w + box.x - 32, 32):
            for y in range(32, box.h - 32, 32):
                img.blit(self.originFrames[4], (x, y))

        img.blit(self.originFrames[0], (0, 0))
        img.blit(self.originFrames[2], (box.w - 32, 0))
        img.blit(self.originFrames[6], (0, box.h - 32))
        img.blit(self.originFrames[8], (box.w - 32, box.h - 32))

        wLimit = box.w - 64

        subStrings = []
        lastIndex = 0
        for eachIndex in range(len(text)):
            eachSub = text[lastIndex:eachIndex]
            if text[eachIndex] == "\n":
                subStrings.append(eachSub)
                lastIndex = eachIndex + 1
            elif self.font.size(eachSub)[0] > wLimit:
                subStrings.append(eachSub[:-1])
                lastIndex = eachIndex - 1
            elif eachIndex == (len(text) - 1):
                subStrings.append(eachSub + text[-1])
        if len(subStrings) is 0:
            subStrings = [text]

        curIndex = 0
        curY = 32
        while curY < box.h - 32 and curIndex < len(subStrings):
            eachImg = self.font.render(subStrings[curIndex], True,
                                       pygame.Color(0, 0, 0))
            img.blit(eachImg, (32, curY))
            curY += eachImg.get_height()
            curIndex += 1

        HudElement.__init__(self, playState, box.topleft, img, False)
        self.image.set_colorkey(self.colourKey)

        self.dying = False
        self.removed = False
        self.removeTime = 0.5
        self.removeTimer = 0.0

        self.borning = True
        self.bornTime = 0.25
        self.bornTimer = 0.0