// remember the start position
if(MT.bp(0))
{
startPos = MT.pos(0);
}
// at release compare with the start position and choose the
// direction which has the biggest distance
if(MT.br(0))
{
float xDistance = Abs(MT.smoothPos(0).x - MT.startPos(0).x);
float yDistance = Abs(MT.smoothPos(0).y - MT.startPos(0).y);
if(xDistance > yDistance)
{
if(MT.startPos(0).x < MT.smoothPos(0).x)
{
Worm.h.direction.set(1, 0);
} else
{
Worm.h.direction.set(-1, 0);
}
} else
{
if(MT.startPos(0).y < MT.smoothPos(0).y)
{
Worm.h.direction.set(0, 1);
} else
{
Worm.h.direction.set(0, -1);
}
}
}
// during a swipe take velocity and double check with the
// previous position to make sure. The final direction will be
// corrected at touch release
if(MT.b(0) && (MT.vel(0).x > 3) && (Abs(MT.vel(0).y) < 2))
{
if(MT.smoothPos(0).x > previousPos.x)
{
Worm.h.direction.set(1, 0);
}
previousPos = MT.smoothPos(0);
} else if(MT.b(0) && (MT.vel(0).x < -3) && (Abs(MT.vel(0).y) < 2))
{
if(MT.smoothPos(0).x < previousPos.x)
{
Worm.h.direction.set(-1, 0);
}
previousPos = MT.smoothPos(0);
} else if(MT.b(0) && (MT.vel(0).y > 3) && (Abs(MT.vel(0).x) < 2))
{
if(MT.smoothPos(0).y > previousPos.y)
{
Worm.h.direction.set(0, 1);
}
previousPos = MT.smoothPos(0);
} else if(MT.b(0) && (MT.vel(0).y < -3) && (Abs(MT.vel(0).x) < 2))
{
if(MT.smoothPos(0).y < previousPos.y)
{
Worm.h.direction.set(0, -1);
}
previousPos = MT.smoothPos(0);
}