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.     END_GAME_ID : constant Event_Id := To_Event_Id( "End_Game" ); 
  17.  
  18.     -- A command to end the game session. 
  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.     ---------------------------------------------------------------------------- 
  23.  
  24.     GAME_PAUSED_ID : constant Event_Id := To_Event_Id( "Game_Paused" ); 
  25.  
  26.     -- A notification that the game paused state has changed. 
  27.     type Game_Paused_Event is new Event with private; 
  28.     type A_Game_Paused_Event is access all Game_Paused_Event'Class; 
  29.  
  30.     -- Returns True if the gameplay has been paused or False if it has been resumed. 
  31.     function Is_Paused( this : not null access Game_Paused_Event'Class ) return Boolean; 
  32.  
  33.     ---------------------------------------------------------------------------- 
  34.  
  35.     GAME_STATE_ID : constant Event_Id := To_Event_Id( "Game_State" ); 
  36.  
  37.     -- A notification that the gameplay state has changed. This happens when a 
  38.     -- game session begins and ends. 
  39.     type Game_State_Event is new Event with private; 
  40.     type A_Game_State_Event is access all Game_State_Event'Class; 
  41.  
  42.     -- Returns True if gameplay is not in progress now because the game session 
  43.     -- was interrupted by the player, instead of ending naturally (winning or 
  44.     -- losing.) The game session can be interrupted to start a new game, load a 
  45.     -- saved game, or just end the current game session by choice. 
  46.     function Is_Interrupted( this : not null access Game_State_Event'Class ) return Boolean; 
  47.  
  48.     -- Returns True if gameplay is in progress. 
  49.     function Is_Playing( this : not null access Game_State_Event'Class ) return Boolean; 
  50.  
  51.     ---------------------------------------------------------------------------- 
  52.  
  53.     GAME_VAR_CHANGED_ID : constant Event_Id := To_Event_Id( "Game_Var_Changed" ); 
  54.  
  55.     -- A notification that a game session variable has changed. 
  56.     type Game_Var_Changed_Event is new Event with private; 
  57.     type A_Game_Var_Changed_Event is access all Game_Var_Changed_Event'Class; 
  58.  
  59.     -- Returns the name of the variable that changed. 
  60.     function Get_Var( this : not null access Game_Var_Changed_Event'Class ) return String; 
  61.  
  62.     -- Returns a copy of the variable's new value. The value can be of any type. 
  63.     procedure Copy_Value( this : access Game_Var_Changed_Event; 
  64.                           val  : in out A_Value ); 
  65.     pragma Precondition( val = null ); 
  66.  
  67.     ---------------------------------------------------------------------------- 
  68.  
  69.     LOADING_ID : constant Event_Id := To_Event_Id( "Loading" ); 
  70.  
  71.     -- A notification that the game loading state has changed. This happens when 
  72.     -- the game logic begins and finishes loading resources. 
  73.     type Loading_Event is new Event with private; 
  74.     type A_Loading_Event is access all Loading_Event'Class; 
  75.  
  76.     -- Returns True if loading is in progress or False if it has completed. 
  77.     function Is_Loading( this : not null access Loading_Event'Class ) return Boolean; 
  78.  
  79.     ---------------------------------------------------------------------------- 
  80.  
  81.     NEW_GAME_ID : constant Event_Id := To_Event_Id( "New_Game" ); 
  82.  
  83.     -- A command to begin a new game session. 
  84.     type New_Game_Event is new Event with private; 
  85.     type A_New_Game_Event is access all New_Game_Event'Class; 
  86.  
  87.     ---------------------------------------------------------------------------- 
  88.  
  89.     PAUSE_GAME_ID : constant Event_Id := To_Event_Id( "Pause_Game" ); 
  90.  
  91.     -- A command to change the game paused state. 
  92.     type Pause_Game_Event is new Event with private; 
  93.     type A_Pause_Game_Event is access all Pause_Game_Event'Class; 
  94.  
  95.     -- Returns True if the command is to pause the gameplay, or False if the 
  96.     -- command is to resume gameplay. 
  97.     function Is_Paused( this : not null access Pause_Game_Event'Class ) return Boolean; 
  98.  
  99.     ---------------------------------------------------------------------------- 
  100.  
  101.     PLAYER_DIED_ID : constant Event_Id := To_Event_Id( "Player_Died" ); 
  102.  
  103.     -- A notification that the player died. 
  104.     type Player_Died_Event is new Event with private; 
  105.     type A_Player_Died_Event is access all Player_Died_Event'Class; 
  106.  
  107.     ---------------------------------------------------------------------------- 
  108.  
  109.     SCROLL_VIEW_ID : constant Event_Id := To_Event_Id( "Scroll_View" ); 
  110.  
  111.     -- A command to scroll the gaame view's viewport of the world. 
  112.     type Scroll_View_Event is new Event with private; 
  113.     type A_Scroll_View_Event is access all Scroll_View_Event'Class; 
  114.  
  115.     -- Amount to scroll view in the X axis in world coordinates. 
  116.     function Get_X( this : not null access Scroll_View_Event'Class ) return Float; 
  117.  
  118.     -- Amount to scroll view in the Y axis in world coordinates. 
  119.     function Get_Y( this : not null access Scroll_View_Event'Class ) return Float; 
  120.  
  121.     ---------------------------------------------------------------------------- 
  122.  
  123.     VIEW_READY_ID : constant Event_Id := To_Event_Id( "View_Ready" ); 
  124.  
  125.     -- A notification that the gameplay readiness state of the view has changed. 
  126.     -- When a new world is loaded, the view also loads the required content 
  127.     -- referenced in the World_Loaded event and sends a View_Ready event when it 
  128.     -- is finished loading and finished display the level loading dialog and is 
  129.     -- ready for gameplay to begin. 
  130.     type View_Ready_Event is new Event with private; 
  131.     type A_View_Ready_Event is access all View_Ready_Event'Class; 
  132.  
  133.     -- Returns True if the view is ready for gameplay. 
  134.     function Is_Ready( this : not null access View_Ready_Event'Class ) return Boolean; 
  135.  
  136.     ---------------------------------------------------------------------------- 
  137.  
  138.     -- Queues an End_Game_Event. 
  139.     procedure Queue_End_Game; 
  140.  
  141.     -- Queues a Game_Paused_Event. 
  142.     procedure Queue_Game_Paused( paused : Boolean ); 
  143.  
  144.     -- Queues a Game_State_Event. 
  145.     procedure Queue_Game_State( playing : Boolean; interrupted : Boolean := False ); 
  146.  
  147.     -- Queues a Game_Var_Changed_Event. 
  148.     procedure Queue_Game_Var_Changed( var : String; 
  149.                                       val : in out A_Value ); 
  150.     pragma Precondition( var'Length > 0 ); 
  151.     pragma Postcondition( val = null ); 
  152.  
  153.     -- Queues a Loading_Event. 
  154.     procedure Queue_Loading( loading : Boolean ); 
  155.  
  156.     -- Queues a New_Game_Event. 
  157.     procedure Queue_New_Game; 
  158.  
  159.     -- Queues a Pause_Game_Event. 
  160.     procedure Queue_Pause_Game( paused : Boolean ); 
  161.  
  162.     -- Queues a Player_Died_Event. 
  163.     procedure Queue_Player_Died; 
  164.  
  165.     -- Queues a Scroll_View_Event. 
  166.     procedure Queue_Scroll_View( x, y : Float ); 
  167.  
  168.     -- Queues a View_Ready_Event. 
  169.     procedure Queue_View_Ready( ready : Boolean ); 
  170.  
  171. private 
  172.  
  173.     type End_Game_Event is new Event with null record; 
  174.  
  175.     ---------------------------------------------------------------------------- 
  176.  
  177.     type Game_Paused_Event is new Event with 
  178.         record 
  179.             paused : Boolean := True; 
  180.         end record; 
  181.  
  182.     procedure Construct( this : access Game_Paused_Event; paused : Boolean ); 
  183.  
  184.     function To_String( this : access Game_Paused_Event ) return String; 
  185.  
  186.     ---------------------------------------------------------------------------- 
  187.  
  188.     type Game_State_Event is new Event with 
  189.         record 
  190.             playing     : Boolean := True; 
  191.             interrupted : Boolean := False; 
  192.         end record; 
  193.  
  194.     procedure Construct( this        : access Game_State_Event; 
  195.                          playing     : Boolean; 
  196.                          interrupted : Boolean ); 
  197.  
  198.     function To_String( this : access Game_State_Event ) return String; 
  199.  
  200.     ---------------------------------------------------------------------------- 
  201.  
  202.     type Game_Var_Changed_Event is new Event with 
  203.         record 
  204.             var : Unbounded_String; 
  205.             val : A_Value := null; 
  206.         end record; 
  207.  
  208.     procedure Adjust( this : access Game_Var_Changed_Event ); 
  209.  
  210.     procedure Construct( this : access Game_Var_Changed_Event; 
  211.                          var  : String; 
  212.                          val  : in out A_Value ); 
  213.     pragma Precondition( var'Length > 0 ); 
  214.     pragma Postcondition( val = null ); 
  215.  
  216.     procedure Delete( this : in out Game_Var_Changed_Event ); 
  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.         end record; 
  226.  
  227.     procedure Construct( this : access Loading_Event; loading : Boolean ); 
  228.  
  229.     function To_String( this : access Loading_Event ) return String; 
  230.  
  231.     ---------------------------------------------------------------------------- 
  232.  
  233.     type New_Game_Event is new Event with null record; 
  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 Player_Died_Event is new Event with null record; 
  247.  
  248.     ---------------------------------------------------------------------------- 
  249.  
  250.     type Scroll_View_Event is new Event with 
  251.         record 
  252.             x, y : Float := 0.0; 
  253.         end record; 
  254.  
  255.     procedure Construct( this : access Scroll_View_Event; x, y : Float ); 
  256.  
  257.     ---------------------------------------------------------------------------- 
  258.  
  259.     type View_Ready_Event is new Event with 
  260.         record 
  261.             ready : Boolean := True; 
  262.         end record; 
  263.  
  264.     procedure Construct( this : access View_Ready_Event; ready : Boolean ); 
  265.  
  266. end Events.Game;