Пример #1
0
def load_image(filename, transparent=False):
    image = pygame.image.load(filename)
    image = image.convert()
    if transparent:
        color = image.get_at((0, 0))
        image.set_colorkey(color)
    return image
Пример #2
0
 def image(self, rect, colorkey=None, alpha=False):
     rect = Rect(rect)
     if alpha: image = Surface(rect.size).convert_alpha()
     else: image = Surface(rect.size).convert()
     image.blit(self.sheet, (0,0), rect)
     if colorkey is not None:
         if colorkey == -1:
             colorkey = image.get_at((0,0))
         image.set_colorkey(colorkey, RLEACCEL)
     return image
Пример #3
0
 def image_at(self, rectangle, colorkey = None):
     "Loads image from x,y,x+offset,y+offset"
     rect = pygame.Rect(rectangle)
     image = pygame.Surface(rect.size).convert()
     image.blit(self.sheet, (0, 0), rect)
     if colorkey is not None:
         if colorkey is -1:
             colorkey = image.get_at((0,0))
         image.set_colorkey(colorkey, pygame.RLEACCEL)
     return image
 def imageAt(self, rectangle, colorkey=-1):
     """
     Note: When calling images_at the rect is the format: (x, y, x + offset, y + offset)
     """
     "Loads image from x,y,x+offset,y+offset"
     rect = Rect(rectangle)
     image = Surface(rect.size).convert()
     image.blit(self.sheet, (0, 0), rect)
     if colorkey is not None:
         if colorkey is -1:
             colorkey = image.get_at((0, 0))
         image.set_colorkey(colorkey, RLEACCEL)
     return image
Пример #5
0
 def imageAt(self, rectangle, colorkey=-1):
     """
     Note: When calling images_at the rect is the format: (x, y, x + offset, y + offset)
     """
     "Loads image from x,y,x+offset,y+offset"
     rect = Rect(rectangle)
     image = Surface(rect.size).convert()
     image.blit(self.sheet, (0, 0), rect)
     if colorkey is not None:
         if colorkey is -1:
             colorkey = image.get_at((0, 0))
         image.set_colorkey(colorkey, RLEACCEL)
     return image
Пример #6
0
def load_images():
    images = {}

    bpath = __file__.replace(os.path.basename(__file__), '')
    bpath = os.path.join(bpath, 'gfx', 'img')
    image_filenames = os.listdir(bpath)

    for image_filename in image_filenames:
        path = os.path.join("./", bpath, image_filename)
        name = name = os.path.basename(image_filename).split('.')[0].lower()
        image = pygame.image.load(path).convert()
        colorkey = image.get_at((10, 10))
        image.set_colorkey(colorkey)
        images[name] = image
    return images
Пример #7
0
    def __init__(self, rect, font, scrollback=1000,
                 bg=(255, 165, 0)):
        image = pygame.Surface(rect.size)
        image.set_colorkey(bg)
        image.set_alpha(127)
        image.fill(bg)
        Sprite.__init__(self, rect, image)
        self.scrollback = scrollback
        self.buffer = [''] * scrollback
        self.font = font
        self.bg = bg
        self.linesize = linesize(font)
	self.numlines = int(self.rect.height / self.linesize) + 1
	self.currentcolor = (255, 255, 255)
	self.offset = 0
Пример #8
0
    def get_image(self, x, y, width, height):
        """ Grab a single image out of a larger spritesheet
            Pass in the x, y location of the sprite
            and the width and height of the sprite. """

        # Create a new blank image
        image = Surface([width, height]).convert()

        # Copy the sprite from the large sheet onto the smaller image
        image.blit(self.sprite_sheet, (0, 0), (x, y, width, height))

        # Assuming black works as the transparent color
        image.set_colorkey(self.color)

        # Return the image
        return image
Пример #9
0
def object_image_load(parameters):
    """
    @param parameters: list with picture parameters (NAME, TRANSPARENCY, SIZE)
    @return: image descriptor
    """
    from pygame.constants import RLEACCEL
    from pygame import error
    from pygame.transform import scale
    import pygame.image
    try:
        image = pygame.image.load('res/' + parameters[0] + '.bmp').convert()
    except error:
        error_message("Loading:", "not found " + parameters[0] + '.bmp')
    else:
        image.set_colorkey(image.get_at((0, 0)), RLEACCEL)
        image.set_alpha(parameters[1])
        image = scale(image, (parameters[2][0], parameters[2][1]))
        return image
