Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Rota em linguagem c


Bean Dragon

Pergunta

Ola galera. Eu iniciei uma engine, feita em cima de sdl2. A engine esta fluindo bem em termos gerais....

Porém tem algo me encafifando. Eu criei uma função pra traçar a rota de um objeto.. a object_route. Eu recolho as coordenadas de destino através das coordenadas do mouse no momento do click. O personagem começa a movimentação e muitas vezes termina o trajeto perfeitamente.... mas algumas vezes ele simplesmente para antes de chegar no destino. :/ Alguém poderia me ajudar a entender se existe algum erro de lógica no meu código... Muito obrigado... E aqui esta o código:

STATUS        object_route(PLACE * to,OBJECT * object,int x,int y){
  if(to==NULL||to->map==NULL||object==NULL)return(Off);
  if(object->x==x&&object->y>y){
    object->where = NORTH;
    object->y    -= object->y_speed;
    if(object->y<=y){
      object->where = NOWHERE;
      object->y     = y;
      return(On);
      }
    }
  else if(object->x==x&&object->y<y){
    object->where = SOUTH;
    object->y    += object->y_speed;
    if(object->y>=y){
      object->where = NOWHERE;
      object->y     = y;
      return(On);
      }
    }
  else if(object->x<x&&object->y==y){
    object->where = EAST;
    object->x    += object->x_speed;
    if(object->x>=x){
      object->where = NOWHERE;
      object->x = x;
      return(On);
      }
    }
  else if(object->x>x&&object->y==y){
    object->where = WEST;
    object->x    -= object->x_speed;
    if(object->x<=x){
      object->where = NOWHERE;
      object->x = x;
      return(On);
      }
    }
  else {
    if(object->x>x&&object->y>y){
      object->where = NORTHWEST;
      object->x    -= object->x_speed;
      object->y    -= object->y_speed;
      if(object->x<=x&&object->y<=y){
        object->where = NOWHERE;
        object->x     = x;
        object->y     = y;
        return(On);
        }
      if(object->x<=x){object->x = x;}
      if(object->y<=y){object->y = y;}
      }
    else if(object->x<x&&object->y>y){
      object->where = NORTHEAST;
      object->x    += object->x_speed;
      object->y    -= object->y_speed;
      if(object->x>=x&&object->y<=y){
        object->where = NOWHERE;
        object->x     = x;
        object->x     = y;
        return(On);
        }
      if(object->x>=x){object->x = x;}
      if(object->y<=y){object->y = y;}
      }
    else if(object->x<x&&object->y<y){
      object->where = SOUTHEAST;
      object->x    += object->x_speed;
      object->y    += object->y_speed;
      if(object->x>=x&&object->y>=y){
        object->where = NOWHERE;
        object->x     = x;
        object->y     = y;
        return(On);
        }
      if(object->x>=x){object->x = x;}
      if(object->y>=y){object->y = y;}
      }
    else if(object->x>x&&object->y<y){
      object->where = SOUTHWEST;
      object->x    -= object->x_speed;
      object->y    += object->y_speed;
      if(object->x<=x&&object->y>=y){
        object->where = NOWHERE;
        object->x     = x;
        object->y     = y;
        return(On);
        }
      if(object->x<=x){object->x = x;}
      if(object->y>=y){object->y = y;}
      }
    }
  if(object->x==x&&object->y==y){
    object->where = NOWHERE;
    return(On);
    }
  return(Off);
  }
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...