1. private with Ada.Real_Time; 
  2. private with Ada.Strings.Unbounded; 
  3. private with Allegro.Keyboard; 
  4. private with Entities; 
  5. private with Events.Game; 
  6. private with Events.Keen; 
  7. private with Events.World; 
  8.  
  9. package Game_Views.Keen is 
  10.  
  11. private 
  12.  
  13.     use Ada.Real_Time; 
  14.     use Ada.Strings.Unbounded; 
  15.     use Allegro.Keyboard; 
  16.     use Entities; 
  17.     use Events.Game; 
  18.     use Events.Keen; 
  19.     use Events.World; 
  20.  
  21.     type Boolean_Key_Array is array (1..KEY_MAX) of Boolean; 
  22.  
  23.     type Key_Purpose is ( 
  24.         MOVE_UP,        -- move/look up 
  25.         MOVE_DOWN,      -- move/look down 
  26.         MOVE_LEFT,      -- move left 
  27.         MOVE_RIGHT,     -- move right 
  28.         JUMP,           -- jump up 
  29.         POGO,           -- toggle pogostick 
  30.         SHOOT,          -- shoot stunner gun 
  31.         PROGRESS,       -- toggle progress board 
  32.         PAUSE,          -- pause/resume play 
  33.         MENU            -- exit to menu 
  34.     ); 
  35.  
  36.     type Key_Binding_Array is array (Key_Purpose) of Integer; 
  37.  
  38.     type Keen_View is new Game_View with 
  39.         record 
  40.             -- true if a game is currently in-session 
  41.             gameInProgress : Boolean := False; 
  42.  
  43.             -- paused automatically by the gui. this indicates that the gui 
  44.             -- should resume the game because the pause command was not given by 
  45.             -- the user. (ex: auto pause when showing progress board or entering 
  46.             -- the menu) 
  47.             autoPaused : Boolean := False; 
  48.  
  49.             -- player can pause/resume the game. the gui may lock the pause 
  50.             -- feature temporarily so the user can't directly pause/resume. 
  51.             pauseEnabled : Boolean := True; 
  52.  
  53.             -- the id of the player entity, for sending impulses. 
  54.             playerId : Entity_Id := INVALID_ID; 
  55.  
  56.             -- events from these keys sent to the scene should be ignored until 
  57.             -- the next key press event. 
  58.             ignoreKey : Boolean_Key_Array := Boolean_Key_Array'(others => False); 
  59.  
  60.             -- time when the loading screen was shown; the time is set when 
  61.             -- the world introduction text is put into it, not when the message 
  62.             -- box is first displayed. this allows a minimum time to pass where 
  63.             -- the player can read the text before it is hidden again. 
  64.             loadScreenStarted : Time := Time_Last; 
  65.  
  66.             -- true when loading is in progress. 
  67.             loading : Boolean := False; 
  68.  
  69.             -- the name of the music for the current world. this is set when the 
  70.             -- 'music' world property changes and played when the world loading 
  71.             -- dialog is closed. 
  72.             worldMusic : Unbounded_String; 
  73.  
  74.             -- an array of key scancodes bound to key purposes 
  75.             key : Key_Binding_Array; 
  76.  
  77.             -- the id of the most recent dialog event pending a response. 
  78.             dialogId : Integer := 0; 
  79.         end record; 
  80.     type A_Keen_View is access all Keen_View'Class; 
  81.  
  82.     procedure Construct( this : access Keen_View ); 
  83.  
  84.     procedure Handle( this : not null access Keen_View'Class; 
  85.                       evt  : not null A_Dialog_Event ); 
  86.  
  87.     procedure Handle( this : not null access Keen_View'Class; 
  88.                       evt  : not null A_Game_State_Event ); 
  89.  
  90.     procedure Handle( this : not null access Keen_View'Class; 
  91.                       evt  : not null A_Game_Var_Changed_Event ); 
  92.  
  93.     procedure Handle( this : not null access Keen_View'Class; 
  94.                       evt  : not null A_Scroll_View_Event ); 
  95.  
  96.     procedure Handle( this : not null access Keen_View'Class; 
  97.                       evt  : not null A_World_Property_Changed_Event ); 
  98.  
  99.     procedure Handle_Close_Request( this : access Keen_View ); 
  100.  
  101.     -- Inherited from the Event_Listener interface. Handles events that the view 
  102.     -- is registered to receive. 
  103.     procedure Handle_Event( this : access Keen_View; 
  104.                             evt  : in out A_Event; 
  105.                             resp : out Response_Type ); 
  106.     pragma Precondition( evt /= null ); 
  107.  
  108.     -- This is called when the application starts and stops loading resources. 
  109.     procedure Handle_Loading( this : access Keen_View; loading : Boolean ); 
  110.  
  111.     -- This is called when a new world is loaded by the Game. 
  112.     procedure Handle( this : not null access Keen_View'Class; 
  113.                       evt  : not null A_World_Loaded_Event ); 
  114.  
  115.     -- This is called when the paused state of the Game changes. 
  116.     procedure Handle_Paused( this : access Keen_View; paused : Boolean ); 
  117.  
  118.     -- This is called to start the view and attach it to the application 
  119.     -- framework on startup. 
  120.     procedure Start_View( this : access Keen_View ); 
  121.  
  122.     -- This is called to stop the view and detach it from the application 
  123.     -- framework on shutdown. 
  124.     procedure Stop_View( this : access Keen_View ); 
  125.  
  126.     -- Inherited from the Process interface. This will be called regularly after 
  127.     -- the view is started. 
  128.     procedure Tick( this : access Keen_View; time : Tick_Time ); 
  129.  
  130.     -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  131.     -- The following procedures handle direct user actions. 
  132.  
  133.     -- Called when the user attempts to start a new game. This procedure 
  134.     -- ensures that a new game may be started and then queues a New_Game event. 
  135.     procedure Action_New_Game( this : not null access Keen_View'Class ); 
  136.  
  137.    -- Called when the user attempts to quit the game. This procedure may do 
  138.    -- something else first, like ask if the game should be saved, etc. When the 
  139.    -- game should be quit, this procedure will queue a Close_Window event. 
  140.     procedure Action_Quit( this : not null access Keen_View'Class ); 
  141.  
  142.     -- Called when the user attempts to resume a game in progress from the menu. 
  143.     procedure Action_Resume_Game( this : not null access Keen_View'Class ); 
  144.  
  145.     -- Called when the user responds to the retry level dialog. 
  146.     procedure Action_Retry_Level( this  : not null access Keen_View'Class; 
  147.                                   again : Boolean ); 
  148.  
  149.     -- Called when a registered scene key is pressed/released/held. 
  150.     procedure Action_Scene_Key( this    : not null access Keen_View'Class; 
  151.                                 action  : A_Key_Action; 
  152.                                 handled : out Boolean ); 
  153.  
  154.     -- Called when the user confirms that they have seen the title screen. The 
  155.     -- gui will return to the menu. 
  156.     procedure Action_Title_OK( this : not null access Keen_View'Class ); 
  157.  
  158.     -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  159.     -- The following procedures update the GUI. 
  160.  
  161.     -- Pauses the game automatically if it isn't already paused, or unpauses the 
  162.     -- game if it was paused automatically and not by the player. 
  163.     procedure Auto_Pause( this  : not null access Keen_View'Class; 
  164.                           pause : Boolean ); 
  165.  
  166.     -- Loads the key bindings for the game from the preferences system. 
  167.     procedure Load_Bindings( this : not null access Keen_View'Class ); 
  168.  
  169.     -- Queues an event to pause or resume the game. The user must be allowed to 
  170.     -- pause or resume the game or else 'force' must be set to True. Note that 
  171.     -- the paused state of the game remains unchanged until Handle_Paused is 
  172.     -- called. 
  173.     procedure Pause_Game( this  : not null access Keen_View'Class; 
  174.                           pause : Boolean; 
  175.                           force : Boolean := False ); 
  176.  
  177.     -- Creates all of the widgets required for the game view. This should only 
  178.     -- be called once as part of Game_View object construction. An exception 
  179.     -- will be raised if an error occurs creating the widgets. 
  180.     procedure Populate_View( this  : not null access Keen_View'Class; 
  181.                              xres, 
  182.                              yres  : Positive; 
  183.                              scale : Positive ); 
  184.  
  185.     -- Returns the gui to the menu from gameplay, pausing the game automatically. 
  186.     procedure Return_To_Menu( this : not null access Keen_View'Class ); 
  187.  
  188.     -- Indicates to the game logic that the view is ready to play. The menu and 
  189.     -- load screen is hidden and the scene is made visible. 
  190.     procedure Ready_To_Play( this : not null access Keen_View'Class ); 
  191.  
  192.     -- Puts 'text' into the loading message box, splitting text into multiple 
  193.     -- lines on whitespace boundaries as necessary. If visibility of the loading 
  194.     -- message will not be affected. 
  195.     procedure Set_Loading_Text( this : not null access Keen_View'Class; 
  196.                                 text : String ); 
  197.  
  198.     -- Shows the game widgets and focuses the scene, or hides the game widgets. 
  199.     procedure Show_Game( this : not null access Keen_View'Class; show : Boolean ); 
  200.  
  201.     -- Shows or hides the modal loading dialog. If 'show' is True then 'text' 
  202.     -- will be the text shown in the dialog. 
  203.     procedure Show_Loading( this : not null access Keen_View'Class; 
  204.                             show : Boolean; 
  205.                             text : String := "" ); 
  206.  
  207.     -- Shows or hides the menu widgets. 
  208.     procedure Show_Menu( this : not null access Keen_View'Class; show : Boolean ); 
  209.  
  210. end Game_Views.Keen;