1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Events; 
  10. with Values;                            use Values; 
  11.  
  12. pragma Elaborate_All( Events ); 
  13.  
  14. package Events.Game is 
  15.  
  16.     -- A command to end the game session. 
  17.     END_GAME_ID : constant Event_Id := To_Event_Id( "End_Game" ); 
  18.  
  19.     type End_Game_Event is new Event with private; 
  20.     type A_End_Game_Event is access all End_Game_Event'Class; 
  21.  
  22.     function Is_Completed( this : not null access End_Game_Event'Class ) return Boolean; 
  23.  
  24.     ---------------------------------------------------------------------------- 
  25.  
  26.     GAME_PAUSED_ID : constant Event_Id := To_Event_Id( "Game_Paused" ); 
  27.  
  28.     -- A notification that the game paused state has changed. 
  29.     type Game_Paused_Event is new Event with private; 
  30.     type A_Game_Paused_Event is access all Game_Paused_Event'Class; 
  31.  
  32.     -- Returns True if the gameplay has been paused or False if it has been resumed. 
  33.     function Is_Paused( this : not null access Game_Paused_Event'Class ) return Boolean; 
  34.  
  35.     ---------------------------------------------------------------------------- 
  36.  
  37.     GAME_STATE_ID : constant Event_Id := To_Event_Id( "Game_State" ); 
  38.  
  39.     -- A notification that the gameplay state has changed. This happens when a 
  40.     -- game session begins and ends. 
  41.     type Game_State_Event is new Event with private; 
  42.     type A_Game_State_Event is access all Game_State_Event'Class; 
  43.  
  44.     -- Returns True if gameplay is not in progress now because the game session 
  45.     -- was interrupted by the player, instead of ending naturally (winning or 
  46.     -- losing.) The game session can be interrupted to start a new game, load a 
  47.     -- saved game, or just end the current game session by choice. 
  48.     function Is_Interrupted( this : not null access Game_State_Event'Class ) return Boolean; 
  49.  
  50.     -- Returns True if gameplay is in progress. 
  51.     function Is_Playing( this : not null access Game_State_Event'Class ) return Boolean; 
  52.  
  53.     ---------------------------------------------------------------------------- 
  54.  
  55.     GAME_VAR_CHANGED_ID : constant Event_Id := To_Event_Id( "Game_Var_Changed" ); 
  56.  
  57.     -- A notification that a game session variable has changed. 
  58.     type Game_Var_Changed_Event is new Event with private; 
  59.     type A_Game_Var_Changed_Event is access all Game_Var_Changed_Event'Class; 
  60.  
  61.     -- Returns a copy of the variable's new value. 
  62.     function Get_Value( this : access Game_Var_Changed_Event ) return Value_Ptr; 
  63.     pragma Postcondition( Get_Value'Result /= Values.Nul ); 
  64.  
  65.     -- Returns the name of the variable that changed. 
  66.     function Get_Var( this : not null access Game_Var_Changed_Event'Class ) return String; 
  67.  
  68.     ---------------------------------------------------------------------------- 
  69.  
  70.     -- A notification that the loading of a world by the game logic has begun or 
  71.     -- ended. If loading has ended, an error message is included on failure. 
  72.     LOADING_WORLD_ID : constant Event_Id := To_Event_Id( "Loading_World" ); 
  73.  
  74.     -- A notification regarding the loading state of a resource. 
  75.     type Loading_Event is new Event with private; 
  76.     type A_Loading_Event is access all Loading_Event'Class; 
  77.  
  78.     -- Returns an error message if the loading has ended due to a failure. An 
  79.     -- empty string will be returned otherwise. 
  80.     function Get_Error( this : not null access Loading_Event'Class ) return String; 
  81.  
  82.     -- Returns True if loading is beginning or False if it has ended. If loading 
  83.     -- has ended, check Get_Error to determine if the load was successful. 
  84.     function Is_Loading( this : not null access Loading_Event'Class ) return Boolean; 
  85.  
  86.     ---------------------------------------------------------------------------- 
  87.  
  88.     -- A command to begin a new game session. 
  89.     NEW_GAME_ID : constant Event_Id := To_Event_Id( "New_Game" ); 
  90.  
  91.     ---------------------------------------------------------------------------- 
  92.  
  93.     PAUSE_GAME_ID : constant Event_Id := To_Event_Id( "Pause_Game" ); 
  94.  
  95.     -- A command to change the game paused state. 
  96.     type Pause_Game_Event is new Event with private; 
  97.     type A_Pause_Game_Event is access all Pause_Game_Event'Class; 
  98.  
  99.     -- Returns True if the command is to pause the gameplay, or False if the 
  100.     -- command is to resume gameplay. 
  101.     function Is_Paused( this : not null access Pause_Game_Event'Class ) return Boolean; 
  102.  
  103.     ---------------------------------------------------------------------------- 
  104.  
  105.     -- A notification that the player died. 
  106.     PLAYER_DIED_ID : constant Event_Id := To_Event_Id( "Player_Died" ); 
  107.  
  108.     ---------------------------------------------------------------------------- 
  109.  
  110.     SCROLL_VIEW_ID : constant Event_Id := To_Event_Id( "Scroll_View" ); 
  111.  
  112.     -- A command to scroll the gaame view's viewport of the world. 
  113.     type Scroll_View_Event is new Event with private; 
  114.     type A_Scroll_View_Event is access all Scroll_View_Event'Class; 
  115.  
  116.     -- Amount to scroll view in the X axis in world coordinates. 
  117.     function Get_X( this : not null access Scroll_View_Event'Class ) return Float; 
  118.  
  119.     -- Amount to scroll view in the Y axis in world coordinates. 
  120.     function Get_Y( this : not null access Scroll_View_Event'Class ) return Float; 
  121.  
  122.     ---------------------------------------------------------------------------- 
  123.  
  124.     -- A notification that the view is ready for game play to begin after a new 
  125.     -- world has been loaded. After loading a new world, the game waits in the 
  126.     -- Loaded state until the view notifies it with this event. 
  127.     VIEW_READY_ID : constant Event_Id := To_Event_Id( "View_Ready" ); 
  128.  
  129.     ---------------------------------------------------------------------------- 
  130.  
  131.     -- Queues an End_Game event. 'completed' indicates the game session ended naturally, 
  132.     -- one way or another. If the game was aborted by the player via the menu, completed 
  133.     -- must be False. 
  134.     procedure Queue_End_Game( completed : Boolean ); 
  135.  
  136.     -- Queues a Game_Paused event. 
  137.     procedure Queue_Game_Paused( paused : Boolean ); 
  138.  
  139.     -- Queues a Game_State event. 
  140.     procedure Queue_Game_State( playing : Boolean; interrupted : Boolean := False ); 
  141.  
  142.     -- Queues a Game_Var_Changed event. 
  143.     procedure Queue_Game_Var_Changed( var : String; val : Value_Ptr'Class ); 
  144.     pragma Precondition( var'Length > 0 ); 
  145.     pragma Precondition( Value_Ptr(val) /= Values.Nul ); 
  146.  
  147.     -- Queues a Loading_World event. 
  148.     procedure Queue_Loading_World( loading : Boolean; error : String := "" ); 
  149.     pragma Precondition( not loading or else error'Length = 0 ); 
  150.  
  151.     -- Queues a New_Game event. 
  152.     procedure Queue_New_Game; 
  153.  
  154.     -- Queues a Pause_Game event. 
  155.     procedure Queue_Pause_Game( paused : Boolean ); 
  156.  
  157.     -- Queues a Player_Died event. 
  158.     procedure Queue_Player_Died; 
  159.  
  160.     -- Queues a Scroll_View event. 
  161.     procedure Queue_Scroll_View( x, y : Float ); 
  162.  
  163.     -- Queues a View_Ready event. 
  164.     procedure Queue_View_Ready; 
  165.  
  166. private 
  167.  
  168.     type End_Game_Event is new Event with 
  169.         record 
  170.             completed : Boolean := True; 
  171.         end record; 
  172.  
  173.     procedure Construct( this : access End_Game_Event; completed : Boolean ); 
  174.  
  175.     function To_String( this : access End_Game_Event ) return String; 
  176.  
  177.     ---------------------------------------------------------------------------- 
  178.  
  179.     type Game_Paused_Event is new Event with 
  180.         record 
  181.             paused : Boolean := True; 
  182.         end record; 
  183.  
  184.     procedure Construct( this : access Game_Paused_Event; paused : Boolean ); 
  185.  
  186.     function To_String( this : access Game_Paused_Event ) return String; 
  187.  
  188.     ---------------------------------------------------------------------------- 
  189.  
  190.     type Game_State_Event is new Event with 
  191.         record 
  192.             playing     : Boolean := True; 
  193.             interrupted : Boolean := False; 
  194.         end record; 
  195.  
  196.     procedure Construct( this        : access Game_State_Event; 
  197.                          playing     : Boolean; 
  198.                          interrupted : Boolean ); 
  199.  
  200.     function To_String( this : access Game_State_Event ) return String; 
  201.  
  202.     ---------------------------------------------------------------------------- 
  203.  
  204.     type Game_Var_Changed_Event is new Event with 
  205.         record 
  206.             var : Unbounded_String; 
  207.             val : Value_Ptr; 
  208.         end record; 
  209.  
  210.     procedure Adjust( this : access Game_Var_Changed_Event ); 
  211.  
  212.     procedure Construct( this : access Game_Var_Changed_Event; 
  213.                          var  : String; 
  214.                          val  : Value_Ptr'Class ); 
  215.     pragma Precondition( var'Length > 0 ); 
  216.     pragma Precondition( Value_Ptr(val) /= Values.Nul ); 
  217.  
  218.     function To_String( this : access Game_Var_Changed_Event ) return String; 
  219.  
  220.     ---------------------------------------------------------------------------- 
  221.  
  222.     type Loading_Event is new Event with 
  223.         record 
  224.             loading : Boolean; 
  225.             error   : Unbounded_String; 
  226.         end record; 
  227.  
  228.     procedure Construct( this    : access Loading_Event; 
  229.                          name    : String; 
  230.                          loading : Boolean; 
  231.                          error   : String ); 
  232.  
  233.     function To_String( this : access Loading_Event ) return String; 
  234.  
  235.     ---------------------------------------------------------------------------- 
  236.  
  237.     type Pause_Game_Event is new Event with 
  238.         record 
  239.             paused : Boolean := True; 
  240.         end record; 
  241.  
  242.     procedure Construct( this : access Pause_Game_Event; paused : Boolean ); 
  243.  
  244.     ---------------------------------------------------------------------------- 
  245.  
  246.     type Scroll_View_Event is new Event with 
  247.         record 
  248.             x, y : Float := 0.0; 
  249.         end record; 
  250.  
  251.     procedure Construct( this : access Scroll_View_Event; x, y : Float ); 
  252.  
  253. end Events.Game;