def setValue(self, v): if v == 0: self.text = '' return self.text = str(v) fs = 50 while v >= 10: fs -= 8 v //= 10 self.font = font_mod.load('ENCR10B.TTF', fs) w, h = c_int(), c_int() TTF_SizeText(self.font.font, self.text.encode('utf-8'), ctypes.byref(w), ctypes.byref(h)) self.hw = w.value / 2
def __init__(self, x, y): self.value=0 self.x, self.y = x,y self.font = font.load('verdanab.ttf', 50)
def init(args, view): music.preinit(view) pygame.init() pygame.display.set_caption("OpenCraft") pygame.display.set_icon(pygame.image.load("images/icon.png")) pygame.mouse.set_visible(False) view.screen = pygame.display.set_mode([640, 480]) view.screen.blit(pygame.image.load("images/title.png"), (0, 0)) pygame.display.update() music.init(view) print "Loading palettes" view.palettes = {} for path in os.listdir("palettes"): if path[0] == ".": continue pal = open(os.path.join("palettes", path), "rb").read() palette = [] for i in range(0, len(pal), 3): palette.append((ord(pal[i]), ord(pal[i + 1]), ord(pal[i + 2]))) view.palettes[path] = palette view.palettes["shadow"] = [(0, 0, 0)] * 256 print "Reading map" filename = "maps/BroodWar/(2)Astral Balance.scm" if len(sys.argv) > 1: filename = sys.argv[1] view.mapdim, view.tileset, view.map, view.doodads, view.starts, view.resources = mapreader.load( filename) print "Loading tileset:", view.tileset view.tile = tile.tiles["tileset/" + view.tileset + "/" + view.tileset] view.tilepalette = view.tile.palette print "Loading sprites" for datum in os.walk("images"): for path in [os.path.join(datum[0], x) for x in datum[2]]: if path.find("/.") != -1: continue name = '.'.join('/'.join(path.split("/")[1:]).split(".") [:-1]) # remove images/ and extension ext = path.split(".")[-1] if ext == "grp": sprite = grp.load(path, view.palettes["unit"]) if ext == "grc": sprite = grp.load(path, view.palettes["unit"], True) if ext == "gro": sprite = grp.load(path, view.palettes["orange"]) if ext == "grt": sprite = grp.load(path, view.tilepalette) if ext == "grs": sprite = grp.load(path, view.palettes["shadow"]) if ext == "png": sprite = pygame.image.load(path) if ext == "pcx": sprite = pygame.image.load(path) sprite.set_colorkey(0) view.sprites[name] = sprite print "Loading doodads" for path in os.listdir("tileset/" + view.tileset): if path == ".svn": continue if path.split(".")[-1] != "grp": continue view.sprites["tileset/" + view.tileset + "/" + path] = grp.load( "tileset/" + view.tileset + "/" + path, view.tilepalette) print "Loading fonts" font.load() print "Loading team colors" colors = pygame.image.load("images/colors.pcx") view.colors = [] for team in range(15): view.colors.append( [colors.get_at((x + team * 8, 0))[0:3] for x in range(7)]) colors = pygame.image.load("images/colorsm.pcx") view.colorsm = [] for team in range(16): view.colorsm.append(colors.get_at((team, 0))) if view.tileset == "platform": print "Reading stars" view.star = star.init(view.palettes["unit"]) print "Making map surface" make_map(view) print "Generating minimap" s = pygame.image.tostring(view.map_surf, "RGBX") temp = PIL.Image.fromstring("RGBX", view.map_surf.get_size(), s) temp.thumbnail((128, 128), PIL.Image.ANTIALIAS) view.minimap = pygame.image.fromstring(temp.tostring(), temp.size, temp.mode) for doodad in view.doodads: if type(doodad[0]) == int: view.sprites["tileset/" + str(doodad[0])] = [ view.font.render(str(doodad[0]), True, (255, 255, 255)) ] doodad = [str(doodad[0]), doodad[1], doodad[2]] view.units.append(Doodad(doodad)) view.mapw = [[all(pygame.surfarray.pixels2d(view.tile[m][1])) for m in y] for y in view.map] #view.mapw = [[True for m in y] for y in view.map] #print view.mapw #print mapw[5][5], mapw[10][10] view.pathfind = pathfind.path(view.mapdim) view.movie = [] for path in sorted(os.listdir("movie")): if path[0] == ".": continue view.movie.append(pygame.image.load(os.path.join("movie", path))) print "Loading units" load(view) print "Loaded! Took", pygame.time.get_ticks() / 1000.0 music.fade(view)
def load_font(name): return font.load(name)
def enter(): global font, board font = font_mod.load('ENCR10B.TTF', 50) board = Board() global sceneBgImage sceneBgImage = load_image('ingame_bg.png')
def init(args,view): music.preinit(view) pygame.init() pygame.display.set_caption("OpenCraft") pygame.display.set_icon(pygame.image.load("images/icon.png")) pygame.mouse.set_visible(False) view.screen = pygame.display.set_mode([640,480]) view.screen.blit(pygame.image.load("images/title.png"),(0,0)) pygame.display.update() music.init(view) print "Loading palettes" view.palettes = {} for path in os.listdir("palettes"): if path[0] == ".": continue pal = open(os.path.join("palettes", path),"rb").read() palette = [] for i in range(0, len(pal), 3): palette.append((ord(pal[i]), ord(pal[i+1]), ord(pal[i+2]))) view.palettes[path] = palette view.palettes["shadow"] = [(0,0,0)]*256 print "Reading map" filename = "maps/BroodWar/(2)Astral Balance.scm" if len(sys.argv) > 1: filename = sys.argv[1] view.mapdim, view.tileset, view.map, view.doodads, view.starts, view.resources = mapreader.load(filename) print "Loading tileset:", view.tileset view.tile = tile.tiles["tileset/"+view.tileset+"/"+view.tileset] view.tilepalette = view.tile.palette print "Loading sprites" for datum in os.walk("images"): for path in [os.path.join(datum[0],x) for x in datum[2]]: if path.find("/.") != -1: continue name = '.'.join('/'.join(path.split("/")[1:]).split(".")[:-1]) # remove images/ and extension ext = path.split(".")[-1] if ext == "grp": sprite = grp.load(path, view.palettes["unit"]) if ext == "grc": sprite = grp.load(path, view.palettes["unit"], True) if ext == "gro": sprite = grp.load(path, view.palettes["orange"]) if ext == "grt": sprite = grp.load(path, view.tilepalette) if ext == "grs": sprite = grp.load(path, view.palettes["shadow"]) if ext == "png": sprite = pygame.image.load(path) if ext == "pcx": sprite = pygame.image.load(path) sprite.set_colorkey(0) view.sprites[name] = sprite print "Loading doodads" for path in os.listdir("tileset/"+view.tileset): if path == ".svn": continue if path.split(".")[-1] != "grp": continue view.sprites["tileset/"+view.tileset+"/"+path] = grp.load("tileset/"+view.tileset+"/"+path, view.tilepalette) print "Loading fonts" font.load() print "Loading team colors" colors = pygame.image.load("images/colors.pcx") view.colors = [] for team in range(15): view.colors.append([colors.get_at((x+team*8,0))[0:3] for x in range(7)]) colors = pygame.image.load("images/colorsm.pcx") view.colorsm = [] for team in range(16): view.colorsm.append(colors.get_at((team,0))) if view.tileset == "platform": print "Reading stars" view.star = star.init(view.palettes["unit"]) print "Making map surface" make_map(view) print "Generating minimap" s = pygame.image.tostring(view.map_surf,"RGBX") temp = PIL.Image.fromstring ("RGBX", view.map_surf.get_size (), s) temp.thumbnail ((128,128), PIL.Image.ANTIALIAS) view.minimap = pygame.image.fromstring (temp.tostring(), temp.size, temp.mode) for doodad in view.doodads: if type(doodad[0]) == int: view.sprites["tileset/"+str(doodad[0])] = [view.font.render(str(doodad[0]),True,(255,255,255))] doodad = [str(doodad[0]),doodad[1],doodad[2]] view.units.append(Doodad(doodad)) view.mapw = [[all(pygame.surfarray.pixels2d(view.tile[m][1])) for m in y] for y in view.map] #view.mapw = [[True for m in y] for y in view.map] #print view.mapw #print mapw[5][5], mapw[10][10] view.pathfind = pathfind.path(view.mapdim) view.movie = [] for path in sorted(os.listdir("movie")): if path[0] == ".": continue view.movie.append(pygame.image.load(os.path.join("movie",path))) print "Loading units" load(view) print "Loaded! Took", pygame.time.get_ticks()/1000.0 music.fade(view)
def enter(): global verdana verdana=font.load('verdana.ttf', 50) startedOn=get_time()