Beispiel #1
0
    def start (self):
        """
         Called when the schedule is first assigned
        """
        # -- Create our input_listener 
        self.il = input.listener()

        # -- Add the listener to the manager
        input.manager.add(self.il)
        
        # -- connect the callback to handle key/control events
        self.il.connect_control_function(self.handle_controls)
        self.il.connect_keyboard_function(self.handle_keys)
Beispiel #2
0
    def start(self):
        """
         Called when the schedule is first assigned
        """
        # -- Create our input_listener
        self.il = input.listener()

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

        # -- connect the callback to handle key/control events
        self.il.connect_control_function(self.handle_controls)
        self.il.connect_keyboard_function(self.handle_keys)
Beispiel #3
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)
Beispiel #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)
Beispiel #5
0
    def main (self):
        ## Initialize the gfx and input systems
        self.init_modules (main.app.GFX | main.app.INPUT)

        ## 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(self.handle_keys)

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

        ## 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 self.Letsexit:
            input.manager.update()

        return 0
Beispiel #6
0
    def main(self):
        ## Initialize the gfx and input systems
        self.init_modules(main.app.GFX | main.app.INPUT)

        ## 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(self.handle_keys)

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

        ## 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 self.Letsexit:
            input.manager.update()

        return 0
Beispiel #7
0
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
Beispiel #8
0
    def worldtest(self):
        global handle_keys
        # -- need gfx backend for graphics
        self.init_modules(self.GFX | self.INPUT)

        # -- add data directory to python search path
        sys.path.insert(0, "data")

        # -- need this for SDL backend to work
        #gfx.screen.set_video_mode (640, 480)
        #gfx.screen.set_video_mode (1024, 768)
        gfx.screen.set_video_mode(1280, 1024)

        ## 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)

        # -- create world
        wrld = world.area()

        # -- create character
        chr = wrld.add_character("Player")

        # -- load character model from file
        chr.load("data/models/char/npc/ng.xml")

        # -- set character attributes
        chr.set_position(160, 160)
        chr.set_altitude(5)
        chr.set_speed(1.0)

        # -- set character location in world
        wrld.place_entity(0, chr)

        # -- create a ground tile
        tile = wrld.add_object()

        # -- load tile data
        tile.load("data/models/map/ground/outside/wood-1.xml")

        # -- place tile in world
        pos = world.coordinates(160, 160, 0)
        wrld.place_entity(1, pos)

        # -- create mapview
        view = world.mapview(640, 480)

        # -- set map to show
        view.set_map(wrld)

        # -- set schedule of view
        view.set_schedule("focus_on_character", ("Player", ))

        mov = {
            0: chr.EAST,
            20: chr.SOUTH,
            60: chr.WEST,
            100: chr.NORTH,
            140: chr.EAST
        }
        i = 0
        cur_mov = 0

        # -- main loop
        while not letsexit:
            if i in mov:
                # -- let character walk
                chr.remove_direction(cur_mov)
                cur_mov = mov[i]
                chr.add_direction(cur_mov)

            # -- update game clock
            event.date.update()

            # -- process world
            wrld.update()

            # -- process map view
            view.update()
            view.draw(0, 0)

            # update keys
            input.manager.update()

            # -- debugging
            chr.debug_collision(0, 0)
            print chr.x(), chr.y(), chr.z()

            # -- process gfx output
            gfx.screen.update()
            gfx.screen.clear()

            # -- keep framerate stable
            base.Timer.update()

            i = (i + 1) % 160

        return 0
Beispiel #9
0
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
Beispiel #10
0
    def worldtest (self):
        global handle_keys
        # -- need gfx backend for graphics
        self.init_modules (self.GFX| self.INPUT)
        
        # -- add data directory to python search path
        sys.path.insert (0, "data")
        
        # -- need this for SDL backend to work
        #gfx.screen.set_video_mode (640, 480)
        #gfx.screen.set_video_mode (1024, 768)
        gfx.screen.set_video_mode (1280, 1024)

    
        ## 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)


        # -- create world
        wrld = world.area ()
        
        # -- create character
        chr = wrld.add_character ("Player")
        
        # -- load character model from file
        chr.load ("data/models/char/npc/ng.xml")

        # -- set character attributes
        chr.set_position (160, 160)
        chr.set_altitude (5)
        chr.set_speed (1.0);

        # -- set character location in world
        wrld.place_entity (0, chr)

        # -- create a ground tile
        tile = wrld.add_object ()
        
        # -- load tile data
        tile.load ("data/models/map/ground/outside/wood-1.xml")
        
        # -- place tile in world
        pos = world.coordinates (160, 160, 0)
        wrld.place_entity (1, pos)

        # -- create mapview
        view = world.mapview (640, 480)
        
        # -- set map to show
        view.set_map (wrld)

        # -- set schedule of view
        view.set_schedule ("focus_on_character", ("Player",))

        mov = { 0:chr.EAST, 20:chr.SOUTH, 60:chr.WEST, 100:chr.NORTH, 140:chr.EAST }
        i = 0
        cur_mov = 0        

        # -- main loop
        while not letsexit:
           if i in mov:
               # -- let character walk
               chr.remove_direction(cur_mov)
               cur_mov = mov[i]
               chr.add_direction(cur_mov)

           # -- update game clock
           event.date.update ()
        
           # -- process world
           wrld.update ()
        
           # -- process map view
           view.update ()
           view.draw (0, 0)

           # update keys
           input.manager.update() 

           # -- debugging
           chr.debug_collision(0, 0)
           print chr.x(), chr.y(), chr.z()
           
           # -- process gfx output
           gfx.screen.update()
           gfx.screen.clear()
           
           # -- keep framerate stable
           base.Timer.update()
        
           i = (i + 1) % 160

        return 0