Example #1
0
//Change the rect's x/y based on how far we're moving in a particular direction (using our 8 dir system, not abstract)
void rect::OffsetByDirection(direction dir, sShort distance)
{
    //OffsetByAngle(directionToAngle(dir), distance);
    /*Can't use the angle calculation because 45deg and whatnot doesn't work
    	with our current movement calculations. Yes I know diagonals are
    	going to be a bit faster and further than moving horiz/vert, but the
    	grid is small and not very noticeable
    */
    switch (dir)
    {
    case SOUTHEAST:
        OffsetByAngle(90, distance); //do south
        OffsetByAngle(0, distance); //do east
        break;
    case SOUTHWEST:
        OffsetByAngle(90, distance); //do south
        OffsetByAngle(180, distance); //do west
        break;
    case NORTHEAST:
        OffsetByAngle(270, distance); //do north
        OffsetByAngle(0, distance); //do east
        break;
    case NORTHWEST:
        OffsetByAngle(270, distance); //do north
        OffsetByAngle(180, distance); //do west
        break;
    default: //angle offset is fine for horiz/vert
        OffsetByAngle(directionToAngle(dir), distance);
        break;
    }
}
Example #2
0
void Movable::setOrientation(sf::Vector2f direction)
{
	m_sprite.setRotation(directionToAngle(direction));
}