コード例 #1
0
def gfxtest():
    if not gfx.init("sdl"): raise "Can't load gfx backend!"
    gfx.screen.set_video_mode(640, 480)
    image = gfx.animation()
    image.load_animation("foo")
    image.save_animation("naked_guy.xml")
    return 0
コード例 #2
0
ファイル: gfxsave.py プロジェクト: artes-liberales/adonthell
def gfxtest ():
    if not gfx.init("sdl"): raise "Can't load gfx backend!"
    gfx.screen.set_video_mode(640, 480)
    image = gfx.animation()
    image.load_animation("foo")
    image.save_animation("naked_guy.xml")
    return 0
コード例 #3
0
ファイル: guitest.py プロジェクト: artes-liberales/adonthell
def guitest ():
    ## Initialize the gfx and input systems
    if not gfx.init("sdl"): raise "Can't load gfx backend!"
    if not input.init("sdl"): raise "Can't load input backend!"
    
    ## Set us a nice window
    gfx.screen.set_video_mode(640, 480)

    ## Create our input_listener and connect the callback
    ## to handle keyboard events
    il = input.listener()
    il.connect_keyboard_function(handle_keys)

    ## Add the listener to the manager
    input.manager.add(il)

    ## gui stuff
    cont = gui.container ()
    cont.set_size (150, 150)
    cont.set_location (20, 30)

    a = dict ()
    for i in range (0,7):
    	a[i] = gui.base ()
	a[i].set_size (40,20)
	a[i].set_location (30, 10)
	cont.add_child (a[i])
  
    # set the layout
    cont.set_extend_policy (2)
    z = gui.listlayout ()
    cont.set_layout (z)

    
    ## Run this loop until letsexit is set to 1 by the
    ## callback function. Every time a key event is raised,
    ## the input manager will send it to the listeners it handles
    ## (that is, only the one we've connected) which will call the
    ## callback function that has been connected to handle keyboard events.
    while not letsexit:
        gfx.screen.update ()
        input.manager.update()
        #gfx.screen.draw ()
        cont.update ()
        cont.draw ()
        
    ## Do some cleanup, and we're ready to exit!
    input.cleanup()
    gfx.cleanup()

    sys.exit(0)
コード例 #4
0
def guitest():
    ## Initialize the gfx and input systems
    if not gfx.init("sdl"): raise "Can't load gfx backend!"
    if not input.init("sdl"): raise "Can't load input backend!"

    ## Set us a nice window
    gfx.screen.set_video_mode(640, 480)

    ## Create our input_listener and connect the callback
    ## to handle keyboard events
    il = input.listener()
    il.connect_keyboard_function(handle_keys)

    ## Add the listener to the manager
    input.manager.add(il)

    ## gui stuff
    cont = gui.container()
    cont.set_size(150, 150)
    cont.set_location(20, 30)

    a = dict()
    for i in range(0, 7):
        a[i] = gui.base()
        a[i].set_size(40, 20)
        a[i].set_location(30, 10)
        cont.add_child(a[i])

    # set the layout
    cont.set_extend_policy(2)
    z = gui.listlayout()
    cont.set_layout(z)

    ## Run this loop until letsexit is set to 1 by the
    ## callback function. Every time a key event is raised,
    ## the input manager will send it to the listeners it handles
    ## (that is, only the one we've connected) which will call the
    ## callback function that has been connected to handle keyboard events.
    while not letsexit:
        gfx.screen.update()
        input.manager.update()
        #gfx.screen.draw ()
        cont.update()
        cont.draw()

    ## Do some cleanup, and we're ready to exit!
    input.cleanup()
    gfx.cleanup()

    sys.exit(0)
