home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Think Class Libraries / SAT-TCL 1.0b2 / SAT-TCLBouncingDemo ƒ / CBDDirector.p < prev    next >
Encoding:
Text File  |  1996-06-08  |  4.9 KB  |  222 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {    CBDDirector.p                                                                                                }
  4. {}
  5. {    Director class the BD application.                                                                    }
  6. {}
  7. {    Copyright © 1995 by Patrick C Hew. All rights reserved.                                }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit CBDDirector;
  13.  
  14. interface
  15.  
  16.     uses
  17.         TCL, BDIntf;
  18.  
  19. implementation
  20.  
  21.  
  22. {****************************************************}
  23. {}
  24. {    IBDDirector                                                                                                    }
  25. {}
  26. {    Initialize an BD Director object.                                                                        }
  27. {}
  28. {****************************************************}
  29.  
  30.     procedure CBDDirector.IBDDirector (aSupervisor: CGameApp);
  31.  
  32.  
  33.     begin { IBDDirector }
  34.         ISATDirector(aSupervisor);
  35.  
  36.         itsGameApp := aSupervisor;
  37.  
  38.         BuildWindow;
  39.         SetUpSprites;
  40.         GetWindow.Select;
  41.     end; { IBDDirector }
  42.  
  43.  
  44. {****************************************************}
  45. {}
  46. {    Free                                                                                                                }
  47. {}
  48. {    We reset our private pointer to the application.                                                }
  49. {}
  50. {****************************************************}
  51.  
  52.     procedure CBDDirector.Free;
  53.  
  54.     begin { Free }
  55.         itsGameApp := nil;
  56.  
  57.         inherited Free;
  58.     end; { Free }
  59.  
  60.  
  61. {****************************************************}
  62. {}
  63. {    BuildWindow                                                                                                    }
  64. {}
  65. {    We build a fixed size window which has one pane, the SAT pane.                        }
  66. {}
  67. {****************************************************}
  68.  
  69.     procedure CBDDirector.BuildWindow;
  70.  
  71.         const
  72.             kSATPanoLenh = 400;
  73.             kSATPanoLenv = 280;
  74.  
  75.         var
  76.             theWindow: CSATWindow;
  77.             theRect: Rect;
  78.             theSATPane: CSATPane;
  79.             theScrollPane: CScrollPane;
  80.  
  81.     begin { BuildWindow }
  82.         { There is a bug, probably in this method, which makes window zooming produce strange results. }
  83.  
  84.         new(theWindow);
  85.         theWindow.ISATWindow(WINDBD, kNotFloating, gDesktop, SELF);
  86.         itsWindow := theWindow;
  87.  
  88.         NEW(theScrollPane);
  89.         theScrollPane.IScrollPane(itsWindow, SELF, 10, 10, 0, 0, sizELASTIC, sizELASTIC, kHasHScroll, kHasVScroll, kHasSizebox);
  90.         theScrollPane.FitToEnclFrame(kDoHorizontal, kDoVertical);
  91.  
  92.         SetRect(theRect, 0, 0, kSATPanoLenh, kSATPanoLenv);
  93.  
  94.         new(theSATPane);
  95.         theSATPane.ISATPane(theScrollPane, SELF, 10, 10, 0, 0, sizELASTIC, sizELASTIC, PICTColorBackground, PICTBWBackground, theRect, kNoUseMenuBar, kNoDither4Bit, kNoBeSmart);
  96.         theSATPane.FitToEnclosure(kDoHorizontal, kDoVertical);
  97.  
  98.         itsSATPane := theSATPane;
  99.         theWindow.InstallSATPane(theSATPane);
  100.  
  101.         theScrollPane.InstallPanorama(theSATPane);
  102.         theScrollPane.SetSteps(8, 8);
  103.         theScrollPane.SetOverlaps(72, 72);
  104.  
  105.         SetRect(theRect, 80, 80, kSATPanoLenh, kSATPanoLenv);
  106.         itsWindow.SetSizeRect(theRect);
  107.  
  108.         gDecorator.PlaceNewWindow(itsWindow);
  109.     end; { BuildWindow }
  110.  
  111.  
  112. {****************************************************}
  113. {}
  114. {    SetUpSprites                                                                                                    }
  115. {}
  116. {    Set up the sprites for the bouncer.                                                                    }
  117. {}
  118. {****************************************************}
  119.  
  120.     procedure CBDDirector.SetUpSprites;
  121.  
  122.         var
  123.             theSpritePtr: SpritePtr;
  124.  
  125.     begin { SetUpSprites }
  126.         theSpritePtr := SATNewSprite(0, 30, 30, @SetupBouncer);
  127.     end; { SetUpSprites }
  128.  
  129.  
  130. {****************************************************}
  131. {}
  132. {    UpdateMenus                                                                                                    }
  133. {}
  134. {    Enables the appropriate commands in the Game Menu.                                        }
  135. {}
  136. {****************************************************}
  137.  
  138.     procedure CBDDirector.UpdateMenus;
  139.  
  140.     begin { UpdateMenus }
  141.         inherited UpdateMenus;
  142.  
  143.         if isPlaying then begin
  144.             gBartender.EnableCmd(cmdAbort);
  145.             if isPaused then begin
  146.                 gBartender.EnableCmd(cmdResume);
  147.             end { if }
  148.             else begin
  149.                 gBartender.EnableCmd(cmdPause);
  150.             end { else }
  151.         end { if }
  152.         else begin
  153.             gBartender.EnableCmd(cmdStart);
  154.         end; { else }
  155.     end; { UpdateMenus }
  156.  
  157.  
  158. {****************************************************}
  159. {}
  160. {    DoCommand                                                                                                    }
  161. {}
  162. {    React to commands to start, pause, resume or abort the game.                        }
  163. {}
  164. {****************************************************}
  165.  
  166.     procedure CBDDirector.DoCommand (theCommand: longint);
  167.  
  168.     begin { DoCommand }
  169.         case theCommand of
  170.  
  171.             cmdStart:  begin
  172.                 isPlaying := TRUE;
  173.                 isPaused := FALSE;
  174.                 itsGameApp.BeginGameMode;
  175.             end; { cmdStart }
  176.  
  177.             cmdPause:  begin
  178.                 isPaused := TRUE;
  179.                 itsGameApp.EndGameMode;
  180.             end; { cmdPause }
  181.  
  182.             cmdResume:  begin
  183.                 isPaused := FALSE;
  184.                 itsGameApp.BeginGameMode;
  185.             end; { cmdPause }
  186.  
  187.             cmdAbort:  begin
  188.                 isPlaying := FALSE;
  189.                 isPaused := FALSE;
  190.                 itsGameApp.EndGameMode;
  191.             end;
  192.  
  193.             otherwise begin
  194.                 inherited DoCommand(theCommand);
  195.             end; { otherwise }
  196.         end; { case }
  197.     end; { DoCommand }
  198.  
  199.  
  200. {****************************************************}
  201. {}
  202. {    Dawdle                                                                                                            }
  203. {}
  204. {    When playing, this is the heart of the game loop.                                            }
  205. {}
  206. {****************************************************}
  207.  
  208.     procedure CBDDirector.Dawdle (var maxSleep: longint);
  209.  
  210.     begin { DoPlay }
  211.         if isPlaying and not isPaused then begin
  212.  
  213.             maxSleep := 0;
  214.  
  215.             itsSATPane.DoSATRun2(FALSE);
  216.  
  217.             { Maybe a delay loop here, if you want to slow things down. }
  218.         end; { if }
  219.     end; { Dawdle }
  220.  
  221.  
  222. end. { CBDDirector }