Пример #10
0
    def mouseon(self):
	# we want the ORT to behave like an exit
	if self.nick == 'ORT_Number_1':
	    self.server.whichmouseover('ov_tram_exit')
        if self.label is not None:
	    print self.nick, 'on'
	    self.label.die()
	
	# Strip color codes from the nick for display
	nicklist = list(self.nick)
	nick = ''
	avoid = list(string.digits)
	avoid.extend([',', '\x03'])
	found = 0
	for n in nicklist:
	    if n == '\x03':
		found = 1
	    if found == 1:
		try:
		    test = avoid.index(n)
		except:
		    found = 0
	    if found == 0:
		nick = nick + n
	
	sx, sy = _font.size(nick)
	s = _font.render(nick, 0, (255, 255, 255))
	image = pygame.Surface((sx+2, sy+2))
	image.set_colorkey((255,165,0))
	image.fill((255,165,0))
	for x in range(3):
	    for y in range(3):
	        image.blit(s, (x, y))
	image.blit(_font.render(nick, 1, (0,0,0)), (1, 1))
	image.set_alpha(127)
	x, y = self.rect.center
	nx, ny = self.noffset
	self.label = ClampingSprite((x+nx, y+ny), image, Rect(0, 0, 640, 480))
	self.group.add(self.label)
	return [self.label.rect]
Пример #11
0
    def load_images(self):
        images = {}

        bpath = __file__.replace(os.path.basename(__file__), '')
        bpath = os.path.join(bpath, 'gfx', 'img')
        image_filenames = os.listdir(bpath)

        for image_filename in image_filenames:
            try:
                path = os.path.join("./", bpath, image_filename)
                name = name = os.path.basename(image_filename).split(
                    '.')[0].lower()
                image = pygame.image.load(path).convert()
                colorkey = image.get_at((10, 10))
                image.set_colorkey(colorkey)
                images[name] = image
                msg = "{'load' : True, 'msg' : 'loaded: %s'}" % path
                self.cm.talk(msg)
            except:
                msg = "{'error' : True, 'msg' : 'Failed to load: %s'}" % path
                self.cm.talk(msg)

        self.images = images
Пример #12
0
             
       
# following function and class are used for the displaying of the pointer
#functions to create our resources
def load_image(name, colorkey=None):
    #fullname = os.path.join('c:\\program files\\pygame-docs\\examples\\data', name)
    fullname=name
    try:
        image = pygame.image.load(fullname).convert()
    except pygame.error, message:
        print 'Cannot load image:', name
        raise SystemExit, message
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, RLEACCEL)
    return image, image.get_rect()

def main():
    """this function is called when the program starts.
       it initializes everything it needs, then runs in
       a loop until the function returns."""
    #Initialize Everything
    #this calls the 'main' function when this script is executed
    s = Animation()
    s.initio()
    #s.imagedir = IMAGEDIR
    #s.imagedir = r'C:\_research_cleath\Documents-By-Date-and-Study\2002-09-30-Animation-project\images\bmpSmall'
    #s.imagedir = r'X:\test_label_bug\bmpLarge'
    s.imagedir = r'X:\test_label_bug\bmpSmall'
    s._initimagelist()
Пример #13
0
def loadImage(image, colorKey=None):
    #Load an image and set color key
    image = pygame.image.load(image)
    image.set_colorkey(colorKey)
    return image