コード例 #5
0
def convert():
    """ convert either animation or mapobject """
    
    file = sys.argv[1]
    
    old_gfx = base.igzstream ()
    old_gfx.open (file)
    
    if not old_gfx.is_open ():
        print "Cannot open file", file
        sys.exit (1)

    gfx.init ("sdl")
    gfx.screen.set_video_mode (640, 480)
    
    filename, ext = os.path.splitext (file)
    if ext == ".mobj":
        print "Mapobject found"
        convert_mapobject (old_gfx, filename)
        
    elif ext == ".anim":
        print "Animation found"
        convert_anim (old_gfx, filename)
    
    elif ext == ".img":
        print "Image found"
        convert_raw_image (old_gfx, filename)
    
    elif ext == ".mchar":
        print "Character found"
        convert_character (old_gfx, filename)
        
    else:
        print "File extension '%s' not recognized" % ext
        print "Valid extensions are .anim, .img, .mobj and .mchar"
        
    return 0
コード例 #6
0
def convert():
    """ convert either animation or mapobject """

    file = sys.argv[-1]

    old_gfx = base.igzstream()
    old_gfx.open(file)

    if not old_gfx.is_open():
        print "Cannot open file", file
        sys.exit(1)

    gfx.init("sdl")
    gfx.screen.set_video_mode(640, 480)

    filename, ext = os.path.splitext(file)
    if ext == ".mobj":
        print "Mapobject found"
        convert_mapobject(old_gfx, filename)

    elif ext == ".anim":
        print "Animation found"
        convert_anim(old_gfx, filename)

    elif ext == ".img":
        print "Image found"
        convert_raw_image(old_gfx, filename)

    elif ext == ".mchar":
        print "Character found"
        convert_character(old_gfx, filename)

    else:
        print "File extension '%s' not recognized" % ext
        print "Valid extensions are .anim, .img, .mobj and .mchar"

    return 0
コード例 #7
0
ファイル: gfxtest.py プロジェクト: artes-liberales/adonthell
def gfxtest ():
    global screenshot, walkdir
    
    #setup key handler
    def key_callback(ev):
        global letsexit, walkdir, screenshot
        if ev.type() == input.keyboard_event.KEY_PUSHED:
            if ev.key() == input.keyboard_event.ESCAPE_KEY: letsexit = 1
            elif ev.key() == input.keyboard_event.LEFT_KEY: walkdir = 'walk_west'
            elif ev.key() == input.keyboard_event.RIGHT_KEY: walkdir = 'walk_east'
            elif ev.key() == input.keyboard_event.UP_KEY: walkdir = 'walk_north'
            elif ev.key() == input.keyboard_event.DOWN_KEY: walkdir = 'walk_south'
            elif ev.key() == input.keyboard_event.F8_KEY: screenshot = True
        elif ev.type() == input.keyboard_event.KEY_RELEASED:
            if ev.key() == input.keyboard_event.LEFT_KEY and walkdir == 'walk_west': walkdir = "stand" + walkdir[4:]
            elif ev.key() == input.keyboard_event.RIGHT_KEY and walkdir == 'walk_east': walkdir = "stand" + walkdir[4:]
            elif ev.key() == input.keyboard_event.UP_KEY and walkdir == 'walk_north': walkdir = "stand" + walkdir[4:]
            elif ev.key() == input.keyboard_event.DOWN_KEY and walkdir == 'walk_south': walkdir = "stand" + walkdir[4:]
        return 1

    if not gfx.init("sdl"): raise "Can't load gfx backend!"
    if not input.init("sdl"): raise "Can't load input backend!"

    gfx.screen.set_video_mode(640, 480)

    li = input.listener()
    li.connect_keyboard_function(key_callback)
    input.manager.add(li)

    xloc = 10
    yloc = 10
    
    #setup a 'fake' background
    background = gfx.create_surface()
    background.thisown = 0
    background.resize(640,480)
    backgroundcolor = [
    0x000000,0xFF0000,0x00FF00,0x0000FF,
    0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF,
    0x7FFF00,0x007FFF,0xFF007F,0xFF7FFF]
    for x in xrange(4):
        for y in xrange(3):
            background.fillrect(160*x,160*y,160,160,backgroundcolor[0])
            backgroundcolor = backgroundcolor[1:]
            
    #load an image... gfx must be checked out and linked
    image = gfx.animation()
    image.load_animation("gfx/character/npc/naked_guy/naked_guy.xml")
    count = 0
    oldwalkdir = None
    while not letsexit:
        count += 1
        input.manager.update()
        if(walkdir != oldwalkdir):
            oldwalkdir = walkdir
            image.change_animation(walkdir)
        background.draw(0,0)
        image.draw(xloc,yloc)
        if count == 10: image.update(); count = 0
        
        if screenshot:
            print "saving screenshot to 'screenshot.png'"
            screenshot = False
            ssurface = gfx.screen.get_surface()
            ssurface.save_png("screenshot.png")
        
        gfx.screen.update()

    input.cleanup()
    gfx.cleanup()
    return 0
