In my code, I have a few places where I have to implement the same thing twice, only mirrored for when the character looks to the right and where it looks to the left.
The algorithm is exactly the same, but there are a bunch of variables, constants and comparisons that are different.
Here is an example. Do you have any creative idea how I can make this shorter, so that it occupies less ROM space?
The algorithm is exactly the same, but there are a bunch of variables, constants and comparisons that are different.
Here is an example. Do you have any creative idea how I can make this shorter, so that it occupies less ROM space?
Code:
if (Chrs.Direction[IndexScarlett] == DirectionRight)
{
for (i = 0; i < ScarlettPixelsPerMovementRight; ++i)
{
if (Chrs.X[IndexScarlett] < Chrs.X[IndexAmy]
&& Chrs.X[IndexScarlett] != ScarlettRightmostX)
{
++Chrs.X[IndexScarlett];
}
else
{
InitializeScarlettMovementUp();
break;
}
}
}
else
{
for (i = 0; i < ScarlettPixelsPerMovementLeft; ++i)
{
if (Chrs.X[IndexScarlett] > Chrs.X[IndexAmy]
&& Chrs.X[IndexScarlett] != ScarlettLeftmostX)
{
--Chrs.X[IndexScarlett];
}
else
{
InitializeScarlettMovementUp();
break;
}
}
}
{
for (i = 0; i < ScarlettPixelsPerMovementRight; ++i)
{
if (Chrs.X[IndexScarlett] < Chrs.X[IndexAmy]
&& Chrs.X[IndexScarlett] != ScarlettRightmostX)
{
++Chrs.X[IndexScarlett];
}
else
{
InitializeScarlettMovementUp();
break;
}
}
}
else
{
for (i = 0; i < ScarlettPixelsPerMovementLeft; ++i)
{
if (Chrs.X[IndexScarlett] > Chrs.X[IndexAmy]
&& Chrs.X[IndexScarlett] != ScarlettLeftmostX)
{
--Chrs.X[IndexScarlett];
}
else
{
InitializeScarlettMovementUp();
break;
}
}
}