Пример #14
0
    def render(self):
        """Render the text, returning the affected rect."""

	pad = 3
        maxdist = 200
        screen_rect = Rect(0, 0, 640, 480 - (linesize(_font)+2))
        size = linesize(_font)
        
        # Try not overlapping anything
        balloonrects = map(lambda s: s.rect, self.group.list)
        try: balloonrects.remove(self.rect)
        except ValueError: pass

        # First, try to avoid everything
        rects1 = invertrect(screen_rect, balloonrects +
                            map(lambda s: s.rect, self.avgroup.list))
        rects1.sort(self.nearer)

        # Next, try to avoid just balloons and my av
        rects2 = invertrect(screen_rect, balloonrects +
                            [self.avatar.rect])
        rects2.sort(self.nearer)

        # Finally, just avoid my own av
        rects3 = invertrect(screen_rect, [self.avatar.rect])
        rects3.sort(self.nearer)

        rects = filter(lambda r,p=self.pos,m=maxdist: rectdist(r,p) < m,
                       rects1 + rects2 + rects3) + [screen_rect]

        notdone = 1
        while notdone:
            # Loop until we can fit the balloon into *some* rect
            for r in rects:
                try: lines = wrap_lines(self.text, r.width-pad*2, _font)
                except ValueError: continue
                if len(lines) * size + pad*2 < r.height:
                    notdone = 0
                    break
            else:
                # Couldn't render the balloon, delete some lines
                del self.text[0]
                del self.timeouts[0]

        # Count the number of lines in each sequence of text
        surfaces = map(lambda t,f=_font,c=self.fgcolor: f.render(t, 1, c),
                       lines)
        width = max(map(lambda l: _font.size(l)[0], lines)) + (pad * 2)
        height = len(surfaces) * size + (pad * 2)

        x, y = self.pos
        rect = Rect(x-width/2, y-height/2, width, height).clamp(r)

        bigrect = rect.union((self.pos, (1, 1)))
        image = pygame.Surface(bigrect.size)
        image.set_colorkey((255,165,0))
        image.fill((255,165,0))

        cx, cy = closest(rect, self.pos)
        cx = cx - bigrect.left
        cy = cy - bigrect.top
        x = x - bigrect.left
        y = y - bigrect.top
        left = rect.left - bigrect.left
        right = rect.right - bigrect.left - 1
        top = rect.top - bigrect.top
        bottom = rect.bottom - bigrect.top - 1
        # Calculate arcs for corners
        nwarc = arc(pad, (left+pad, top+pad), pi*1.5, pi*2, 5)
        nearc = arc(pad, (right-pad, top+pad), 0, pi*0.5, 5)
        searc = arc(pad, (right-pad, bottom-pad), pi*0.5, pi, 5)
        swarc = arc(pad, (left+pad, bottom-pad), pi, pi*1.5, 5)
        
        # Go in a clockwise direction
        if x > right-pad*2:
            # Drawing to the east
            if y > bottom-pad*2:
                # Draw the arrow to the southeast
                points = ((right, bottom-pad), (x, y),
                          (right-pad, bottom)) + swarc + nwarc + nearc
            elif y < top+pad*2:
                # Draw the arrow to the northeast
                points = ((right-pad, top), (x, y),
                          (right, top+pad)) + searc + swarc + nwarc
            elif x > right:
                # Due east
                points = ((right, cy-pad), (x, y),
                          (right, cy+pad)) + \
                          searc + swarc + nwarc + nearc
            else:
                # Arrow is inside balloon
                points = searc + swarc + nwarc + nearc
        elif x < left+pad*2:
            # Drawing to the west
            if y > bottom-pad*2:
                # Southwest
                points = ((left+pad, bottom), (x, y),
                          (left, bottom-pad)) + \
                          nwarc + nearc + searc
            elif y < top+pad*2:
                # Northwest
                points = ((left, top+pad), (x, y),
                          (left+pad, top)) + \
                          nearc + searc + swarc
            elif x < left:
                # Due west
                points = ((left, cy+pad), (x, y),
                          (left, cy-pad)) + \
                          nwarc + nearc + searc + swarc
            else:
                # Arrow is inside balloon
                points = nwarc + nearc + searc + swarc
        elif y < top:
            # Due north
            points = ((cx-pad, top), (x, y), (cx+pad, top)) + \
                     nearc + searc + swarc + nwarc
        elif y > bottom:
            # Due south
            points = ((cx+pad, bottom), (x, y),
                      (cx-pad, bottom)) + \
                      swarc + nwarc + nearc + searc
        else:
            print >> sys.stderr, 'Oops, arrow point is inside balloon!'
            points = swarc + nwarc + nearc + searc

        pygame.draw.polygon(image, (255,255,255), points, 0)
        pygame.draw.polygon(image, (0,0,0), points, 1)
        y = rect.top - bigrect.top + pad
        x = rect.left - bigrect.left
        for s in surfaces:
            image.blit(s, (((width - s.get_width())/2+x), y))
            y = y + size

        self.image = image

        #rect = rect.clamp((0, 0, 640, 480))
        self.rect = bigrect

        return bigrect