コード例 #8
0
ファイル: gfxtest.py プロジェクト: peppapiggyme/adonthell
def gfxtest():
    global screenshot, walkdir

    #setup key handler
    def key_callback(ev):
        global letsexit, walkdir, screenshot
        if ev.type() == input.keyboard_event.KEY_PUSHED:
            if ev.key() == input.keyboard_event.ESCAPE_KEY: letsexit = 1
            elif ev.key() == input.keyboard_event.LEFT_KEY:
                walkdir = 'walk_west'
            elif ev.key() == input.keyboard_event.RIGHT_KEY:
                walkdir = 'walk_east'
            elif ev.key() == input.keyboard_event.UP_KEY:
                walkdir = 'walk_north'
            elif ev.key() == input.keyboard_event.DOWN_KEY:
                walkdir = 'walk_south'
            elif ev.key() == input.keyboard_event.F8_KEY:
                screenshot = True
        elif ev.type() == input.keyboard_event.KEY_RELEASED:
            if ev.key(
            ) == input.keyboard_event.LEFT_KEY and walkdir == 'walk_west':
                walkdir = "stand" + walkdir[4:]
            elif ev.key(
            ) == input.keyboard_event.RIGHT_KEY and walkdir == 'walk_east':
                walkdir = "stand" + walkdir[4:]
            elif ev.key(
            ) == input.keyboard_event.UP_KEY and walkdir == 'walk_north':
                walkdir = "stand" + walkdir[4:]
            elif ev.key(
            ) == input.keyboard_event.DOWN_KEY and walkdir == 'walk_south':
                walkdir = "stand" + walkdir[4:]
        return 1

    if not gfx.init("sdl"): raise "Can't load gfx backend!"
    if not input.init("sdl"): raise "Can't load input backend!"

    gfx.screen.set_video_mode(640, 480)

    li = input.listener()
    li.connect_keyboard_function(key_callback)
    input.manager.add(li)

    xloc = 10
    yloc = 10

    #setup a 'fake' background
    background = gfx.create_surface()
    background.thisown = 0
    background.resize(640, 480)
    backgroundcolor = [
        0x000000, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF,
        0xFFFFFF, 0x7FFF00, 0x007FFF, 0xFF007F, 0xFF7FFF
    ]
    for x in xrange(4):
        for y in xrange(3):
            background.fillrect(160 * x, 160 * y, 160, 160, backgroundcolor[0])
            backgroundcolor = backgroundcolor[1:]

    #load an image... gfx must be checked out and linked
    image = gfx.animation()
    image.load_animation("gfx/character/npc/naked_guy/naked_guy.xml")
    count = 0
    oldwalkdir = None
    while not letsexit:
        count += 1
        input.manager.update()
        if (walkdir != oldwalkdir):
            oldwalkdir = walkdir
            image.change_animation(walkdir)
        background.draw(0, 0)
        image.draw(xloc, yloc)
        if count == 10:
            image.update()
            count = 0

        if screenshot:
            print "saving screenshot to 'screenshot.png'"
            screenshot = False
            ssurface = gfx.screen.get_surface()
            ssurface.save_png("screenshot.png")

        gfx.screen.update()

    input.cleanup()
    gfx.cleanup()
    return 0