Prev: 57297 Up: Map Next: 57628
57328: Run Game
Used by the routine at GameEntry.
The main loop of the game. A game starts with the title menu, and then each life is played in the loop from RunGame_Life. When the player loses a life the next player is switched to if there is a second player. When the last life is lost the high score is checked and the game starts again.
Clear the bytes at ScratchValue that the game uses as variables.
RunGame 57328 LD HL,23768 Clear 48 bytes starting at ScratchValue.
57331 LD B,48
57333 CALL ClearBytes
Start a new game from the title menu. Make player 1 the player on the left of the panel, and go to the first level.
RunGame_Loop 57336 LD A,(57646) Fetch the flag that shows the scores are swapped.
57339 AND A Test it.
57340 CALL NZ,SwitchPlayer_Flip Swap the players back if they were swapped.
57343 XOR A Set the level number to zero.
57344 LD (57055),A
57347 CALL SetLevelGraphics Set the colours and the shape of the level.
57350 CALL ResetAttributes Reset the attributes of the screen.
57353 CALL ClearScreen Clear the screen.
57356 CALL ShowTitleMenu Show the title menu and wait for the game to be started.
57359 CALL StartGame Set up the lives, the scores, the gauges and the bottles for a new game.
57362 CALL ShowPlayerNumber Show the number of the player.
57365 CALL ResetAttributes Reset the attributes of the screen.
57368 CALL ClearScreen Clear the screen.
57371 CALL DrawPanel Draw the panel.
Colour the window of the game for the level.
RunGame_Loop2 57374 LD HL,30512 Set HL to the position 30512 of the game window.
57377 LD DE,57628 Point DE at PanelRectangle.
57380 CALL FillRectangle Colour the window.
Start a life. Draw the icon of each player that shows whether the player has the bottle flag set, putting the icon of the current player on the left.
RunGame_Life 57383 LD A,(57084) Fetch the bottle flag of the first player and keep it in C.
57386 LD C,A
57387 LD A,(57115) Fetch the bottle flag of the second player and keep it in B.
57390 LD B,A
57391 LD A,(57053) Fetch the number of the current player.
57394 AND A Test it.
57395 JR Z,RunGame_Pictures Jump to RunGame_Pictures if it is the first player.
57397 LD A,C Swap the flags of the players, so that the flag of the current player is in C.
57398 LD C,B
57399 LD B,A
RunGame_Pictures 57400 PUSH BC Stash the flags on the stack.
57401 LD HL,26632 Set HL to the position 26632 of the icon on the left of the panel.
57404 LD DE,25788 Point DE at EmptyCupPicture.
57407 LD A,C Fetch the flag for the icon.
57408 AND A Test it.
57409 JR Z,RunGame_LeftIcon Jump to RunGame_LeftIcon if the flag is not set.
57411 LD DE,25752 Point DE at FilledCupPicture.
RunGame_LeftIcon 57414 CALL DrawPicture Draw the icon on the left.
57417 LD L,232 Move across to the icon on the right of the panel.
57419 LD DE,25788 Point DE at EmptyCupPicture.
57422 POP BC Restore the flags.
57423 LD A,B Fetch the flag for the icon on the right.
57424 AND A Test it.
57425 JR Z,RunGame_RightIcon Jump to RunGame_RightIcon if the flag is not set.
57427 LD DE,25752 Point DE at FilledCupPicture.
RunGame_RightIcon 57430 CALL DrawPicture Draw the icon on the right.
Update the panel, reset the state of the player and print the digits of the lives and the bottles.
57433 CALL UpdatePanelDigits Update the digits of the lives and the bottles.
57436 CALL StartGame_Life Reset the state of the player, the countdown timer and the gauges.
57439 LD DE,57765 Point DE at LivesTextPlayerOne_Record.
57442 LD B,4 Set the number of text records to 4.
57444 CALL PrintTextRecords Print the digits of the lives and the bottles of both players.
Put the entities and the bottles of the level in place, build the view and print the messages.
57447 CALL ResetEntities Reset the entities.
57450 CALL RestoreBottles Restore the bottles that the player has not yet collected.
57453 CALL BuildView Build the view of the level.
57456 CALL ScrollStageMessage Scroll in the message for the stage.
57459 CALL ShowExitMessage Show the exit message, if all of the bottles have been collected.
Draw the first frame, and wipe it on to the screen.
RunGame_Frame 57462 LD IX,46400 Point IX at Entities.
57466 CALL ProjectPlayerEntity Project the player on to the screen.
57469 CALL UpdateEntities Update the entities.
57472 CALL BuildDrawList Build the draw list.
57475 CALL SortDrawList Sort the draw list.
57478 CALL DrawItems Draw the items of the draw list.
57481 CALL WipeViewIn Wipe the view on to the screen.
57484 CALL RestoreItemRows Put the rows of the screen buffer back.
Run the frames of the game until the player loses a life or leaves the level. Then remove the entities that were made from the objects of the level, and clear the message.
57487 CALL RunFrame Run the frames of the game.
57490 CALL RemoveObjectEntities Remove the entities that were made from the objects of the level.
57493 LD DE,52826 Point DE at ExitClosedMessages.
57496 CALL PrintText Clear the first part of the message.
57499 CALL PrintText Clear the second part of the message.
57502 LD A,(43610) Fetch the flag that shows a life has been lost.
57505 AND A Test it.
57506 JR Z,RunGame_Complete Jump to RunGame_Complete if the player has left the level.
The player lost a life. Wipe the view off the screen and take away a life.
RunGame_Lost 57508 CALL WipeViewOut Wipe the view off the screen.
57511 LD A,(57054) Fetch the number of lives.
57514 DEC A Take away a life.
RunGame_Loop3 57515 LD (57054),A Store the number of lives.
57518 JR Z,RunGame_Over Jump to RunGame_Over if the player has no lives left.
Hand over to the other player in a game with two players, and carry on from the start of a life.
57520 LD A,(24829) Fetch the number of players.
57523 AND A Test it.
57524 CALL NZ,SwitchPlayer Swap the details of the two players if there are two players.
57527 JP RunGame_Life Start the next life.
The player has no lives left. Show the message 'GAME OVER' and the number of the player, and check the high score.
RunGame_Over 57530 CALL ResetAttributes Reset the attributes of the screen.
57533 CALL ClearScreen Clear the screen.
57536 LD DE,57040 Point DE at GameOverText.
57539 CALL PrintText Print it.
57542 CALL ShowPlayerNumber_Print Print the number of the player and play the game over tune.
57545 CALL UpdateHighScore Check whether the score is a new high score.
57548 LD A,(24829) Fetch the number of players.
57551 AND A Test it.
57552 JP Z,RunGame_Loop Go back to the title menu if there is only one player.
57555 LD A,(57085) Fetch the number of lives of the other player.
57558 AND A Test it.
57559 JP Z,RunGame_Loop Go back to the title menu if the other player has no lives left either.
57562 CALL SwitchPlayer Swap the details of the two players.
57565 JP RunGame_Life Start a life for the other player.
The player has left the level. Go on to the next level, put all of the bottles back and give the bonus for the time that is left.
RunGame_Complete 57568 XOR A Clear the bottle flag of the player.
57569 LD (57084),A Store it.
57572 LD A,(57055) Fetch the number of the level.
57575 INC A Go on to the next level.
57576 LD (57055),A Store it.
57579 LD HL,57057 Point HL at BottleStates.
57582 LD A,129 Set the state of an uncollected bottle.
57584 LD B,20 Set the number of bottles to 20.
RunGame_Loop4 57586 LD (HL),A Set the state of a bottle.
57587 INC HL Move on to the next bottle.
57588 DJNZ RunGame_Loop4 Loop back to RunGame_Loop4 until all of the bottles have been done.
57590 LD HL,0 Clear the wanted heading of the player.
57593 LD (46436),HL Store it.
57596 CALL PlayFanfare Play the fanfare.
57599 CALL CountDownTime Count down the time that is left and add it to the score.
57602 CALL WipeViewOut Wipe the view off the screen.
57605 XOR A Clear the restart position.
57606 LD (57079),A Store it.
After the last level, show the ending and finish the game.
57609 LD A,(57055) Fetch the number of the level.
57612 SUB 5 Take away the number of levels.
57614 JR NZ,RunGame_Next Jump to RunGame_Next if the last level has not been finished.
57616 CALL ShowEnding Show the ending.
57619 XOR A Set the number of lives to zero.
57620 JR RunGame_Loop3 Jump to RunGame_Loop3 to finish the game.
RunGame_Next 57622 CALL SetLevelGraphics Set the colours and the shape of the next level.
57625 JP RunGame_Loop2 Start the level.
Prev: 57297 Up: Map Next: 57628