def createRect(width, height, color=(255,255,255)): image = _pygame.Surface((width, height)) _pygame.draw.rect(image, color, (0, 0, width, height)) return image.subsurface(image.get_rect())
def activate(self, a=None): if (a == None): self.active = not self.active else: self.active = a if (self.active): _sys.stdout.write(CURSOR + " ") self._temp = self.screen.copy() t = _pygame.Surface((800, 200)) t.fill((255, 255, 255)) self.screen.blit(t, (0, 0), self.rect) if not self.active: if (self.bg): self.screen.blit(self.bg, (0, 0), self.rect) self.screen.blit(self._temp, (0, 0,), self.rect) self._temp = None
def __init__( self, name, # Name of map _type, # Type of map size, # Tuple of grids layout, # Grid collision, # Grid camera=None, # only used in creating Camera Sprites background=None, # Background path tileSize=(24, 24), # size of tiles layoutImage={0: None}, # paths to image numbers collisionTypes={0: None}, # types of collisions ): self.name = name self.type = _type self.size = size self.layout = layout self.collision = collision self.camera = camera print "NAME: " + name print "SIZE: " + str(size) print "TILESIZE: " + str(tileSize) if (background == None): print "Default background loading..." self.background = _pygame.Surface((WIDTH, HEIGHT)) self.background.fill(COLORS['black']) else: self.background = tools.loadImage(background) self.tileSize = tileSize self.defaultTile = _pygame.Surface(tileSize) self.defaultTile.set_alpha(0) print "Loading tiles..." self.layoutImage = {0: self.defaultTile} for x in layoutImage: if ((x != -1) and (x != 'Map')): try: if (type(layoutImage) != type([])): layoutImage[x] = [layoutImage[x], 0, 0] if (layoutImage[x][0] in COLORS): #print COLORS[layoutImage[x][0]] load = tools.createRect(tileSize[0], tileSize[1], COLORS[layoutImage[x][0]]) elif (((type(layoutImage[x][0]) == type([])) or (type(layoutImage[x][0]) == type(tuple([])))) and (len(layoutImage[x][0]) == 3)): load = tools.createRect(tileSize[0], tileSize[1], layoutImage[x][0]) else: load = tools.loadImage(layoutImage[x][0]) location = layoutImage[x][1] * tileSize[0] , \ layoutImage[x][2] * tileSize[1] image = _pygame.Surface(tileSize) image.blit(load, [0, 0, 0, 0], [ location[0], location[1], load.get_width(), load.get_height() ]) except: print("Warning: %s was not loaded" % (layoutImage[x][0].__repr__())) image = self.defaultTile self.layoutImage[x] = image print "Loading collision..." self.collisionTypes = {} for x in collisionTypes: if (x != 'Map'): self.collisionTypes[x] = collisionTypes[x] self._sprites = None