I have another stupid question..
I want to make a moving object inside of a maze, using Tims build. (from the tuts)
I figured out that if I want to find a way out of a maze, I should follow one of the walls (left or right), then every time when I reach a wall in front of me I will just check the next direction (if right is a wall, I would go down etc).
I know that in function OnMove, we check for collision at every new position.
I'm talking about this:
- Code: Select all
if(PosValid((int)(X + NewX), (int)(Y))){
X += NewX;
}
else
{
SpeedX = 0;
}
if(PosValid((int)(X), (int)(Y + NewY)))
{
Y += NewY;
}
else
{
SpeedY = 0;
}
I change it like this:
- Code: Select all
if( PosValid( (int)(X + NewX), (int)(Y) ) ){
X += NewX;
}
else{
SpeedX = 0;
if( PosValid( (int)(X), (int)(Y + NewY) ) ){
Y += NewY;
}
else{
SpeedY = 0;
if( PosValid( (int)(X + NewX), (int)(Y) ) ){
X -= NewX;
}
else{
SpeedX = 0;
if( PosValid( (int)(X), (int)(Y + NewY) ) ){
Y -= NewY;
}
else{
SpeedY = 0;
}
}
}
}
if( PosValid( (int)(X), (int)(Y-NewY) ) ){
Y += NewY;
}
else{
SpeedY = 0;
if( PosValid( (int)(X-NewY), (int)(Y) ) ){
X -= NewX;
}
else{
SpeedX = 0;
if( PosValid( (int)(X), (int)(Y + NewY) ) ){
Y -= NewY;
}
else{
SpeedY = 0;
if( PosValid( (int)(X+NewX), (int)(Y) ) ){
X -= NewX;
}
else{
SpeedX = 0;
}
}
}
}
Then in the CEntity::OnLoop I move right by 1:
- Code: Select all
OnMove(1, 0);
When I run the program, the player walks to the right side, until he collides with a wall.
After that nothing happens.
I can't figure out, how can I change the direction after the object collides with a wall..

