Example #1
0
 def test_get(self):
     obj1 = Object('Test1')
     add_object(obj1)
     obj2 = Object('Test2')
     add_object(obj2)
     
     self.assertEqual(obj1, get_object('Test1'))
     self.assertEqual(obj2, get_object('Test2'))
     self.assertEqual(None, get_object('Test3'))
     
     
Example #2
0
 def __init__(self, name, object_name, font_name, font_size, font_color=(255, 255, 255), x=0, y=0, size_x=0, size_y=0):
     Widget.__init__(self, name, x, y)
     
     self.object_name = object_name
     obj = get_object(object_name)
     
     if obj is not None and 'EquipmentSlots' in obj.components:            
         self.character = obj.components['EquipmentSlots']
     else:
         self.character = None
     
     self.image = None     
     
     self.font_name = font_name 
     self.font_size = font_size
     self.font_color = font_color
     
     self.space_x = 10
     self.space_y = 10
     
     self.size_x = size_x
     self.size_y = size_y
     
     self.on_b1_up = None
     self.on_b2_up = None
     
     self.must_update = True
Example #3
0
 def __init__(self, name, object_name, font_name, font_size, font_color=(255, 255, 255), x=0, y=0, size_x=0, size_y=0):
     Widget.__init__(self, name, x, y)
     
     self.object_name = object_name
     obj = get_object(object_name)
     
     if obj is not None and 'Inventory' in obj.components:            
         self.inventory = obj.components['Inventory']
     else:
         self.inventory = None
     
     self.image = None     
     
     self.font_name = font_name 
     self.font_size = font_size
     self.font_color = font_color
     
     self.space_x = 10
     self.space_y = 10
     
     self.size_x = size_x
     self.size_y = size_y
     
     self.active = 0
     self.start = 0
     self.length = 6
     
     self.on_b1_up = None
     self.on_b2_up = None
     
     self.must_update = True
Example #4
0
def main():
    global map, hero
    
    pygame.init()
    screen = pygame.display.set_mode((1400, 1100))
    pygame.display.set_caption('Pyro 0.0.07')
    
    utility.Path.create()
    
    add_function('Quit', quit)    
    add_function('Use', use)
    add_function('Wait', lambda: can_wait(hero))
    add_function('PickUp', lambda: can_pick_up(hero))
    add_function('Up', lambda: move(2))
    add_function('Down', lambda: move(0))
    add_function('Left', lambda: move(3))
    add_function('Right', lambda: move(1))
    
    utility.Input.bind_key_up(K_ESCAPE, 'Quit')
    utility.Input.bind_key_up(K_e, 'Use')
    utility.Input.bind_key_up(K_p, 'PickUp')
    utility.Input.bind_key_up(K_SPACE, 'Wait')
    utility.Input.bind_key_up(K_UP, 'Up')
    utility.Input.bind_key_up(K_DOWN, 'Down')
    utility.Input.bind_key_up(K_LEFT, 'Left')
    utility.Input.bind_key_up(K_RIGHT, 'Right')
    utility.Input.bind_key_up(K_w, 'Up')
    utility.Input.bind_key_up(K_s, 'Down')
    utility.Input.bind_key_up(K_a, 'Left')
    utility.Input.bind_key_up(K_d, 'Right')
    
    resource.Image.init()    
    resource.Tile.init('tiles.txt')    
    init_celltypes('cell_types.txt')    
    init_behaviors('behaviors.txt')
    init_templates('templates.txt')      
    
    init_maps()
    map = load_map('test', 'map.txt')
    
    hero = get_object('Hero_0')
    hero.add_component(Player())
    
    gui.Gui.init()
    active_gui = gui.Gui.load_gui('main', 'pyro.txt', screen)
    utility.Input.add_mouse_listener(active_gui) 
    
    active_gui.get_widget('MapViewer').on_b1_up = attack
    active_gui.get_widget('MapViewer').on_b2_up = sound
    label_hp = active_gui.get_widget('HP')
    label_damage = active_gui.get_widget('Damage')
    
    char = hero.components['Character']
    health = hero.components['Health']
    
    clock = pygame.time.Clock()
    
    while running:
        clock.tick(5)
        utility.Input.update()
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                quit()
            elif event.type == KEYDOWN:
                utility.Input.on_key_down(event.key)
            elif event.type == KEYUP:
                utility.Input.on_key_up(event.key)
            elif event.type == MOUSEBUTTONUP:
                utility.Input.on_mouse_up(event.button, event.pos[0], event.pos[1])
            elif event.type == MOUSEBUTTONDOWN:
                utility.Input.on_mouse_down(event.button, event.pos[0], event.pos[1])
        
        map.update()
        
        label_hp.set_text('%d / %d' % (health.get_health(), health.get_max_health()))
        label_damage.set_text('%d / %d' % (char.get_weapon_damage(), char.get_armor()))
            
        screen.fill((50, 50, 50))
        
        active_gui.draw()
        
        pygame.display.flip()