Example #1
0
File: game.py Project: vedun-z/pyrl
class Game():
            
    def __init__(self):
        events.init()        
        self.keymapper = Keymapper()                    
        self.tree = None
        self.grass = None
        self.hero = None
        self.skeleton = None
        self.skeleton_archer = None
        self.water = None         
        self.create_tiles()
        self.ui = UI()
        forest = LevelGenerator.generate_river_forest(
                                        90,
                                        90,
                                        self.water,
                                        self.grass,
                                        [self.tree])

        self.ui.set_current_level(forest, forest.map_width / 2,
                                   forest.map_height / 2)
                                  
        def change_camera(x, y):
            self.ui.camera_x += x 
            self.ui.camera_y += y
                    
        self.keymapper.bind_on_press(lambda :
                                      change_camera(-1, 0), pygame.K_LEFT)
        self.keymapper.bind_on_press(lambda :
                                      change_camera(+1, 0), pygame.K_RIGHT)
        self.keymapper.bind_on_press(lambda :
                                      change_camera(0, -1), pygame.K_UP)
        self.keymapper.bind_on_press(lambda :
                                      change_camera(0, +1), pygame.K_DOWN)
        
        
    def create_tiles(self):
        font = Font()        
        self.tree = Landscape(Landscape.WALL)
        font.attach_character(self.tree, "T", Color("Dark Green"))
        self.grass = Landscape(Landscape.BACKGROUND)
        font.attach_character(self.grass, "\"", Color("Green"))
        self.hero = Hero()
        font.attach_character(self.hero, "@", Color("Light Gray"))
        self.skeleton = NPC()
        font.attach_character(self.skeleton, "S", Color("Gray"))
        self.skeleton_archer = NPC()
        font.attach_character(self.skeleton_archer, "A", Color("Gray"))
        self.water = Landscape(Landscape.BACKGROUND)
        font.attach_character(self.water, "=", Color("Blue"))         
    
                

    
    def run(self):
        events.run()
Example #2
0
File: game.py Project: vedun-z/pyrl
    def __init__(self):
        events.init()        
        self.keymapper = Keymapper()                    
        self.tree = None
        self.grass = None
        self.hero = None
        self.skeleton = None
        self.skeleton_archer = None
        self.water = None         
        self.create_tiles()
        self.ui = UI()
        forest = LevelGenerator.generate_river_forest(
                                        90,
                                        90,
                                        self.water,
                                        self.grass,
                                        [self.tree])

        self.ui.set_current_level(forest, forest.map_width / 2,
                                   forest.map_height / 2)
                                  
        def change_camera(x, y):
            self.ui.camera_x += x 
            self.ui.camera_y += y
                    
        self.keymapper.bind_on_press(lambda :
                                      change_camera(-1, 0), pygame.K_LEFT)
        self.keymapper.bind_on_press(lambda :
                                      change_camera(+1, 0), pygame.K_RIGHT)
        self.keymapper.bind_on_press(lambda :
                                      change_camera(0, -1), pygame.K_UP)
        self.keymapper.bind_on_press(lambda :
                                      change_camera(0, +1), pygame.K_DOWN)