Ejemplo n.º 1
0
def handle_mouse_click(evt):
    context = evt.context
    if evt.state == MouseClickEvent.State.up and context.player:

        LOG.debug('Action: {}'.format(evt))
        LOG.debug('Viewport pos: {},{}'.format(evt.x, evt.y))

        renderer_conf = context.conf['Renderer']
        w = int(renderer_conf['width'])
        h = int(renderer_conf['height'])

        x, y = evt.x, evt.y
        camera = context.camera

        target = ray_cast(x, y, w, h, camera)
        world_pos = to_world(target.x, target.y, target.z)
        LOG.debug('World pos: {}'.format(world_pos))
        pos = world_pos.x, world_pos.y

        if context.game_mode == context.GameMode.default:
            c_pos, ray = camera.trace_ray(x, y, w, h)
            entity = context.pick_entity(c_pos, ray)
            if entity:
                # step 1 - try to pick entities
                entity_picked(context, entity)
            else:
                # step 2 - just find the destination and start a movement
                start_move_action(context, pos)
        elif context.game_mode == context.GameMode.building:
            start_build_action(context, pos)
Ejemplo n.º 2
0
def handle_mouse_click(evt):
    context = evt.context
    if evt.state == MouseClickEvent.State.up and context.player:

        LOG.debug('Action: {}'.format(evt))
        LOG.debug('Viewport pos: {},{}'.format(evt.x, evt.y))

        renderer_conf = context.conf['Renderer']
        w = int(renderer_conf['width'])
        h = int(renderer_conf['height'])

        x, y = evt.x, evt.y
        camera = context.camera

        target = ray_cast(x, y, w, h, camera)
        world_pos = to_world(target.x, target.y, target.z)
        LOG.debug('World pos: {}'.format(world_pos))
        pos = world_pos.x, world_pos.y

        if context.game_mode == context.GameMode.default:
            c_pos, ray = camera.trace_ray(x, y, w, h)
            entity = context.pick_entity(c_pos, ray)
            if entity:
                # step 1 - try to pick entities
                entity_picked(context, entity)
            else:
                # step 2 - just find the destination and start a movement
                start_move_action(context, pos)
        elif context.game_mode == context.GameMode.building:
            start_build_action(context, pos)
Ejemplo n.º 3
0
def place_building_template(context, x, y):
    """Places the template building on the world.

    :param context: The game context.
    :type context: :class:`context.Context`

    :param x: The non-clamped x-axis coordinate.
    :type x: int

    :param y: The non-clamped y-ayis coordinate.
    :type y: int
    """
    map_res = context.res_mgr.get('/map')

    renderer_conf = context.conf['Renderer']
    w = int(renderer_conf['width'])
    h = int(renderer_conf['height'])
    camera = context.camera

    target = ray_cast(x, y, w, h, camera)
    world_pos = to_world(target.x, target.y, target.z)
    pos = clamp_to_grid(world_pos.x, world_pos.y, map_res.data['scale_factor'])
    context.building_template.pos = pos
Ejemplo n.º 4
0
def place_building_template(context, x, y):
    """Places the template building on the world.

    :param context: The game context.
    :type context: :class:`context.Context`

    :param x: The non-clamped x-axis coordinate.
    :type x: int

    :param y: The non-clamped y-ayis coordinate.
    :type y: int
    """
    map_res = context.res_mgr.get('/map')

    renderer_conf = context.conf['Renderer']
    w = int(renderer_conf['width'])
    h = int(renderer_conf['height'])
    camera = context.camera

    target = ray_cast(x, y, w, h, camera)
    world_pos = to_world(target.x, target.y, target.z)
    pos = clamp_to_grid(
            world_pos.x, world_pos.y, map_res.data['scale_factor'])
    context.building_template.pos = pos
Ejemplo n.º 5
0
 def mouse_vip(self, mouse_pos):
     self.vip.move_to(utils.to_world(mouse_pos))