Exemplo n.º 1
0
 def initialize(self, local_state, global_state):
     for y, line in enumerate(BoulderMaze.MAZE):
         for x, cell in enumerate(line):
             if cell == 2:
                 self.add_object(Boulder(self), Position(x, y))
             elif cell == 3:
                 self.add_object(Victory(self), Position(x, y))
Exemplo n.º 2
0
    def initialize(self, local_state, global_state):
        self.add_object(LogPile(self), Position(4, 5))
        self.add_object(Tree(self), Position(6, 5))
        self.add_object(PandoraBarrel(self), Position(5, 6))
        self.add_object(SavePoint(self), Position(5, 2))

        self.inventory_context = InventoryContext(self)
        self.add_context(self.inventory_context)
Exemplo n.º 3
0
    def initialize(self, local_state, global_state):
        index = 0
        for i in range(6, 2, -1):
            for j in range(3, 1, -1):
                self.add_object(ObjectTestNPC(index), Position(i, j))
                index = (index + 1) % 8

        self.add_object(ObjectTestRock(self), Position(7, 2))
Exemplo n.º 4
0
    def initialize(self, local_state, global_state):
        self.add_area(RelativeTeleportArea(x_offset=-8, map_id=2),
                      RectangleArea((9, 0), (9, 9)))

        if local_state is not None:
            self.chest = Chest(local_state['chest_closed'])
        else:
            self.chest = Chest()
        self.add_object(self.chest, Position(5, 5))

        self.add_object(SavePoint(self), Position(6, 7))
Exemplo n.º 5
0
    def initialize(self, local_state, global_state):
        # Add yummy NPCs
        index = 0
        for i in range(6, 2, -1):
            for j in range(3, 1, -1):
                self.add_object(ObjectTestNPC(index), Position(i, j))
                index = (index + 1) % 8

        # Add rock
        self.add_object(ObjectTestRock(self), Position(7, 2))

        # Add counter
        self.object_counter = CounterContext(self)
        self.add_context(self.object_counter)
Exemplo n.º 6
0
    def initialize(self, local_state, global_state):
        self.add_area(RelativeTeleportArea(x_offset=+8, map_id=1),
                      RectangleArea((0, 0), (0, 9)))

        self.add_area(RelativeTeleportArea(x_offset=-8, map_id=3),
                      RectangleArea((9, 0), (9, 9)))

        if local_state is not None:
            self.chest = Chest(local_state['chest_closed'])
        else:
            self.chest = Chest()
        self.add_object(self.chest, Position(5, 5))

        self.add_object(SavePoint(self), Position(3, 4))
        self.add_area(AreaAroundWell(), RectangleArea((2, 3), (4, 5)))
Exemplo n.º 7
0
    def draw(self):
        party_avatar = self.map_model.party_avatar

        # Draw the background
        if party_avatar:
            party_pos = party_avatar.position
            movement_offset = self.calc_object_movement_offset(party_avatar)
            party_x_offset, party_y_offset = movement_offset
        else:
            party_pos = Position(0, 0)
            party_x_offset, party_y_offset = 0, 0
        self.bg_topleft = self.camera_mode.calc_bg_slice_topleft(
            party_pos, party_x_offset, party_y_offset)
        bg_rect = pygame.Rect(self.bg_topleft, g_cfg.screen_dimensions)
        phase = self.phase / g_cfg.animation_frame_period
        get_screen().blit(self.backgrounds[phase], (0, 0), bg_rect)

        # Draw the map objects
        self.draw_object_layer(self.map_model.below_objects)
        self.draw_object_layer(self.map_model.obstacle_objects)
        self.draw_object_layer(self.map_model.above_objects)

        # Draw the foreground
        get_screen().blit(self.foreground, (0, 0), bg_rect)

        # Update phase
        self.phase = (self.phase + 1) % (ANIMATION_PERIOD *
                                         g_cfg.animation_frame_period)
Exemplo n.º 8
0
    def activate(self, party_avatar, direction):
        print 'Activated NPC'
        for _ in xrange(2):
            step = Step(inverse(direction), back=True)
            party_avatar.schedule_movement(step)

        dialog = MessageDialog(u"Ouch!", block_movement=True)
        dialog.sync_open()

        dialog = MessageDialog(u"Hey, why are you hitting me?",
                               block_movement=True)
        dialog.sync_open()

        def on_choice(user_data, choice):
            map = user_data
            msg = MessageDialog('on_choice got %d' % (choice + 1))
            map.schedule_message(msg)
        dialog = ChoiceDialog(u"Choose NOW:",
                              ["Choice 1", "Choice 2", "Choice 3", "Choice 4"],
                              user_data=self.map,
                              completion_callback=on_choice,
                              block_movement=True)
        dialog.sync_open()

        dialog = MessageDialog(u"Chose %d" % (dialog.result + 1),
                               block_movement=True)
        dialog.sync_open()

        movement = PathMovement(self.map, party_avatar, Position(9, 4))
        party_avatar.schedule_movement(movement)
