Exemplo n.º 1
0
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)
Exemplo n.º 2
0
ship.init(root)
item.init(root)
primitives.init(root)
tasks.init(root)
ai.init(root)
ui_states.init(root)
sectors.init(root)
newgame.init(root)
dialog.init(root)
quests.init(root)
eb.init_grufs(root)
faction.init(root)
lang.init()

import music
music.init()

root.gfxcursor = gfxcursor.GfxCursor(root, root.screen.screen)

root.particlemanager = particles.ParticleManager()

root.state_manager = state.StateManager(root)
root.console = pyconsole.Console(screen.image, (0, 0, 1300, 200),
                                 localsx=locals())

root.igconsole = overlay_gui.IngameRenderedConsole(root, 5)
root.igconsole.enable_debug()

root.game_time = 0
root.fps = 999
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
import music
import versusclient
import versusserver
import stageselect
import credits
import serverselect

import gamestate
import serializability

if __name__ == "__main__":
    multiprocessing.freeze_support()
    gamestate.init_pygame_vars()
    screen = gamestate.screen
    pygame.display.set_caption("Way of the Stick")
    music.init()
    
    if len(sys.argv) >= 2 and sys.argv[1] == "dev":
        gamestate.devmode = True
    
    while 1:
        try:
            if gamestate.drawing_mode == gamestate.DrawingModes.UPDATE_ALL:
                screen.fill((0,0,0))
            
            gamestate.update_time()
            wotsuievents.get_events()
            
            events = wotsuievents.events
            event_types = wotsuievents.event_types
            mousePos = wotsuievents.mouse_pos