📄 game.c
字号:
g_pcMines[ulCount][1]--;
//
// If the mine is too far off the left edge of the display then disable
// it.
//
if(g_pcMines[ulCount][1] == (char)-4)
{
g_pcMines[ulCount][0] = (char)-1;
g_pcMines[ulCount][1] = (char)-1;
g_pcMines[ulCount][2] = (char)-1;
continue;
}
//
// See if this mine is further to the right than any other mine that
// has been encountered thus far.
//
if((g_pcMines[ulCount][1] + 5) > ulMax)
{
//
// Set the new maximal mine position.
//
ulMax = g_pcMines[ulCount][1] + 5;
}
//
// See which type of mine this is.
//
if(g_pcMines[ulCount][0] == 0)
{
//
// Draw mine type one on the local frame buffer.
//
DrawImage(g_pucMine1, g_pcMines[ulCount][1], g_pcMines[ulCount][2],
3);
}
else
{
//
// Draw mine type two on the local frame buffer.
//
DrawImage(g_pucMine2, g_pcMines[ulCount][1], g_pcMines[ulCount][2],
4);
}
}
//
// If there are mines too close to the right side of the display then do
// not place any new mines.
//
if(ulMax > 85)
{
return;
}
//
// Get a random number.
//
ulIdx = RandomNumber();
//
// Only place new mines occasionally.
//
if(ulIdx >= 0x0c000000)
{
return;
}
//
// Try to find an unused mine entry.
//
for(ulCount = 0; ulCount < 5; ulCount++)
{
if((g_pcMines[ulCount][0] == (char)-1) &&
(g_pcMines[ulCount][1] == (char)-1) &&
(g_pcMines[ulCount][2] == (char)-1))
{
break;
}
}
//
// If all five mines are already in use, then a new mine can not be added.
//
if(ulCount == 5)
{
return;
}
//
// Choose a random mine type.
//
ulIdx = NEXT_RAND(ulIdx);
g_pcMines[ulCount][0] = ulIdx >> 31;
//
// The mine starts at the right edge of the display.
//
g_pcMines[ulCount][1] = 95;
//
// Choose a random vertical position within the tunnel for the mine.
//
ulIdx = NEXT_RAND(ulIdx);
g_pcMines[ulCount][2] = (g_pucOffset[0] + 1 +
(((g_pucOffset[1] - g_pucOffset[0] - 1 - 3 -
g_pcMines[ulCount][0]) *
(ulIdx >> 16)) >> 16));
//
// See which type of mine was choosen.
//
if(g_pcMines[ulCount][0] == 0)
{
//
// Draw mine type one on the local frame buffer.
//
DrawImage(g_pucMine1, g_pcMines[ulCount][1], g_pcMines[ulCount][2], 3);
}
else
{
//
// Draw mine type two on the local frame buffer.
//
DrawImage(g_pucMine2, g_pcMines[ulCount][1], g_pcMines[ulCount][2], 4);
}
}
//*****************************************************************************
//
// Move the missile further to the right, checking for impacts.
//
//*****************************************************************************
static void
UpdateMissile(tBoolean bFire, tBoolean bDead)
{
unsigned long ulBit, ulX;
//
// Set the X position to zero to indicate that no impact has been detected.
//
ulX = 0;
//
// See if a missile is currently in flight.
//
if((g_pcMissile[0] == (char)-1) && (g_pcMissile[1] == (char)-1))
{
//
// No missile is in flight, so see if one should be fired.
//
if(bFire && !bDead)
{
//
// Set the position of a newly fired missile
//
g_pcMissile[0] = 8;
g_pcMissile[1] = (((1023 - g_ulWheel) * 14) / 1024) + 2;
}
else
{
//
// No missile is in flight, and no missile is being fired, so do
// nothing.
//
return;
}
}
//
// Move the missile to the right.
//
g_pcMissile[0] += 2;
//
// See if the missile has moved off the display.
//
if(g_pcMissile[0] == 96)
{
//
// The missile is no longer on the display, so remove it from the
// display.
//
g_pcMissile[0] = (char)-1;
g_pcMissile[1] = (char)-1;
//
// Return without doing anything else.
//
return;
}
//
// See if the missile is on the first row or the second row.
//
if(g_pcMissile[1] < 8)
{
//
// Compute the bit that contains the missile.
//
ulBit = 1 << g_pcMissile[1];
//
// Draw the left most column of the missile and check for an impact.
//
g_pucFrame[g_pcMissile[0] + 0] ^= ulBit;
if((g_pucFrame[g_pcMissile[0] + 0] & ulBit) != ulBit)
{
g_pucFrame[g_pcMissile[0] + 0] |= ulBit;
ulX = g_pcMissile[0];
}
//
// Draw the middle column of the missile and check for an impact.
//
g_pucFrame[g_pcMissile[0] + 1] ^= ulBit;
if((g_pucFrame[g_pcMissile[0] + 1] & ulBit) != ulBit)
{
g_pucFrame[g_pcMissile[0] + 1] |= ulBit;
if(ulX == 0)
{
ulX = g_pcMissile[0] + 1;
}
}
//
// Draw the right column of the missile and check for an impact. The
// right column may be off the display, so bypass the check in that
// case.
//
if(g_pcMissile[0] != 94)
{
g_pucFrame[g_pcMissile[0] + 2] ^= ulBit;
if((g_pucFrame[g_pcMissile[0] + 2] & ulBit) != ulBit)
{
g_pucFrame[g_pcMissile[0] + 2] |= ulBit;
if(ulX == 0)
{
ulX = g_pcMissile[0] + 2;
}
}
}
}
else
{
//
// Compute the bit that contains the missile.
//
ulBit = 1 << (g_pcMissile[1] - 8);
//
// Draw the left most column of the missile and check for an impact.
//
g_pucFrame[g_pcMissile[0] + 96] ^= ulBit;
if((g_pucFrame[g_pcMissile[0] + 96] & ulBit) != ulBit)
{
g_pucFrame[g_pcMissile[0] + 96] |= ulBit;
ulX = g_pcMissile[0];
}
//
// Draw the middle column of the missile and check for an impact.
//
g_pucFrame[g_pcMissile[0] + 97] ^= ulBit;
if((g_pucFrame[g_pcMissile[0] + 97] & ulBit) != ulBit)
{
g_pucFrame[g_pcMissile[0] + 97] |= ulBit;
if(ulX == 0)
{
ulX = g_pcMissile[0] + 1;
}
}
//
// Draw the right column of the missile and check for an impact. The
// right column may be off the display, so bypass the check in that
// case.
//
if(g_pcMissile[0] != 94)
{
g_pucFrame[g_pcMissile[0] + 98] ^= ulBit;
if((g_pucFrame[g_pcMissile[0] + 98] & ulBit) != ulBit)
{
g_pucFrame[g_pcMissile[0] + 98] |= ulBit;
if(ulX == 0)
{
ulX = g_pcMissile[0] + 2;
}
}
}
}
//
// See if the missile hit something.
//
if(ulX != 0)
{
//
// Loop through the mines.
//
for(ulBit = 0; ulBit < 5; ulBit++)
{
//
// See if the missile hit this mine.
//
if((g_pcMines[ulBit][0] != (char)-1) &&
(g_pcMines[ulBit][1] <= ulX) &&
((g_pcMines[ulBit][1] + g_pcMines[ulBit][0] + 2) >= ulX) &&
(g_pcMines[ulBit][2] <= g_pcMissile[1]) &&
((g_pcMines[ulBit][2] + g_pcMines[ulBit][0] + 2) >=
g_pcMissile[1]))
{
//
// This mine was struck, so remove it from the display.
//
g_pcMines[ulBit][0] = (char)-1;
g_pcMines[ulBit][1] = (char)-1;
g_pcMines[ulBit][2] = (char)-1;
//
// Increase the player's score by 25 if they are not dead.
//
if(!bDead)
{
g_ulScore += 25;
}
//
// Stop looking through the mines.
//
break;
}
}
//
// Find an empty entry in the explosion list.
//
for(ulBit = 0; ulBit < 4; ulBit++)
{
if(g_pcExplosions[ulBit][0] == (char)-1)
{
break;
}
}
//
// See if an empty entry was found.
//
if(ulBit != 5)
{
//
// Start an explosion at the point of impact.
//
g_pcExplosions[ulBit][0] = 0;
g_pcExplosions[ulBit][1] = ulX;
g_pcExplosions[ulBit][2] = g_pcMissile[1];
}
//
// Remove the missile from the display.
//
g_pcMissile[0] = (char)-1;
g_pcMissile[1] = (char)-1;
}
}
//*****************************************************************************
//
// Draw the player's ship, checking for collisions.
//
//*****************************************************************************
static tBoolean
DrawShip(void)
{
unsigned long ulPos, ulCount, ulBits;
tBoolean bBoom;
//
// Convert the wheel position to the position of the ship on the display.
//
ulPos = ((1023 - g_ulWheel) * 14) / 1024;
//
// Assume no collisions until one is found.
//
bBoom = false;
//
// Loop through the five columns of the ship image.
//
for(ulCount = 0; ulCount < 5; ulCount++)
{
//
// See if the ship image starts in the first or second row of the
// display.
//
if(ulPos < 8)
{
//
// Get the scan lines that should be set for the first row of the
// display.
//
ulBits = (g_pucShip[ulCount] << ulPos) & 0xff;
if(ulBits)
{
//
// Set the scan lines in the local frame buffer and check for
// an impact.
//
g_pucFrame[ulCount + 4] ^= ulBits;
if((g_pucFrame[ulCount + 4] & ulBits) != ulBits)
{
g_pucFrame[ulCount + 4] |= ulBits;
bBoom = true;
}
}
//
// Get the scan lines that should be set for the second row of the
// display.
//
ulBits = g_pucShip[ulCount] >> (8 - ulPos);
if(ulBits)
{
//
// Set the scan lines in the local frame buffer and check for
// an impact.
//
g_pucFrame[ulCount + 100] ^= ulBits;
if((g_pucFrame[ulCount + 100] & ulBits) != ulBits)
{
g_pucFrame[ulCount + 100] |= ulBits;
bBoom = true;
}
}
}
else
{
//
// Get the scan lines that should be set for the second row of the
// display.
//
ulBits = g_pucShip[ulCount] << (ulPos - 8);
//
// Set the scan lines in the local frame buffer and check for an
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -