Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Lísias de Castro

Rota em linguagem c

Recommended Posts

Ola galera.

Estou com uma duvida insolente

Estou desenvolvendo uma engine em cima do sdl2.

A maioria da parada já ta pelo.

Porém, eu fiz uma função nomeada object_route.

Que move as coordenas cartesianas do objeto até

que chegue em seu destino.

A função funciona. Porém, muitas vezes não executa a rota com precisão,

muitas vezes dando-se por completa no meio do caminho.

Se alguém conseguir localizar o erro de lógica eu agradeço.

Ass: Mister Bean

 

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;}
}
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;}
}
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;}
}
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);
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.