How to use the rpg.MovePlayer function in rpg

To help you get started, we’ve selected a few rpg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davexunit / CocosRPG / rpg.py View on Github external
if self.collide_player(new) or self.check_collision(new):
                self.dx = 0
            # Test for collision along y axis
            new = last.copy()
            new.y += self.dy * dt
            if self.collide_player(new) or self.check_collision(new):
                self.dy = 0
        else:
            self.target.walking = False

        # Set new velocity
        self.target.velocity = (self.dx, self.dy)
        # Get objects that sprite is currently over before moving
        old_objects = map['objects'].get_in_region(self.target.get_hitbox())
        # Move
        super(MovePlayer, self).step(dt)
        # Get objects that sprite is currently over after moving
        new_objects = map['objects'].get_in_region(self.target.get_hitbox())
        # Call on_object_enter event handler for any object that is in the new list but not in the old list
        for obj in new_objects:
            if obj not in old_objects:
                obj.on_object_enter(self.target)
        # Call on_object_exit event handler for any object that is in the old list but not in the new list
        for obj in old_objects:
            if obj not in new_objects:
                    obj.on_object_exit(self.target)
        # Focus scrolling layer on player
        map.set_focus(self.target.x, self.target.y)
        # Y sort
        map['objects'].remove_object(self.target)
        map['objects'].add_object(self.target)
github davexunit / CocosRPG / rpg.py View on Github external
# Add resource file paths
    pyglet.resource.path.append('data')
    pyglet.resource.path.append('data/images')
    pyglet.resource.path.append('data/maps')
    pyglet.resource.path.append('data/anims')
    pyglet.resource.reindex()
    # Open database
    db = sqlite3.connect(utility.resource_path('database'))
    # Load map
    map = loadmap.Map('outside.tmx', db)
    # Load animation
    anims = loadmap.load_animset('king.xml')
    # Setup player sprite
    player = create_sprite(450, 200)
    action = player.do(MovePlayer())
    # Add objects to map
    map['objects'].add_object(player)
    dialog_layer = make_dialog_box()
    # Create the main scene
    main_scene = cocos.scene.Scene(map)
    # Handle input
    keyboard = key.KeyStateHandler()
    director.window.push_handlers(keyboard)

    state = "walkaround"
    def on_key_press(key, modifier):
        global state # is bad
        global action # is needed
        if state == "walkaround":
            if key == pyglet.window.key.SPACE:
                dialog = None
github davexunit / CocosRPG / rpg.py View on Github external
dialog = s
                            break
                if dialog != None:
                    dialog.on_interact(player)
                    state = "dialog"
                    player.remove_action(action)
                    player.walking = False
                    label = cocos.text.Label(dialog.text, font_name='DroidSans', font_size=16, multiline=True, width=dialog_layer.px_width)
                    label.position = (16, dialog_layer.px_height - 16) 
                    label.element.anchor_y = 'top'
                    dialog_layer.add(label, name='label')
                    main_scene.add(dialog_layer, z=1)
        elif state == "dialog":
            if key == pyglet.window.key.SPACE:
                state = "walkaround"
                action = player.do(MovePlayer())
                main_scene.remove(dialog_layer)
                dialog_layer.remove('label')
github davexunit / CocosRPG / rpg.py View on Github external
def on_mouse_press (x, y, buttons, modifiers):
        if state == "walkaround":
            # Add a sprite to screen at the mouse location on right click
            if buttons & mouse.RIGHT:
                new_sprite = create_sprite(*map.pixel_from_screen(x, y))
                map['objects'].add_object(new_sprite)
            # Left click changes sprite that player is controlling
            elif buttons & mouse.LEFT:
                global player, action
                for s in map['objects'].get_objects():
                    if isinstance(s, Character) and s.get_rect().contains(*map.pixel_from_screen(x, y)):
                        player.remove_action(action)
                        player = s
                        action = player.do(MovePlayer())
                        break