Exemplo n.º 9
0
 def __init__(self, save_file=None):
     maps = {1: Map1, 2: Map2, 3: Map3}
     World.__init__(self, maps=maps, character_factory=char_factory)
     if save_file is None:
         self.initial_state(map=1, position=Position(5, 4), chars=['Andy'])
     else:
         self.load_state(state_file=save_file)
Exemplo n.º 10
0
 def __mouse_movement(self, pos):
     target_x, target_y = self.map_view.calc_pos_from_mouse(pos)
     if self.map_model.terrain_layer.valid((target_x, target_y)):
         movement = PathMovement(self.map_model,
                                 self.map_model.party_avatar,
                                 Position(target_x, target_y))
         self.map_model.party_avatar.schedule_movement(movement)
Exemplo n.º 11
0
 def __getitem__(self, index):
     if self.cur_y > self.bottom:
         raise IndexError('Finished')
     result = Position(self.cur_x, self.cur_y)
     self.cur_x += 1
     if self.cur_x > self.right:
         self.cur_x = self.left
         self.cur_y += 1
     return result
Exemplo n.º 12
0
 def initialize(self, local_state, global_state):
     self.add_object(ObjectTestNPC(), Position(2, 2))
     self.add_object(ObjectTestChest(), Position(8, 4))
     self.add_object(ObjectTestRock(self), Position(7, 2))
     self.add_object(ObjectTestTowerUpper(self), Position(6, 0))
     self.add_object(ObjectTestTowerLower(self), Position(6, 1))
     self.add_object(ObjectTestCity(self), Position(7, 1))
     self.add_object(ObjectTestGameOverBarrel(self), Position(9, 9))
Exemplo n.º 13
0
def main():
    librpg.init('Object Test')
    librpg.config.graphics_config.config(tile_size=32, object_height=32,
                                         object_width=32)

    world = MicroWorld(ObjectTestMap(), char_factory)
    world.initial_state(Position(0, 0), ['Andy'])
    world.gameloop()

    exit()
Exemplo n.º 14
0
    def initialize(self, local_state, global_state):
        self.add_object(GameOverBarrel(self), Position(6, 4))

        self.add_area(RelativeTeleportArea(x_offset=+8, map_id=2),
                      RectangleArea((0, 0), (0, 9)))

        self.add_area(RelativeTeleportArea(y_offset=+8),
                      RectangleArea((0, 0), (9, 0)))
        self.add_area(RelativeTeleportArea(y_offset=-8),
                      RectangleArea((0, 9), (9, 9)))
Exemplo n.º 15
0
def main():
    librpg.init('Boulder Test')
    librpg.config.graphics_config.config(tile_size=32,
                                         object_height=32,
                                         object_width=32,
                                         scale=1.7)

    world = librpg.world.MicroWorld(BoulderMaze(), char_factory)
    world.initial_state(position=Position(4, 9), chars=['Andy'])
    world.gameloop()
    exit()
Exemplo n.º 16
0
def main():
    librpg.init()
    librpg.config.graphics_config.config(tile_size=16,
                                         object_height=32,
                                         object_width=24)

    game_config.config(fps=40)
    world = librpg.world.MicroWorld(ObjectTestMap(), char_factory)
    world.initial_state(Position(8, 8), ['Andy'])
    world.gameloop()

    exit()
Exemplo n.º 17
0
 def __str__(self):
     result = ''
     result += '+' + '-' * self.width + '+\n'
     for y in range(self.height):
         result += '|'
         for x in range(self.width):
             if self.party_avatar is not None and\
                self.party_avatar.position == Position(x, y):
                 result += 'P'
             else:
                 result += ' '
         result += '|\n'
     result += '+' + '-' * self.width + '+\n'
     return result
Exemplo n.º 18
0
def main():
    librpg.init('Item Persist Test')
    librpg.config.graphics_config.config(tile_size=32,
                                         object_height=32,
                                         object_width=32,
                                         scale=2,
                                         screen_width=480,
                                         screen_height=320)
    librpg.config.menu_config.config(theme=ClassicMenuTheme())

    world = MicroWorld(PersistTestMap(), char_factory, party_factory)
    if SAVE_FILE in os.listdir('.'):
        world.load_state(SAVE_FILE)
    else:
        world.initial_state(Position(4, 3),
                            chars=['Andy', 'Brenda', 'Charles', 'Dylan'],
                            party_capacity=3,
                            party=['Andy'])
    world.gameloop()
    exit()
Exemplo n.º 19
0
 def party_entered(self, party_avatar, position):
     position = Position(position.x + self.x_offset,
                         position.y + self.y_offset)
     party_avatar.map.schedule_teleport(position, self.map_id,
                                        *self.map_args)