コード例 #1
0
ファイル: movement.cpp プロジェクト: tryzombie501/anaconda
void PathMovement::update(float dt)
{
    node_changed = false;
    if (current_node < 0) {
        instance->set_animation(STOPPED);
        return;
    }
    instance->set_animation(WALKING);
    PathNode & node = nodes[current_node];
    float m = get_pixels(speed) * instance->frame->timer_mul;
    float move_dist = std::min<float>(m, distance_left);
    float move_val = move_dist * dir;
    int old_x = instance->x;
    int old_y = instance->y;
    move(node.dir_x * move_val, node.dir_y * move_val);
    start_x -= instance->x - old_x;
    start_y -= instance->y - old_y;
    distance_left -= move_dist;
    if (distance_left <= 0.0f) {
        int final_x = instance->x + start_x + node.x * dir;
        int final_y = instance->y + start_y + node.y * dir;
        instance->set_position(final_x, final_y);
        add_x = add_y = 0;
        start_x = start_y = 0;
        node_changed = true;
        int next_node = current_node+dir;
        bool is_last = next_node == nodes.size() || next_node == -1;
        if (!is_last) {
            set_current_node(next_node);
            return;
        }
        if (has_reverse && dir == 1) {
            dir = -1;
            set_current_node(current_node);
            return;
        }
        if (!has_reverse && dir == 1)
            move(-end_x, -end_y);
        if (!loop) {
            current_node = -2;
            return;
        }
        if (has_reverse || dir == -1)
            dir = -dir;
        next_node = (current_node+dir) % nodes.size();
        set_current_node(next_node);
    }
}
コード例 #2
0
ファイル: movement.cpp プロジェクト: tryzombie501/anaconda
void PathMovement::start()
{
    if (current_node == -1)
        set_current_node(0);
    else if (current_node == -2)
        return;
    else
        set_speed(nodes[current_node].speed);
}
コード例 #3
0
ファイル: movement.cpp プロジェクト: tryzombie501/anaconda
void PathMovement::reverse()
{
    dir = -dir;
    if (current_node >= 0) {
        PathNode & node = nodes[current_node];
        distance_left = node.length - distance_left;
        start_x += node.x * -dir;
        start_y += node.y * -dir;
        return;
    }
    int n;
    if (dir == 1)
        n = 0;
    else
        n = nodes.size() - 1;
    set_current_node(n);
}
コード例 #4
0
static int shell_init(MYX_GRT *grt)
{
  MYX_GRT_MODULE_LOADER *loader;
  MYX_GRT_SHELL_PRIVATE *priv;
  
  // The Python module loader must be initialized before the shell
  loader= myx_grt_get_loader_of_type(grt, MYX_PYTHON_MODULE_TYPE);
  if (!loader)
    return -1;

  priv= grt->shell->data;
  
  priv->cwd= g_strdup("/");
  priv->pycon= loader->priv;

  myx_py_acquire(priv->pycon);
  set_current_node(grt, grt->root);
  myx_py_release(priv->pycon);
  
  return 0;
}
コード例 #5
0
PyObject *myx_py_grt_cd(PyObject *self, PyObject *args)
{
  MYX_GRT *grt= myx_py_get_grt()->grt;
  char *path= NULL;
  MYX_GRT_VALUE *curnode;

  if (!PyArg_ParseTuple(args, "s", &path))
    return NULL;

  path= myx_grt_get_abspath(grt->shell->data->cwd, path);
  if (!path)
  {
    PyErr_SetString(PyExc_ValueError, "invalid path");
    return NULL;
  }
  curnode= myx_grt_dict_item_get_by_path(grt, grt->root, path);

  if (!curnode)
  {
    PyErr_Format(PyExc_ValueError, "invalid path '%s'", path);
    return NULL;
  }
  
  if (myx_grt_value_get_type(curnode) != MYX_DICT_VALUE &&
      myx_grt_value_get_type(curnode) != MYX_LIST_VALUE)
  {
    PyErr_Format(PyExc_ValueError, "can't cd into '%s'", path);
    return NULL;
  }

  if (set_current_node(grt, curnode) < 0)
    return NULL;

  g_free(grt->shell->data->cwd);
  grt->shell->data->cwd= path;

  Py_INCREF(Py_None);
  return Py_None;
}