Back to Index
[Main pseudocode]
Author: Ki Chung
Description: Many of the game specifics needed to be determined before main loop could be written. Naturally, most of the function and data structures were designed while writing the main loop
_Game
if [_Flags] == exit
exit _Game
if phase == break
{
if phase == deploy break
{
_ScrollBanner(_BannerX, _BannerY)
load [_ScreenOff] from backup
_DrawImage([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, [_DeployBannerOff], DEPLOY_BANNER_WIDTH, DEPLOY_BANNER_HEIGHT, [_BannerX], [_BannerY], 1, 1)
if break time limit reached
{
[_Phase] = deploy
reset [_BannerX] and [_BannerY]
}
}
else if phase == battle break
{
_ScrollBanner(_BannerX, _BannerY)
load [_ScreenOff] from backup
_DrawImage([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, [_BattleBannerOff], BATTLE_BANNER_WIDTH, BATTLE_BANNER_HEIGHT, [_BannerX], [_BannerY], 1, 1)
if break time limit reached
{
[_Phase] = battle
reset [_BannerX] and [_BannerY]
}
}
else if phase == rebuild break
{
_ScrollBanner(_BannerX, _BannerY)
load [_ScreenOff] from backup
_DrawImage([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, [_RebuildBannerOff], REBUILD_BANNER_WIDTH, REBUILD_BANNER_HEIGHT, [_BannerX], [_BannerY], 1, 1)
if break time limit reached
{
[_Phase] = rebuild
reset [_BannerX] and [_BannerY]
}
}
}
else
{
_DrawStatusBar([_ScreenOff], STATUSBAR_X, STATUSBAR_Y)
_DrawMap([_MapScreenOff], [_GameMapOff])
if phase == initialize
{
if P1_init == true
{
_UpdateInitCursor([_P1CastleArray], _P1X, _P1Y, [_P1_InputFlags])
_DrawImage([_MapScreenOff], MAP_PIXEL_WIDTH, MAP_PIXEL_HEIGHT, [_P1InitCursorOff], INIT_CURSOR_WIDTH, INIT_CURSOR_HEIGHT, [_P1X] * 8 + 4, [_P1Y] * 8 + 4, NUM_FRAMES_INIT_CURSOR, 1)
_BuildCastle([_GameMapOff], [_P1X], [_P1Y], _NumP1Territory, [_P1_InputFlags], P1_INIT_PHASE)
}
if P2_init == true
{
_UpdateInitCursor([_P2CastleArray], _P2X, _P2Y, [_P2_InputFlags])
_DrawImage([_MapScreenOff], MAP_PIXEL_WIDTH, MAP_PIXEL_HEIGHT, [_P2InitCursorOff], INIT_CURSOR_WIDTH, INIT_CURSOR_HEIGHT, [_P2X] * 8 + 4, [_P2Y] * 8 + 4, NUM_FRAMES_INIT_CURSOR, 1)
_BuildCastle([_GameMapOff], [_P2X], [_P2Y], _NumP2Territory, [_P2_InputFlags], P2_INIT_PHASE)
}
if all players are initialized == true
{
[_Phase] = break before deploy
_DimBuffer([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, DIM_VAL)
make a copy of the screen
}
}
else if phase == deploy
{
if P1_deploy == true
{
_UpdateCursor(_P1X, _P1Y, 0, 0, GAME_MAP_WIDTH - 1, GAME_MAP_HEIGHT - 1, [_P1_InputFlags])
_DrawDeployCursor([_MapScreenOff], [_P1X] * 8, [_P1Y] * 8, [_P1DeployCursorOff])
_BuildCannon([_GameMapOff], [_P1CannonArray], _NumP1DeployCannon, _NumP1Cannon, [_P1X], [_P1Y], [_P1_InputFlags], P1_REGION, P1_DEPLOY_PHASE)
}
if P2_deploy == true
{
_UpdateCursor(_P2X, _P2Y, 0, 0, GAME_MAP_WIDTH - 1, GAME_MAP_HEIGHT - 1, [_P2_InputFlags])
_DrawDeployCursor([_MapScreenOff], [_P2X] * 8, [_P2Y] * 8, [_P2DeployCursorOff])
_BuildCannon([_GameMapOff], [_P2CannonArray], _NumP2DeployCannon, _NumP2Cannon, [_P2X], [_P2Y], [_P2_InputFlags], P2_REGION, P2_DEPLOY_PHASE)
}
if deploy time limit reached || all players are done deploying == true
{
reset [_TimeTick]
[_Phase] = break before battle
_DimBuffer([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, DIM_VAL)
make a copy of the screen
}
}
else if phase == battle
{
_DrawExplosion([_MapScreenOff], [_GameMapOff], [_ExplosionArray], [_ExplosionOff])
_UpdateCannonBall([_GameMapOff], [_CBallArray])
_DrawCannonBall([_MapScreenOff], [_CBallArray], [_CannonBallOff])
_UpdateCursor(_P1X, _P1Y, 0, 0, MAP_PIXEL_WIDTH - 1, MAP_PIXEL_HEIGHT - 1, [_P1_InputFlags])
_DrawImage([_MapScreenOff], MAP_PIXEL_WIDTH, MAP_PIXEL_HEIGHT, [_P1BattleCursorOff], BATTLE_CURSOR_WIDTH, BATTLE_CURSOR_HEIGHT, [_P1X], [_P1Y], NUM_FRAMES_BATTLE_CURSOR, 1)
_FireCannon([_GameMapOff], [_P1CannonArray], [_CBallArray], [_P1X], [_P1Y], [_P1_InputFlags])
_UpdateCursor(_P2X, _P2Y, 0, 0, MAP_PIXEL_WIDTH - 1, MAP_PIXEL_HEIGHT - 1, [_P2_InputFlags])
_DrawImage([_MapScreenOff], MAP_PIXEL_WIDTH, MAP_PIXEL_HEIGHT, [_P2BattleCursorOff], BATTLE_CURSOR_WIDTH, BATTLE_CURSOR_HEIGHT, [_P2X], [_P2Y], NUM_FRAMES_BATTLE_CURSOR, 1)
_FireCannon([_GameMapOff], [_P2CannonArray], [_CBallArray], [_P2X], [_P2Y], [_P2_InputFlags])
if battle time limit reached
{
reset [_TimeTick]
[_Phase] = break before rebuild
_DimBuffer([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, DIM_VAL)
make a copy of the screen
_UpdateEnclosedRegion([_GameMapOff])
_GenerateRandomBlock(_P1CurrentBlock)
[_P2CurrentBlock] = [_P1CurrentBlock]
}
}
else if phase == rebuild
{
_UpdateCursor(_P1X, _P1Y, 0, 0, GAME_MAP_WIDTH - 1, GAME_MAP_HEIGHT - 1, [_P1_InputFlags])
_DrawBlock([_MapScreenOff], [_P1X] * 8, [_P1Y] * 8, [_P1CurrentBlock], [_P1BlockOff])
_RotateBlock(_P1CurrentBlock, [_P1_InputFlags])
_BuildWall([_GameMapOff], [_P1X], [_P1Y], _P1CurrentBlock, [_P1_InputFlags])
_UpdateCursor(_P2X, _P2Y, 0, 0, GAME_MAP_WIDTH - 1, GAME_MAP_HEIGHT - 1, [_P2_InputFlags])
_DrawBlock([_MapScreenOff], [_P2X] * 8, [_P2Y] * 8, [_P2CurrentBlock], [_P2BlockOff])
_RotateBlock(_P2CurrentBlock, [_P2_InputFlags])
_BuildWall([_GameMapOff], [_P2X], [_P2Y], _P2CurrentBlock, [_P2_InputFlags])
if rebuild time limit reached
{
reset [_TimeTick]
if P1 and P2 has at least one castle
{
[_Phase] = break before deploy
update [_NumP1DeployCannon]
update [_NumP2DeployCannon]
dim screen
make a copy of the screen
}
if P1 has no castle
{
decrement [_P1Life]
increment [_P2Life]
[_Phase] = P1 initialize
update [_NumP1DeployCannon]
}
if P2 has no castle
{
decrement [_P2Life]
increment [_P1Life]
[_Phase] = P2 initialize
update [_NumP2DeployCannon]
}
adjust [_P1Life] and [_P2Life] to max
if P1 has no life && P2 has life
{
_DimBuffer([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, DIM_VAL)
_DrawImage([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, [_P2WinBannerOff], WIN_BANNER_WIDTH, WIN_BANNER_HEIGHT, WIN_BANNER_X, WIN_BANNER_Y, 1, 0)
loop until exit key pressed
exit _Game
}
else if P2 has no life && P1 has life
{
_DimBuffer([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, DIM_VAL)
_DrawImage([_ScreenOff], SCREEN_WIDTH, SCREEN_HEIGHT, [_P1WinBannerOff], WIN_BANNER_WIDTH, WIN_BANNER_HEIGHT, WIN_BANNER_X, WIN_BANNER_Y, 1, 0)
loop until exit key pressed
exit _Game
}
}
} ;end of else if phase == rebuild
_CopyBuffer([_MapScreenBuffer], MAP_PIXEL_WIDTH, MAP_PIXEL_HEIGHT, [_ScreenBuffer], SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0)
} ;end of else
display screen buffer on screen
update [_AnimateTick] and [_AnimateCount]
update [_TimeTick] and [_Time]
update [_CBallTick]
loop to _Game