Skip to content

Commit

Permalink
Further game refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Jan 1, 2025
1 parent f62c6fd commit 0084fbb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion main/modes/games/2048/2048_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void t48_gameLoop(t48_t* t48, int32_t elapsedUs)
const int indicatorSize = 9;
int dx = CLAMP(t48->lastIMUx >> 4, -indicatorSize, indicatorSize);
int dy =-CLAMP(t48->lastIMUy >> 4, -indicatorSize, indicatorSize);
drawRect(indicatorx - indicatorSize - 1, indicatory - indicatorSize - 1,
drawRect(indicatorx - indicatorSize, indicatory - indicatorSize,
indicatorx + indicatorSize + 1, indicatory + indicatorSize + 1, c333 );
drawCircle(indicatorx + dx, indicatory + dy, 1, c555 );
}
Expand Down
31 changes: 27 additions & 4 deletions main/modes/games/2048/mode_2048.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,15 @@ static void t48MainLoop(int64_t elapsedUs)
int oy = qRelativeRotation[1] * 512;
int ox = -qRelativeRotation[2] * 512;

bool bXPressed = ABS(ox) > 128;
bool bXReleased = ABS(ox) < 80;
const int trigger = 104;
const int release = 80;

bool bXPressed = ABS(ox) > trigger;
bool bXReleased = ABS(ox) < release;
bool bYWasTriggered = t48->receivedInputMask & 2;

bool bYPressed = ABS(oy) > 128;
bool bYReleased = ABS(oy) < 80;
bool bYPressed = ABS(oy) > trigger;
bool bYReleased = ABS(oy) < release;
bool bXWasTriggered = t48->receivedInputMask & 1;

if (!bYWasTriggered && bYPressed)
Expand Down Expand Up @@ -302,6 +305,26 @@ static void t48MainLoop(int64_t elapsedUs)
t48->receivedInputMask = (bYWasTriggered ? 2 : 0) | (bXWasTriggered ? 1 : 0);
t48->lastIMUx = ox;
t48->lastIMUy = oy;


// Handle pushing the zero around. You can push it by pushing past the endstops.
bool bXIsRailed = ABS(ox) > (trigger+2);
bool bYIsRailed = ABS(ox) > (trigger+2);
if (bXIsRailed || bYIsRailed)
{
const float fNudgeAmount = 0.04;
float qNudgeX[4] = { 0.999, 0.0, 0.0, 0.0 };
if (bXIsRailed)
{
qNudgeX[2] = ox > 0 ? -fNudgeAmount : fNudgeAmount;
}
if (bYIsRailed)
{
qNudgeX[1] = oy < 0 ? -fNudgeAmount : fNudgeAmount;
}
mathQuatApply(t48->quatBase, t48->quatBase, qNudgeX);
mathQuatNormalize( t48->quatBase, t48->quatBase );
}
}
}

Expand Down

0 comments on commit 0084fbb

Please sign in to comment.